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

A simple substitution cipher can be created by shifting a letter n positions in

ID: 3799278 • Letter: A

Question

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 ch;
   int value,e,fvalue=0;

   printf("enter one alphabetic character ");
   scanf("%c",&ch);
   if(ch>=65 && ch<=90 && ch>=97 && ch<=122)
   {
   printf("enter the shift value ");
   scanf("%d",&value);
   e=ch;
   fvalue=e+value;
   if(fvalue>90)
   {
   fvalue=fvalue+7;
   }
   printf("cipher text is:%c",fvalue);
   fvalue=0;
   }
   else
   {
   printf("wrong input");
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote