|
-
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
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
|