Please photo print the solution if you can. A shift cipher is one of the simples
ID: 3816697 • Letter: P
Question
Please photo print the solution if you can.
A shift cipher is one of the simplest encryption techniques in the field of cryptography. It is a cipher in which each letter in a plain text massage is replace (x) by a letter some (fixed number of positions up the alphabet (i.e., by right shifting the alphabetic characters in the plain text massage). For example, with a right shift, of 2, 'A* is replaced by 'C', 'B' is replaced by 'D', etc. Note that the shift wraps around from the end to the beginning of the alphabet such that, with a right shift of 2, 'Y' is replaced by 'A' and 'Z' is replaced by 'B'. Deciphering works in the same way, but shifts to the left and wraps around from the beginning of the alphabet to the end. Write two functions encrypt and decipher. encrypt takes a NULL terminated string and a shift parameter as inputs, and right shifts all alphabetic characters (i.e., and by the shift parameter. Non-alphabetic chanters should not be changed by encrypt. decipher takes a NULL terminated string and a shift parameter as inputs, and left shifts all alphabetic characters (i.e., 'A' - 'Z' and 'A' - 'Z') by the silt parameter. Non-alphabetic characters should not be changed by encrypt. Your functions can be written assuming that the shift parameter will never be less than 0 or greater than 26. You must use the following function prototypes: void encrypt (char str[], int shift); void decipher(char str[], int shift);Explanation / Answer
#include <stdio.h>
void encrypt(char str[10], int shift)
{
char crypt[10];
int k=0;
char a;
while(str[k] !='')
{
a = toupper(str[k]);
if(a != ' ') a += shift;
{
if(a > 'z') a -=26;
{
crypt[k] = a;
k++;
}
}
}
crypt[k]='';
printf(" Encrypted string is [%s]",crypt);
k=0;
}
void decrypt(char str[10], int shift)
{
char decrypt[10];
char a;
int k=0;
while(str[k] !='')
{
a = str[k];
if(a != ' ') a -=shift;
{
if(a < 'A' && a !=' ') a +=26;
{
decrypt[k] = a;
k++;
}
}
}
decrypt[k]='';
printf(" Decrypted string is [%s]",decrypt);
}
int main()
{
printf("Hello, World! ");
encrypt("Caeser",2);
decrypt("Example",2);
return 0;
}