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

please help me out. A simple substitution cipher can be created by shifting a le

ID: 3799756 • Letter: P

Question

please help me out.

A simple substitution cipher can be created by shifting a letter n positions in alphabetic order. For example, if the possible characters are the list [A…Za…z], a shift of three would translate A to D and Z to c. The shift is circular so z would shift around to C. The shift value, n, can be positive or negative.

Write c/c++ program that performs this simple substitution cipher. Your c/c++ program should request the user to enter a shift value, followed by one alphabetic character. It should then print the cipher text for that character. Print an appropriate error message if the user enters something other than a letter from the list [A…Za…z].

Explanation / Answer

#include <stdio.h>

int main()
{
char c;
int a,s;
printf("Enter the plaintext character: ");
scanf("%c", &c);
printf("Enter the shift: ");
scanf("%d", &s);
  
a = ((c+s)-97)%26 + 97;
printf("Ciphertext: %c ",a);
}

//----------------------------------------------------------------------------------------------

sh-4.2$ main                                                                                                                                                                    

Enter the plaintext character: a                                                                                                                                                

Enter the shift: 4                                                                                                                                                              

Ciphertext: e