Thread: Vigenere - can't stop keyword from iterating

  1. #1
    Registered User
    Join Date
    Aug 2019
    Posts
    2

    Vigenere - can't stop keyword from iterating

    Code:
    // Converts plain text to cipher text
            for (int l = 0, o = strlen(s); l < o; l++)
            {
                if (islower(s[l]))
                {
                    int m = (l % strlen(argv[1]));
                    char c = ((s[l] + shift(argv[1][m]) - 97) % 26 + 97);
                    printf("%c", c);
                    m++;
                }
                else if (isupper(s[l]))
                {
                    int m = (l % strlen(argv[1]));
                    char c = (s[l] + shift(argv[1][m]) - 65) % 26 + 65; 
                    printf("%c", c);
                    m++;
                }
                else
                {
                    char c = s[l];
                    printf("%c", s[l]);
                }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,533
    You've got a very bad case of single letter identifier disease.
    Eye watering alphabet soup is incredibly hard to follow because it has NO meaning.

    What's in s?
    What's in argv[1]?
    What does shift() do?

    Post a complete program we can run.

    Code:
    int main ( ) {
      char *s = "...."; // something, anything, it's just an example
      char *key = "key";  // What would be in argv[1]
      /// any other setup
      // your code
    }
    With something like this, we can just copy/paste/run with ZERO guesswork on our part.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    148
    Interesting...


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vigenere cipher
    By Kecupochren in forum C Programming
    Replies: 2
    Last Post: 03-26-2013, 04:36 PM
  2. Need help with Vigenere
    By saldar05 in forum C Programming
    Replies: 4
    Last Post: 12-24-2012, 10:21 PM
  3. Vigenère chiper
    By drew99 in forum C Programming
    Replies: 1
    Last Post: 10-09-2011, 06:44 AM
  4. Stop button doesnt stop a function (using PostMessage)
    By scwizzo in forum Windows Programming
    Replies: 7
    Last Post: 03-07-2008, 07:54 PM
  5. Vigenere
    By Xander in forum C++ Programming
    Replies: 1
    Last Post: 02-15-2002, 01:34 AM

Tags for this Thread