int main(int argc, string argv[])

    if(argc !=2)
        printf("enter your key first ");
        return 1;
    int d;
    string currkey=argv[1];
    printf("enter plain text here: ");
    string plain=GetString();
    for(int j=0,i=0;j<strlen(plain)&&i<strlen(currkey);j++,i++)

                int a=currkey[i]-'A';
                int b=plain[j]-'A';
                int c=(a+b)%26;
                int a=currkey[i]-'a';
                int b=plain[j]-'a';
                int c=(a+b)%26;

return 0;
  • I assume you're asking how to wrap around array indexes. In that case, this question is a duplicate cs50.stackexchange.com/questions/1298/…
    – kzidane
    Jul 2, 2014 at 17:40
  • but idont know how to apply it in my code i try many ways but it didnt work and give an error
    – JacobLino
    Jul 2, 2014 at 17:42
  • Did you read the answers to the question?
    – kzidane
    Jul 2, 2014 at 18:08

3 Answers 3


analyzes the result of the compilation, and you see running each part separately, you must check that the key is "only alphabetical" traces the key here at this point, then you travel chain, independent "j"

you enter the key control that is alphabetical if its not alphabetical, return 1, imprimer mistake. asks the plaintext. Walking controlling the plaintext length. if the plaintext is alphabetical if lowercase and upercase beam corresponding operations if not shut alphabetical increases j, and let the same character (",",.. etc) print it closed.

Ignoring Non-Alphabetical chars in Vigenere caesar ignores where it says, is to take the same answer, but changed with Vigenere


I won't code it out for you, but I can give you the intuition. To get the ciphertext character, you add the int key value to the int ASCII value. If this new character is past "Z" or "z," then you need to capture the excess shift values:

excess = (int)cipherchar - (int)"z";
cipherchar = excess + "a";

Something like that would wrap it around.

Hope I could help.


Try to play with modulo operator to wrap around the strings. The formula for Vigenere (or caesar) will help you with it.

Formula for encryption in Vigenere cipher is

c = (a + b) % 26

where modulus 26 is because of 26 alphabets in English. This way it simply wrap around these 26 alphabets only. Similarly you can do this with string length.

I would suggest you to take you paper and pen and play with the formula of Vigenere and try to understand whats actually happening. This way you will crack a way to wrap around your key.

Good Luck

You must log in to answer this question.

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