|
发表于 2020-9-22 15:26:11
|
显示全部楼层
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define Len 200
- int main()
- {
- int i,len;
- char cipher_text[Len]; // 密文数组
- char original_text[Len]; // 原文数组
- FILE *fp = fopen("C:\\important.txt", "r");
- if (!fp)
- {
- printf("文件读取失败!\n");
- exit(1);
- }
- len = strlen(cipher_text);
- fgets(cipher_text, Len, fp);
- printf(" 加密的文件如下:\n");
- printf(" %s\n", cipher_text);
- for (i = 0;i < len;i++) // 逐个元素进行解密
- {
- if (cipher_text[i] >= 65 && cipher_text[i] <= 90)
- {
- original_text[i] = 90 - cipher_text[i] + 65;
- }
- else if (cipher_text[i] >= 97 && cipher_text[i] <= 122)
- {
- original_text[i] = 122 - cipher_text[i] + 97;
- }
- else
- original_text[i] = cipher_text[i];
- }
- printf(" 解密的文件如下:\n");
- printf(" %s\n",original_text);
- fclose(fp);
- getchar(); // 让系统处于等待状态,去掉了 Press any key to continue . . .
- return 0;
- }
复制代码
你将下面的文字复制后,新建一个文本文件,并命名为 important.txt ,放置于C盘根目录下。然后,再运行上面的程序,就知道什么是加密,什么是解密了
Lm Lxglyvi 1, 1949. Xszrinzm Nzl Avwlmt hlovnmoh wvxozivw gl gsv dliow: gsv Kvlkov'h Ivkfyorx lu Xsrmz dzh ulfmwvw zmw gsv Xsrmvhv kvlkov szev hgllw fk hrmxv gsvm!
|
|