0

Im trying to figure out where my problem is. Usind the examples given with the keys the transcription works fine. But if i try to run check50:

//Checking for right argument
if (argc != 2)
{
    printf("Invalid argument\n");
    return 1;
}
else
{
    for (int i = 0, n = strlen(argv[1]); i < n; i++)
    {
        if (!isalpha(argv[1][i]))
        {
            printf("Invalid Argument.");
            return 1;
        }
    }
 }

//Getting input as string
string text = get_string("plaintext: ");

//Printing cyphertext beforehand
printf("ciphertext: ");

//Determining the length of argv[1]
string key = argv[1];
int arglength = strlen(key);

//Checking if it's a character and transforming it to ciphertext
for (int i = 0, j = 0, n = strlen(text); i <= n; i++)
{
    //Get the asked key
    int rdykey = tolower(key[j % arglength]) - 'a';

    if isalpha(text[i])
    {
        if isupper(text[i])
        {
            printf("%c", (((text[i] + rdykey) - 65) % 26) + 65);
            j++;
        }
        else if islower(text[i])
        {
            printf("%c", (((text[i] + rdykey) - 97) % 26) + 97);
            j++;
        }
    }
    else
    {
          printf("%c", text[i]);
    }
}
printf("\n");
return 0;

}

Thank you :)

1
  • Sorry i forgot to finish the sentence: But if i try to run check50, it marks every output as red, even if its the same asked ciphertext... im a little confused Nov 18 '18 at 14:49
0

Ok i found the solution. I printed out the '/0' of the string, therefor the output wasn't right :)

1
  • Congrats Then mark your answer as solved
    – myckhel
    Nov 18 '18 at 23:40

You must log in to answer this question.

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