Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assignment 3: Caesar Shift Cipher: shift the letters in a secret message forward

ID: 3855804 • Letter: A

Question

 Assignment 3: Caesar Shift Cipher:  shift the letters in a secret message forward in the alphabet a certain number of places.  Example:  shift 13 Hello, Jack Uryyb, Wnpx  Read the command line for an integer in argv[1]  Run it through atoi() to convert the command line string to an integer:  int shift = atoi(argv[1]) ;   Remember that if you shift a letter off the end of the alphabet, we must  "wrap around" so we come back in down by 'a'.  Here's the pseudocode:  read in a character c  if (c is a letter ) {         make c lowercase          make c a number between 0 and 25          add the shift value to c          mod c so it's between 0 and 25 again          add a 'a' to c so it's a real ASCII letter again. } print c on the output  // this happens for ALL input, not just letters!  

Explanation / Answer

#include int main() { char string4[80]; int rotatorN; printf("Enter String: "); gets(string4); printf("Enter Number: "); scanf("%i", &rotatorN); int n = 0, rotateSwap = 0; int i; for(i=0; string4[i] != ''; i++) { if(string4[i] >='a' && string4[i] n ) { rotateSwap = rotatorN - n - 1; string4[i] = 'a'; string4[i] += rotateSwap; } else string4[i] += rotatorN; } } int j; for(j = 0; string4[j] !=''; j++) { printf("%c", string4[j]); } printf(" "); return 0; }