One of the oldest known encryption techniques is the Caesar cipher, attributed t
ID: 3639949 • Letter: O
Question
One of the oldest known encryption techniques is the Caesar cipher, attributed to Julius Caesar. It involves replacing each letter in a message with another letter that is fixed number of positions later in the alphabet. (If the replacement would go past the letter Z, the cipher “wraps around” to the beginning of the alphabet. For example, if each letter is replaced by the letter two positions after it, the Y would be replaced by A, and Z would be replaced by message to be encrypted and the shift mount (the number of positions by which letters should be shifted):Enter message to be encrypted: Go ahead, make my day.
Enter shift amount (1-25) : 3
Encrypted message: Jr dkhdg, pdnh pb gdb.
mingw compiler
Explanation / Answer
#include<stdio.h>
#include<string.h>
int main()
{
char a[50],b[50];
int i,k;
printf(" Enter message to be encrypted : ");
gets(a);
printf(" Enter Shift amount : ");
scanf("%d",&k);
for(i=0 ; a[i]!='' ; ++i)
{
if(a[i]>='a' && a[i]<='z')
{
if(a[i] <= 'z'-k)
b[i] = a[i] + k;
else
b[i] = a[i] - ('z' - k) + 'a' - 1;
}
else if(a[i]>='A' && a[i]<='Z')
{
if(a[i] <= 'Z'-k)
b[i] = a[i] + k;
else
b[i] = a[i] - ('Z' - k) + 'A' - 1;
}
else
b[i] = a[i];
}
b[i] = '';
printf(" Encrypted Message : %s",b);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.