文本数据加密及查询

 1 文本数据加密
 2 
 3 #define  _CRT_SECURE_NO_WARNINGS
 4 #include <stdio.h>
 5 #include <stdlib.h>
 6 
 7 void run(char *str)
 8 {
 9     char *p = str;
10     while (*p != '\0')
11     {
12         if (*p == '\r' || *p == '\n')
13         {
14             *p = '\0';
15         }
16         p++;
17     }
18     int length = strlen(str);
19     for (int i = 0; i < length; i++)
20     { 
21         str[i] ^= 3; 
22     }
23 
24 
25 }
26 
27 void main()
28 {
29     FILE *pfr = fopen("E:\\XXXX.txt", "r");
30     FILE *pfw = fopen("E:\\XX.txt", "w");
31     while (!feof(pfr))
32     {
33         char str[1024] = { 0 };
34         fgets(str, 1023, pfr);
35         run(str);
36         fputs(str, pfw);
37         fputs("\n", pfw);
38     }
39 
40 
41 
42     fclose(pfr);
43     fclose(pfw);
44 
45     system("pause");
46 }
 1 查询 加密后的数据
 2 
 3 #define  _CRT_SECURE_NO_WARNINGS
 4 #include <stdio.h>
 5 #include <stdlib.h>
 6 #include <string.h>
 7 
 8 void run(char *str)
 9 {    // 处理文本文件"\r\n"
10     char *p = str;
11     while (*p != '\0')
12     {
13         if (*p == '\r' || *p == '\n')
14         {
15             *p = '\0';
16         }
17         p++;
18     }
19     int length = strlen(str);
20     for (int i = 0; i < length; i++)
21     {
22         str[i] ^= 3;
23     }
24 
25 
26 }
27 
28 void main()
29 {
30     FILE *pfr = fopen("E:\\XX.txt", "r"); //加密后的文本
31      
32     while (!feof(pfr))
33     {
34         char str[1024] = { 0 };
35         fgets(str, 1023, pfr);
36         run(str);
37         char *p = strstr(str, "XXX,");
38         char *p1 = strstr(str, "XXX");
39 
40         if (p != NULL && p1 != NULL)
41         {
42             printf("%s\n", p);
43         }
44     }
45 
46 
47 
48     fclose(pfr);
49 
50 
51     system("pause");
52 }

 

posted @ 2018-03-08 11:22  NoThx  阅读(365)  评论(0编辑  收藏  举报