I guess you are done with Caesar I, aren't you?
The big problem with caesar is that it does not allow digits or other characters.
I have fixed this, and now I can use any ascii character in the plaintext.
The keyspace has increased from 26 to 128 too. \o/
Enjoy!
1A 42 42 37 20 3D 42 35 7F 20 4C 42 48 20 46 42 3F 49 38 37 20 42 41 38 20 40 42 45 38 20 36 3B 34 3F 3F 38 41 3A 38 20 3C 41 20 4C 42 48 45 20 3D 42 48 45 41 38 4C 01 20 27 3B 3C 46 20 42 41 38 20 4A 34 46 20 39 34 3C 45 3F 4C 20 38 34 46 4C 20 47 42 20 36 45 34 36 3E 01 20 2A 34 46 41 7A 47 20 3C 47 12 20 04 05 0B 20 3E 38 4C 46 20 3C 46 20 34 20 44 48 3C 47 38 20 46 40 34 3F 3F 20 3E 38 4C 46 43 34 36 38 7F 20 46 42 20 3C 47 20 46 3B 42 48 3F 37 41 7A 47 20 3B 34 49 38 20 47 34 3E 38 41 20 4C 42 48 20 47 42 42 20 3F 42 41 3A 20 47 42 20 37 38 36 45 4C 43 47 20 47 3B 3C 46 20 40 38 46 46 34 3A 38 01 20 2A 38 3F 3F 20 37 42 41 38 7F 20 4C 42 48 45 20 46 42 3F 48 47 3C 42 41 20 3C 46 20 39 37 34 41 40 3F 3A 3F 3A 35 41 34 01
我想你已经做过凯撒 I了,不是吗?
凯撒的最大问题是它不允许数字或其他字符。
我已经解决了这个问题,现在我可以在明文中使用任何ascii字符了。
键空间也从26增加到128。 \\ o /
请享用!
/********** 080502.c ************/
#include<stdio.h>
int b[1000] = {0};
int b2[1000] = {0};
int b_len = 0;
char strs[714]= "0,NUL,16,DLE,32, ,48,0,64,@,80,P,96,`,112,p,1,SOH,17,DC1,33,!,49,1,65,A,81,Q,97,a,113,q,2,STX,18,DC2,34,\",50,2,66,B,82,R,98,b,114,r,3,ETX,19,DC3,35,#,51,3,67,C,83,S,99,c,115,s,4,EOT,20,DC4,36,$,52,4,68,D,84,T,100,d,116,t,5,ENQ,21,NAK,37,%,53,5,69,E,85,U,101,e,117,u,6,ACK,22,SYN,38,&,54,6,70,F,86,V,102,f,118,v,7,BEL,23,ETB,39,',55,7,71,G,87,W,103,g,119,w,8,BS,24,CAN,40,(,56,8,72,H,88,X,104,h,120,x,9,HT,25,EM,41,),57,9,73,I,89,Y,105,i,121,y,10,LF,26,SUB,42,*,58,:,74,J,90,Z,106,j,122,z,11,VT,27,ESC,43,+,59,;,75,K,91,[,107,k,123,{,12,FF,28,FS,44,,,60,<,76,L,92,\\,108,l,124,|,13,CR,29,GS,45,-,61,=,77,M,93,],109,m,125,},14,SO,30,RS,46,.,62,>,78,N,94,^,110,n,126,~,15,SI,31,US,47,/,63,?,79,O,95,_,111,o,127,DEL,";
char words[128][5];//共有128个ascii码字符
void initial_words(){
int len = strlen(strs);
//printf("len=%d\n",len);
int i = 0;
int j = 0;
int result = 0;
memset(words,0,sizeof(words));
while(i < len) //strs的长度(字符的个数)
{
result = 0;
while(strs[i] != ',' && i < len)
{
result = result * 10 + (strs[i++] - '0');//计算对应的ascii十进制数值
}
i++;
j = 0;
while(strs[i] != ',' || i == 548) //逗号","本身作为分隔符存在,但是逗号本身也是一个ascii符号,这里需要做一下特殊处理,逗号对应的字符在strs中的下标是548
{
words[result][j++] = strs[i++];
}
//printf("%d\n%s\n----------------\n",result,words[result]);
i++;
}
}
int F_to_10(char *c,int i)
{
int re,re2 = 0;
re = (c[i] - '0') * 16;
if(c[i + 1] >= '0' && c[i + 1] <= '9')
{
re2 = c[i + 1] - '0';
}
else if(c[i + 1] >= 'A' && c[i + 1] <= 'F')
{
re2 = c[i + 1] - 'A' + 10;
}
else{
printf("不符合要求!\n");
return 0;
}
re += re2;
//printf("re=%d ",re);
return re;
}
void init_b()
{
char a[1000] = "32 5A 5A 4F 20 55 5A 4D 17 20 64 5A 60 20 5E 5A 57 61 50 4F 20 5A 59 50 20 58 5A 5D 50 20 4E 53 4C 57 57 50 59 52 50 20 54 59 20 64 5A 60 5D 20 55 5A 60 5D 59 50 64 19 20 3F 53 54 5E 20 5A 59 50 20 62 4C 5E 20 51 4C 54 5D 57 64 20 50 4C 5E 64 20 5F 5A 20 4E 5D 4C 4E 56 19 20 42 4C 5E 59 12 5F 20 54 5F 2A 20 1C 1D 23 20 56 50 64 5E 20 54 5E 20 4C 20 5C 60 54 5F 50 20 5E 58 4C 57 57 20 56 50 64 5E 5B 4C 4E 50 17 20 5E 5A 20 54 5F 20 5E 53 5A 60 57 4F 59 12 5F 20 53 4C 61 50 20 5F 4C 56 50 59 20 64 5A 60 20 5F 5A 5A 20 57 5A 59 52 20 5F 5A 20 4F 50 4E 5D 64 5B 5F 20 5F 53 54 5E 20 58 50 5E 5E 4C 52 50 19 20 42 50 57 57 20 4F 5A 59 50 17 20 64 5A 60 5D 20 5E 5A 57 60 5F 54 5A 59 20 54 5E 20 51 4F 4C 59 58 57 52 57 52 4D 59 4C 19";
int a_len = strlen(a);
for(int i = 0;i < a_len;i++)
{
if(i % 3 == 0)
{
b[b_len++] = F_to_10(a,i);
}
}
}
int main()
{
init_b();
initial_words();
for(int i = 0;i < 128;i++)
{
printf("%s",words[i]);
}
for(int i = 0;i < 128;i++)
{
for(int j = 0;j< b_len;j++)
{
b2[j] = (b[j] + i) % 128;
}
for(int j = 0;j< b_len;j++)
{
printf("%s",words[b2[j]]);
}
printf("\n\n");
}
return 0;
}