#include <stdio.h>
#include <string.h>
// 凯撒密码(加密方式)
void caesarEncrypt(char *text, int shift) {
int len = strlen(text);
int i=0;
for (i = 0; i < len; i++) {
if (text[i] >= 'a' && text[i] <= 'z') {
text[i] = (text[i] - 'a' + shift) % 26 + 'a';
} else if (text[i] >= 'A' && text[i] <= 'Z') {
text[i] = (text[i] - 'A' + shift) % 26 + 'A';
}
}
}
// 凯撒密码(解密方式)
void caesarDecrypt(char *text, int shift) {
caesarEncrypt(text, 26 - shift);
}
int main() {
char message[100] = "Hello, World!";
int shift = 3;
printf("原始消息: %s\n", message);
// 加密
caesarEncrypt(message, shift);
printf("加密后的消息: %s\n", message);
// 解密
caesarDecrypt(message, shift);
printf("解密后的消息: %s\n", message);
return 0;
}