gvknipiwyhzrqfsmjbknsqfcdexpkrmspoducuqaixhmrdknscqydxhmryrzjijjmosfdnqtecxeikmsozzzlfnbspqaoipxaixmddorzxtsgnmmspqnemlirgeoslaqsbsplcsmfmegjixdbnxktenixilqylelgzwplydxddvbfstzvyzjaqsxnfnptniilyreeeamdmjzwghjopvblfqlttbhnrnva
思路分析:
1将密文输出成对应的ASCII码,减去97得到a~z范围为0~25,然后分成3*75的矩阵。 ○
2选取1*3矩阵[0 0 0]到[25 25 25]总共26*26*26个乘以上述矩阵并模26得到1*75的矩阵,○
统计0~25的个数记为Oi(i为0~25)。 3利用公式 ○
计算出g值,并对其进行由大到小排序,选出前50组对应的矩阵。
4在这前50组中任取3组组成3*3矩阵○(排除有约数有2和13的),右乘3*75矩阵,然后计算出0~25出现的频率(近似看成概率),根据统计规律比较,选出可能的明文。 5从这些可能的明文中按照意义找出需要的明文。 ○
字母统计规律
程序代码如下: clc;
clear all;
fid=fopen('ciphertext.txt'); %打开要读的文本
ciphertext=fread(fid)-97; %读取文本,并表示成0~25之间的数 fclose(fid); %关闭文本
A=reshape(ciphertext,3,75); %将明文矩阵重新排列成3*75的矩阵
P=[8.167;1.492;2.782;4.253;12.702;2.228;... %统计概率矩阵 2.015;6.094;6.966;0.153;0.772;4.025;... 2.406;6.749;7.507;1.929;0.095;5.987;... 6.327;9.056;2.758;0.978;2.360;0.150;... 1.974;0.074]./100;
G=zeros(17576,1); %记录g的值
H=zeros(17576,3); %记录对应的矩阵
for i=0:25 %用0~25产生26*26*26中矩阵 for j=0:25
for k=0:25
B=[i j k]; C=B*A;
D=mod(C,26);
O=zeros(26,1); %分别统计0~25的个数 num=1;den=1; for m=1:26 for n=1:75 if D(n)==m-1 O(m)=O(m)+1; end end
num=P(m)^O(m)*num; %计算分子 den=factorial(O(m))*den;%计算分母 end
G(676*i+26*j+k+1,1)=num/den; H(676*i+26*j+k+1,:)=B; end end
end
[X,Y]=sort(G,'descend'); %Y表示按从大到小对应的下标 M=Y(1:50); %找出前50大数对应的下标 for i=1:50
F(i,:)=H(M(i),:); %求出最大值所对应的矩阵B end
index=nchoosek(1:10,3); %产生所取矩阵的行 for i=1:120
Q=[F(index(i,1),:);F(index(i,2),:);F(index(i,3),:)]; %得到可能的加密矩阵
if (mod(det(Q),2)~=0)&&(mod(det(Q),13)~=0) plaintext=mod(Q*A,26);
E=reshape(plaintext,225,1); %将可能的明文重排 n=0:25;
[R,S]=hist(E,n); %得到0~25出现的个数,R表示个数 N=(R/length(plaintext))'; %计算出频率 DIFF=P-N; %计算明文与统计规律之差 V=DIFF.*DIFF./P; %计算差值的平方 SUM=sum(V); %求差值平方的和
Z(i,:)=SUM; %记录差值以及对应的矩阵 end end
K=find(Z(:)>0); %找出>0的 J=[Z(K(:)),K];
[x,y]=sort(J(:,1)); %x表示卡方由小到大排列,y保存卡方由小到大时对应的
for i=1:5
m=y(i);
Q=[F(index(m,1),:);F(index(m,2),:);F(index(m,3),:)]; plaintext=mod(Q*A,26);
E=reshape(plaintext,225,1)+97;
plaintext= fprintf('可能的plaintext(%d):\\n%s\\n',i,E); end
执行结果:
可能的plaintext(1):
copebreaeiniisvhehosbimvorbannfosmozsesreeinvelrigincninvhehorbdtddaditvroeucusmschcoroannmumhmhreerurtwtrteyilfosmaziovthtnsaieiannthtsifteglileneeererrsgfearinvlulncnupuntaepelilieiofoovornrenrsystighahneaerradachponoclcrxe
可能的plaintext(2):
codebreakingisthemostimportantformofsecretintelligenceintheworldtodayitproducesmuchmoreandmuchmoretrustworthyinformationthanspiesandthisintelligenceexertsgreatinfluenceuponthepoliciesofgovernmentsyetithasneverhadachroniclerxx
可能的plaintext(3):
cocebweaminiisshetoseimuorcansfolmocseyrevinielyigoncdinihexoredtvdanitirotucesmqchcorwanwmushmprevrultwhrtpyimfolmaqiosthnnsdieaanwthlsiateblirenoeeuerisgieaainslujncdupinthepclifieaofeovernfenasystihhadneteryadgcheonaclmrxt
可能的plaintext(4):
cobebaeayinjistheyosdimhoroanafotmojsemretinweluiginceinwheyorodtrdasitironucusmcchnorbanamuihmoretrumtwcrtkyirfotmahiolthlnsxieeanathlsihteflieenleetergsgdealinwlucnceuphntmepplieieeofdovjrnlenysyatinhaqnevergadtchaontclvrxs
可能的plaintext(5):
cdcerwekmigiitshmtoteipuotcatsfrlmfcscyrtvitielyieoneditihwxoledovdynipirdtueesuqcmcoewadwmcshoprtvrsltohrhpynmfrlmtqinstannpdisaadwtilsnatlblgrecoexuetisrietaifslejneduoinhheoclcfisaogeoeermfetasestthhsdnvtehyaagcreoiacemrxt
根据意思合理性选出明文2为:
code breaking is the most important form of secret intelligence in the world today .it produces much more and much more trust worthy information than spies and this intelligence exerts great influence upon the policies of governments .yet it has never had a chronicler. xx
解密矩阵为:
因篇幅问题不能全部显示,请点此查看更多更全内容