A simple substitution cipher can be created by shifting a le
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].
Solution
#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;
}
![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 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],](/WebImages/33/a-simple-substitution-cipher-can-be-created-by-shifting-a-le-1095443-1761577565-0.webp)