After many many hours of trying to accomplish Caesar, check50 only yeilds one error:
- :) caesar.c exists.
- :) caesar.c compiles.
- :) encrypts "a" as "b" using 1 as key
- :) encrypts "barfoo" as "yxocll" using 23 as key
- :) encrypts "BARFOO" as "EDUIRR" using 3 as key
- :) encrypts "BaRFoo" as "FeVJss" using 4 as key
- :( encrypts "barfoo" as "onesbb" using 65 as key expected "ciphertext: one...", not "ciphertext: ihy..."
- :) encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key
- :) handles lack of argv[1]
I'm not sure why it's the only error. My code is:
int main(int argc, string argv[]) {
if (argc != 2)
{
printf("Error -102: Invalid User Input\n");
return 1;
}
else
{
string message;
do
{
message = get_string("plaintext: ");
}
while (!message);
printf("ciphertext: ");
int key = atoi(argv[1]);
char fin;
for (int i = 0; i < strlen(message); i++) {
char ch = message[i];
int c = message[i];
int add = c;
if (add > 90)
{
add = add - 32;
}
add = add - 65;
if (add < 0 || add >= 155)
{
fin = message[i];
printf("%c", fin);
}
else
{
add = add + key;
if ((add + 65) > 90) {
add = add + 39;
}
else {
add = add + 65;
}
fin = (char) add;
if (islower(ch)) {
printf("%c", tolower(fin));
}
else {
printf("%c", toupper(fin));
}
}
}
printf("\n");
}
}
Thank you for any and all help you can offer!