string message = GetString();
string key = argv[1];

for(int i=0, n= strlen(message); i<n; i++)
    int k= i%strlen(key);
    char me = toupper(message[i]);
    char ke= toupper(key[k]);

    char cr =(me-65 + ke-65)%26 + 65;

    printf("%c", cr);

   printf("%c", tolower(cr));

  printf("%c", message[i]);

When the program counts for letters in key, it does not skip non alpha characters like space or ','. I need help with fixing that. (Sorry for bad english.)

1 Answer 1


Your program links the index for the key to the index of the plaintext to be encoded. The index for the key should only increment when a letter is encoded and not when a non-alpha is printed. Because you linked k to I, k is incremented for every character, so your encoding gets out of synch.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • Thanks but I could not figure out how to do that. Jan 23, 2016 at 23:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .