考察編程基礎知識,用到字符和數字相互轉化等。形式是描述清楚明文和暗文的轉化規則。
1 #include <stdio.h>
2 #include <string.h>
3
4 #define MAXLEN 71
5
6 int length;
7
8 void toCode(int code[],char text[]){
9 int i;
10 for(i=0;i<length;i++){
11 if(text[i] == '_')
12 code[i] = 0;
13 else if(text[i] == '.')
14 code[i] = 27;
15 else
16 code[i] = text[i] - 96;
17 }
18 }
19
20 void toText(char text[],int code[]){
21 int i;
22 for(i=0;i<length;i++){
23 if(code[i] == 0)
24 text[i] = '_';
25 else if(code[i] == 27)
26 text[i] = '.';
27 else
28 text[i] = code[i] + 96;
29 }
30 text[i] = 0;
31 }
32
33 int inRange(int n){
34 if(n>=0&&n<=27)
35 return 1;
36 return 0;
37 }
38
39 void untwist(char textC[],int k){
40 int i,j;
41 int codeC[MAXLEN],codeP[MAXLEN];
42 char textP[MAXLEN];
43
44 toCode(codeC,textC);
45 for(i=0;i<length;i++){
46 j = (k*i)%length;
47 if(inRange(codeC[i] + i))
48 codeP[j] = codeC[i] + i;
49 else if(inRange(codeC[i] + i - 28))
50 codeP[j] = codeC[i] + i - 28;
51 else if(inRange(codeC[i] + i - 56))
52 codeP[j] = codeC[i] + i - 56;
53 else if(inRange(codeC[i] + i - 84))
54 codeP[j] = codeC[i] + i - 84;
55 }
56 toText(textP,codeP);
57 printf("%s\n",textP);
58 }
59
60 int main(){
61 int k;
62 char textC[MAXLEN];
63 while(scanf("%d",&k)&&k){
64 scanf("%s",textC);
65 length = strlen(textC);
66 untwist(textC,k);
67 }
68 return 0;
69 }
非常簡單的加密解密方式,類似替換法.不過不是直接替換.
但不知道那個超級sb非得用鳥文寫,有的單詞好象寫錯了.