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:

1
2
3
4
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:

1
2
3
4
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:

 
(c + Codeword::Instance()->getNext()) % 127


And the decription line is:

 
(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

I think the problem is that your trying to use standard the ASCII table and you computer wants to use the extended set. Check this site out: http://www.asciitable.com/

You can see that this should be based on a table that is 256 characters long and not 128.
Wow, thanks very much. That was indeed the problem. I wrote the ruby version some time ago and forgot what made me choose mod 127 then. I didn't think the charset would act differently between two languages on the same machine.

Anyway, thank you very much.
Topic archived. No new replies allowed.