-
March 3rd, 2011, 09:31 PM
#1
extended vigenere cipher problem
Hi all,
Firstly apologies for a somewhat cryptic(!) post, I'm terrible at explaining problem like this, but I hope I haven't made it too difficult to understand my meaning.
I'm just playing around writing a program for an extended vigenere cipher(1). Normally the vigenere cipher is mod 26 but mine is mod 127. This means you don't have to strip out non A-Z chars and it will encode spaces, punctuation, everything.
I've written this same program previously in ruby so I know the maths behind it is correct. However in this C version, decryption is not working correctly. Encrypting produces the correct output, however I can't track down why decrypting isn't working.
For example - expected output:
Code:
Plaintext: This is a basic test message.
Codeword: codewordcodewordcodewordcodew
Ciphertext: 8XNY^XYf^EE^PGGkYV^EXUXZ^X]XXWQLK&y
Plaintext: This is a basic test message.
Actual output:
Code:
Plaintext: This is a basic test message.
Codeword: codewordcodewordcodewordcodew
Ciphertext: 8XNY^XYf^EE^PGGkYV^EXUXZ^X]XXWQLK&y
Plaintext: Õéêô¡êô¡â¡ãâôêä¡õæôõ¡îæôôâèæ¯
Note that the pattern of the last line is exactly right. You can see where the spaces are compared to the original message, and the full stop at the end.
The encryption line is:
Code:
(c + Codeword::Instance()->getNext()) % 127
And the decription line is:
Code:
(c - Codeword::Instance()->getNext()) % 127
Codeword::Instance is a singleton class which will automatically return the next character in the codeword and queue the next one up. Everything looks fine in debugging as far as I can tell, but my mathematics isn't that strong.
Grateful for any assistance or pointers.
(1) http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher
-
March 4th, 2011, 12:48 AM
#2
[SOLVED] extended vigenere cipher problem
All fixed, the problem was that the C program was using the full extended charset. Once I changed to mod 255, it all works perfectly. Strange that it was different between Ruby and C, but never mind
-
March 4th, 2011, 10:57 AM
#3
Re: [SOLVED] extended vigenere cipher problem
Beware, vigenere is one of the easiest cyphers to crack. It's not secure at all.
-
March 4th, 2011, 11:27 AM
#4
Re: extended vigenere cipher problem
Yeah, you should consider something safer, like rot13
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
-
March 4th, 2011, 12:14 PM
#5
Re: extended vigenere cipher problem
Lol don't worry I'm not expecting it to hide my secrets. I wanted to see the comparison between the traditional vigenere cipher and the version I've done. Theoretically, with a decent length key, the frequency analysis attacks should be far less dangerous.
-
March 4th, 2011, 12:23 PM
#6
Re: extended vigenere cipher problem
Well, that's true. At the extreme end of the key length spectrum you have the one-time pad, which of course is completely secure (up to the security of getting the key to the recipient, of course).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|