ADFGVX 张天豪 陆纪圆
古典密码:德国陆军强于恺撒 Plaintext: field cipher key 左上:26个字母和10个数字的polybius方格,构成由adfgvx的第一次加密函数。 Rifle称为移位秘钥。在密文方格上面写上,按照字母次序按列遍历,形成最终密文。 解码结果:findthewapons
加密代码分析 const char table[6]={'A','D','F','G','V','X'}; struct ttt{ char x; int pos; }order[100]; int order_num; const char a[6][6]={{'B','3','M','R','L','I'}, {'A','6','F','*','8','2'}, {'C','7','S','E','U','H'}, {'Z','9','D','X','K','V'}, {'1','Q','Y','W','5','P'}, {'N','J','T','4','G','O'}};
加密代码分析 int main() { string s;string trans; cout<<"Plaintext: "; while(cin>>s){ cout<<"Transposition key: "; cin>>trans; int len=s.length(); for(int i=0;i<len;i++) s[i]=toupper(s[i]); string ans=encode(s,len,trans); cout<<"Ciphertext: "<<ans<<endl<<endl; cout<<"Plaintext: "; } return 0;
加密代码分析 string encode(string s,int len,string trans){ string ans=""; //phase 1 for(int i=0;i<len;i++){ string tmp=find(s[i]); if(tmp=="") return "Unsupported message!"; ans+=tmp; } string find(char x){ string ret=""; for(int i=0;i<6;i++) for(int j=0;j<6;j++) if(x==a[i][j]) { char tmp=table[i]; char tmp2=table[j]; ret+=tmp;ret+=tmp2; return ret; }
加密代码分析 void initorder(string trans){ order_num=trans.length(); //phase 2 initorder(trans); int len2=ans.length(); string ret=""; for(int i=0;i<order_num;i++){ int st=order[i].pos; while(st<len2){ ret+=ans[st]; st+=order_num; } return ret; void initorder(string trans){ order_num=trans.length(); for(int i=0;i<order_num;i++){ order[i].x=toupper(trans[i]); order[i].pos=i; } sort(order,order+order_num,cmp);
加密实例
解密部分