0

Ok. I've been working on this for two days now and have checked various types of answers on here, but I'm not sure what's wrong with my code. I think maybe I need a fresh pair of eyes, or my equation for the enciphering is completely off. When I use check50 it gives me the cipher text. When I run it on my own it stays blank.

Thank you in advance for the help! Coding is new to me.

int main( int argc,string argv[])
{
if (argc != 2 || argc == 0)
{
    printf("Command-Line Arguement Error. Input text: ");
    return 1; 
}


for (int i = 0, n=strlen(argv[1]); i < n ; i++)
{
    if (!(isalpha(argv[1][i])))
    {
        printf("ERROR: Arguement must be alphabetical. Try again.");
        return 1;
    }
}

printf("Plaintext: "); 
string p = get_string(); 

//printf("ciphertext: ");


int m= strlen(argv[1]); 
int i = 0;

for (int j = 0, text_length = strlen(p); j<text_length ; j++) 
{
    if (isalpha(p[j]))
    {
        if (isupper(p[j]))
        {
            printf("%c", ((p[j] - 'A') + ((argv[1][i] - 'A') % m) % 26));

        }
        else
        {
            printf("%c", ((p[j] - 'a') + ((argv[1][i] - 'a') % m) % 26));

        }
        i++;
    }
    else 
    {
        printf("%c", p[j]);
    }
}
return 0; 
}
0

In Vigenere you should encipher every letter of the plaintext with a letter from the key. So if your key is "bar" and the plaintext is "coding", you use b to encipher c, then a to encipher o, then r to encipher d. After that you should start in the beginning of the key again and use b to encipher i, a to encipher n, r to encipher g. Check the walkthrough of Zamyla again, she gives you many hints on how to wrap around the key.

You must log in to answer this question.

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