我一直在研究这个凯撒密码,这是我到目前为止所得到的,当程序运行时没有任何反应。
#include <stdio.h>
#define MAX 80
main()
{
int shift, num;
char ciph[MAX];
printf("Enter the message to be encrypted: ");
while ((ciph[num] = getchar()) != '\n'){ //loops until a blank space is read
for(num=0; num<MAX; num++){ //scans characters into the array
ciph[num] = getchar();
}
}
printf("\nEnter the shift amout: ");
scanf("%d", &shift); //reads the shift amount
for (num = 0; num < MAX; num++) //shifts the letter
{
int c = ciph[num];
if ('a' >= c && c <= 'z')
c = ((c - 'a') + shift) % 26 + 'a';
else if ('A' >= c && c <= 'Z')
c = ((c - 'A') + shift) % 26 + 'A';
else
{
}
ciph[num] = c;
}
printf("%c", ciph[num]); //prints the encryption
}