CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2008
    Posts
    6

    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

  2. #2
    Join Date
    Nov 2008
    Posts
    6

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

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: [SOLVED] extended vigenere cipher problem

    Beware, vigenere is one of the easiest cyphers to crack. It's not secure at all.

  4. #4
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    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.

  5. #5
    Join Date
    Nov 2008
    Posts
    6

    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.

  6. #6
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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
  •  





Click Here to Expand Forum to Full Width

Featured