my code is nearly done for this PS, but I cannot figure out why some checks return errors, as below.
One thing I noticed is that my code fails to encrypt 'z' correctly - when trying to do this for any KEY the output I'm getting is: a1Segmentation fault (core dumped) - 'a' being the correct mapping against the KEY here, but '1' gets added, can't figure out why, and then the Segmentation fault.
Check50 returns these errors:
:( encrypts "XyZ" as "KeD" using NJQSUYBRXMOPFTHZVAWCGILKED as key expected "ciphertext: Ke...", not "ciphertext: Ke..."
:( encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZTEOGXHCIPJSQD as key expected "ciphertext: Cb...", not "ciphertext: Cb..."
:( encrypts "This is CS50" as "Cbah ah KH50" using yukfrnlbavmwzteogxhcipjsqd as key expected "ciphertext: Cb...", not "ciphertext: Cb..."
:( encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZteogxhcipjsqd as key expected "ciphertext: Cb...", not "ciphertext: Cb..."
:( encrypts all alphabetic characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key expected "ciphertext: Rq...", not "ciphertext: Rq..."
:( does not encrypt non-alphabetical characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key expected "ciphertext: Yq...", not "ciphertext: Yq..."
While the ones where plaintext finishes with 'z' are failing due to the issue from point 1, the other ones, when I attempt the check manually, using the given plaintext and key, give the expected output, so not sure why they're failing the check.
Also I can't locate which non-alphabetical characters do not encrypt.
The encryption part of the code is this: (mind that ALPHA is a string of 26 low case alphabet letters, KEY is a string of 26 alphabetical, non-repeating characters also in low case)
for (int k = 0; k < strlen(plaintext); k++) //int k needs to be a pointer for either ALPHA or KEY
{
for (int i = 0; tolower(plaintext[k]) >= ALPHA[i] || i < 26; i++) //int i needs to be a pointer for plaintext
{
if (ALPHA[i] == tolower(plaintext[k]))
{
if (isupper(plaintext[k]))
{
printf("%c", toupper(KEY[i]));
}
else if (islower(plaintext[k]))
{
printf("%c", tolower(KEY[i]));
}
}
}
if (isalpha(plaintext[k]) == 0)
{
printf("%c", plaintext[k]);
}
}
printf("\n");
What am I not seeing here?