Here are the specifications. Caesar- Design and implement a program, caesar, that encrypts messages using Caesar’s cipher. Implement your program in a file called caesar.c in a directory called...

Here are the specifications. Caesar- Design and implement a program, caesar, that encrypts messages using Caesar’s cipher. Implement your program in a file called caesar.c in a directory called caesar. Your program must accept a single command-line argument, a non-negative integer. Let’s call it k for the sake of discussion. If your program is executed without any command-line arguments or with more than one command-line argument, your program should print an error message of your choice (with printf) and return from main a value of 1 (which tends to signify an error) immediately. You can assume that, if a user does provide a command-line argument, it will be a non-negative integer (e.g., 1). No need to check that it’s indeed numeric. Do not assume that k will be less than or equal to 26. Your program should work for all non-negative integral values of k less than 231 - 26. In other words, you don’t need to worry if your program eventually breaks if the user chooses a value for k that’s too big or almost too big to fit in an int. (Recall that an int can overflow.) But, even if k is greater than 26, alphabetical characters in your program’s input should remain alphabetical characters in your program’s output. For instance, if k is 27, A should not become [ even though [ is 27 positions away from A in ASCII, per asciichart.com; Ashould become B, since B is 27 positions away from A, provided you wrap around from Z to A. Your program must output plaintext: (without a newline) and then prompt the user for a string of plaintext (using get_string). Your program must output ciphertext: (without a newline) followed by the plaintext’s corresponding ciphertext, with each alphabetical character in the plaintext "rotated" by k positions; non-alphabetical characters should be outputted unchanged. Your program must preserve case: capitalized letters, though rotated, must remain capitalized letters; lowercase letters, though rotated, must remain lowercase letters. After outputting ciphertext, you should print a newline. Your program should then exit by returning 0 from main. Here is my code- #include #include #include #include #include int main(int argc, string argv[]) { if(argc != 2) { printf("Use: ./caesar key"); return 1; } for(int i = 0, len = strlen(argv[1]); i if(!isdigit(argv[1][i])) { printf("Use: ./caesar "); return 1; } } int r = atoi(argv[1]) % 26; string plaintext = get_string(); int len = strlen(plaintext); for(int i = 0; i if(isalpha(plaintext[i])) { int tmp = (int) plaintext[i] + r; if(toupper(plaintext[i])) { if(tmp > 65 + 25) tmp -= 26; }else{ if(tmp > 97 + 25) tmp -= 26; } printf("%c", (char) tmp); }else printf("%c", plaintext[i]); } printf("\n"); return 0; } Here is what I am getting - :) caesar.c exists. :) caesar.c compiles. :( encrypts "a" as "b" using 1 as key expected prompt for input, found none :( encrypts "barfoo" as "yxocll" using 23 as key expected prompt for input, found none :( encrypts "BARFOO" as "EDUIRR" using 3 as key expected prompt for input, found none :( encrypts "BaRFoo" as "FeVJss" using 4 as key expected prompt for input, found none :( encrypts "barfoo" as "onesbb" using 65 as key expected prompt for input, found none :( encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key expected prompt for input, found none :) handles lack of argv[1]
Nov 14, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here