https://blog.csdn.net/baiduwaimai/article/details/106473268
信息中的每一个字母都被另一个独特的字母替换了(和凯撒密码有点像吧,但不是顺推替换)
XACTZBGKU ZVK XADDKXSGBI ZBL USAVGBI CAVK GBJAVCZSGAB SHZB KQKV YKJAVK,XKCKBSGBI SHK GCTAVSZBXK AJ YASH LZSZ TVGQZXN ZBL LZSZ UKXRVGSN. BAP CAVK SHZB KQKV GS GU XVGSGXZD SA TVASKXS XABJGLKBSGZD GBJAVCZSGAB ZBL KBURVK YRUGBKUU XABSGBRGSN SHVARIH Z VAYRUS LZSZ TVASKXSGAB USVZSKIN. PK UHARDL XAQKV SHK EKN XABXKTSU AJ LZSZ TVGQZXN ZBL LZSZ UKXRVGSN SA HKDT LGJJKVKBSGZSK SHK SPA. SHK SKVCU LZSZ TVGQZXN ZBL LZSZ UKXRVGSN ZVK AJSKB CGURBLKVUSAAL ZBL RUKL GBSKVXHZBIKZYDN.HAPKQKV, SHKN ZVK SPA UKTZVZSK XABXKTSU SHZS PAVE GB SZBLKC SA EKKT LZSZ UZJK. LZSZ TVGQZXN JAXRUKU AB HAP GBJAVCZSGAB GU HZBLDKL, USAVKL, ZBL RUKL. PHGDK LZSZ UKXRVGSN GU XABXKVBKL PGSH TVASKXSGBI SHK ZUUKS AJ NARV AVIZBGMZSGAB.
quipqiup - cryptoquip and cryptogram solver
该网站可以直接进行解密
下面演示频率分析解密过程(其实大部分也都还是在猜)
给定英语单词出现频率表
import numpy as np
import matplotlib.pyplot as plt
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ,.'
count = np.zeros(29)
string = """XACTZBGKU ZVK XADDKXSGBI ZBL USAVGBI CAVK GBJAVCZSGAB SHZB KQKV YKJAVK,XKCKBSGBI SHK GCTAVSZBXK AJ YASH LZSZ TVGQZXN ZBL LZSZ UKXRVGSN. BAP CAVK SHZB KQKV GS GU XVGSGXZD SA TVASKXS XABJGLKBSGZD GBJAVCZSGAB ZBL KBURVK YRUGBKUU XABSGBRGSN SHVARIH Z VAYRUS LZSZ TVASKXSGAB USVZSKIN. PK UHARDL XAQKV SHK EKN XABXKTSU AJ LZSZ TVGQZXN ZBL LZSZ UKXRVGSN SA HKDT LGJJKVKBSGZSK SHK SPA. SHK SKVCU LZSZ TVGQZXN ZBL LZSZ UKXRVGSN ZVK AJSKB CGURBLKVUSAAL ZBL RUKL GBSKVXHZBIKZYDN.HAPKQKV, SHKN ZVK SPA UKTZVZSK XABXKTSU SHZS PAVE GB SZBLKC SA EKKT LZSZ UZJK. LZSZ TVGQZXN JAXRUKU AB HAP GBJAVCZSGAB GU HZBLDKL, USAVKL, ZBL RUKL. PHGDK LZSZ UKXRVGSN GU XABXKVBKL PGSH TVASKXSGBI SHK ZUUKS AJ NARV AVIZBGMZSGAB."""
N = len(string)
for char in string:
index = alphabet.index(char)
count[index] += 1
N -= count[-1]
N -= count[-2]
N -= count[-3]
count = count[0:26]
count = count / N
tick1 = [chr(i + ord('A')) for i in range(26)]
# 绘制第一个条形图
plt.figure(figsize=(10, 8)) # 设置图形的大小
plt.subplot(3, 1, 1) # 创建一个2行1列的子图,并选择第1个子图
plt.bar(tick1, count)
plt.title('Letter Frequency') # 设置标题
plt.xlabel('Letter') # 设置x轴标签
plt.ylabel('Frequency') # 设置y轴标签
# 将 count 和 tick1 组合成一个元组列表,并根据 count 降序排序
sorted_pairs = sorted(zip(count, tick1), key=lambda x: x[0], reverse=True)
# 排序后的 count 和 tick1
sorted_count = [pair[0] for pair in sorted_pairs]
sorted_tick1 = [pair[1] for pair in sorted_pairs]
# 绘制第二个条形图
plt.subplot(3, 1, 2) # 选择第2个子图
plt.bar(sorted_tick1, sorted_count)
plt.title('Letter Frequency (Sorted)') # 设置标题
plt.xlabel('Letter') # 设置x轴标签
plt.ylabel('Frequency') # 设置y轴标签
code2 = ['E', 'T', 'A', 'O', 'I', 'N', 'S', 'H', 'R', 'D', 'L', 'C', 'U', 'M', 'W', 'F', 'G', 'Y', 'P', 'B', 'V', 'K',
'J', 'X', 'Q', 'Z']
count2 = [12.7, 9.1, 8.2, 7.5, 7, 6.7, 6.3, 6.1, 6.0, 4.3, 4.0, 2.8, 2.8, 2.4, 2.4, 2.2, 2.0, 2.0, 1.9, 1.5, 1.0, 0.8,
0.2, 0.2, 0.1, 0.1]
count2 = [x / 100 for x in count2]
plt.subplot(3, 1, 3) # 选择第2个子图
plt.bar(code2, count2)
plt.title('Letter Frequency (ALL)') # 设置标题
plt.xlabel('Letter') # 设置x轴标签
plt.ylabel('Frequency') # 设置y轴标签
plt.tight_layout() # 调整子图布局以防止标签重叠
plt.show() # 显示图形
result = []
for char in string:
if char == ' ':
result.append(' ')
elif char == ',':
result.append(',')
elif char == '.':
result.append('.')
else:
ind = sorted_tick1.index(char)
result.append(code2[ind])
print(''.join(result))
初步解密结果如下:
DOFMAINTH AST DOGGTDENIP AIR HEOSNIP FOST NIWOSFAENOI ELAI TBTS VTWOST,DTFTIENIP ELT NFMOSEAIDT OW VOEL RAEA MSNBADU AIR RAEA HTDCSNEU. IOY FOST ELAI TBTS NE NH DSNENDAG EO MSOETDE DOIWNRTIENAG NIWOSFAENOI AIR TIHCST VCHNITHH DOIENICNEU ELSOCPL A SOVCHE RAEA MSOETDENOI HESAETPU. YT HLOCGR DOBTS ELT KTU DOIDTMEH OW RAEA MSNBADU AIR RAEA HTDCSNEU EO LTGM RNWWTSTIENAET ELT EYO. ELT ETSFH RAEA MSNBADU AIR RAEA HTDCSNEU AST OWETI FNHCIRTSHEOOR AIR CHTR NIETSDLAIPTAVGU.LOYTBTS, ELTU AST EYO HTMASAET DOIDTMEH ELAE YOSK NI EAIRTF EO KTTM RAEA HAWT. RAEA MSNBADU WODCHTH OI LOY NIWOSFAENOI NH LAIRGTR, HEOSTR, AIR CHTR. YLNGT RAEA HTDCSNEU NH DOIDTSITR YNEL MSOETDENIP ELT AHHTE OW UOCS OSPAINJAENOI.
由于这段话的数据量不够,所以频率不一定能反映字母的概率,所以排序会有误差。
解密的文本,字符A单独作为单词出现,所以A确认无误
解密文本中出现多个OW,推测为OF或OR。又W和F在总的频率中差不多,所以推测为OF。即W->F
EO,由于E、T对应的密文中S、K。S、K在密文中出现频率差不多,所以推测为TO。即E->T
解密文本中出现大量ELT,由于E->T,所以推测ELT为THE。即E->T、L->H、T->E
解密文本中出现大量AST,由于T->E,又S和R的频率相近,所以推测AST为ARE。即S->R
text='''DOFMAINTH AST DOGGTDENIP AIR HEOSNIP FOST NIWOSFAENOI ELAI TBTS VTWOST,DTFTIENIP ELT NFMOSEAIDT OW VOEL RAEA MSNBADU AIR RAEA HTDCSNEU. IOY FOST ELAI TBTS NE NH DSNENDAG EO MSOETDE DOIWNRTIENAG NIWOSFAENOI AIR TIHCST VCHNITHH DOIENICNEU ELSOCPL A SOVCHE RAEA MSOETDENOI HESAETPU. YT HLOCGR DOBTS ELT KTU DOIDTMEH OW RAEA MSNBADU AIR RAEA HTDCSNEU EO LTGM RNWWTSTIENAET ELT EYO. ELT ETSFH RAEA MSNBADU AIR RAEA HTDCSNEU AST OWETI FNHCIRTSHEOOR AIR CHTR NIETSDLAIPTAVGU.LOYTBTS, ELTU AST EYO HTMASAET DOIDTMEH ELAE YOSK NI EAIRTF EO KTTM RAEA HAWT. RAEA MSNBADU WODCHTH OI LOY NIWOSFAENOI NH LAIRGTR, HEOSTR, AIR CHTR. YLNGT RAEA HTDCSNEU NH DOIDTSITR YNEL MSOETDENIP ELT AHHTE OW UOCS OSPAINJAENOI.'''
res=""
for i in text:
if i=='W':
res+='F'
elif i=='E':
res+='T'
elif i=='L':
res+='H'
elif i=='T':
res+='E'
elif i=='S':
res+='R'
elif i in ['F','H','R']:
res+=i+"'" #打上个标记,为了区分原本的密文中的F和原文中的F
else:
res+=i
print(res)
DOF’MAINEH’ ARE DOGGEDTNIP AIR’ H’TORNIP F’ORE NIFORF’ATNOI THAI EBER VEFORE,DEF’EITNIP THE NF’MORTAIDE OF VOTH R’ATA MRNBADU AIR’ R’ATA H’EDCRNTU. IOY F’ORE THAI EBER NT NH’ DRNTNDAG TO MROTEDT DOIFNR’EITNAG NIFORF’ATNOI AIR’ EIH’CRE VCH’NIEH’H’ DOITNICNTU THROCPH A ROVCH’T R’ATA MROTEDTNOI H’TRATEPU. YE H’HOCGR’ DOBER THE KEU DOIDEMTH’ OF R’ATA MRNBADU AIR’ R’ATA H’EDCRNTU TO HEGM R’NFFEREITNATE THE TYO. THE TERF’H’ R’ATA MRNBADU AIR’ R’ATA H’EDCRNTU ARE OFTEI F’NH’CIR’ERH’TOOR’ AIR’ CH’ER’ NITERDHAIPEAVGU.HOYEBER, THEU ARE TYO H’EMARATE DOIDEMTH’ THAT YORK NI TAIR’EF’ TO KEEM R’ATA H’AFE. R’ATA MRNBADU FODCH’EH’ OI HOY NIFORF’ATNOI NH’ HAIR’GER’, H’TORER’, AIR’ CH’ER’. YHNGE R’ATA H’EDCRNTU NH’ DOIDERIER’ YNTH MROTEDTNIP THE AH’H’ET OF UOCR ORPAINJATNOI.
THEU ARE 推测为they are。即U->Y
UOCR,又U->Y,且C和U频率相似,推测为your。即C->U
AIR’和R’ATA。推测R’为D。即R->D,I->N
D’OF’MANN’EH’ ARE D’OGGED’TN’NP AND H’TORN’NP F’ORE N’NFORF’ATN’ON THAN EBER VEFORE,D’EF’ENTN’NP THE N’F’MORTAND’E OF VOTH DATA MRN’BAD’Y AND DATA H’ED’URN’TY. NOY’ F’ORE THAN EBER N’T N’H’ D’RN’TN’D’AG TO MROTED’T D’ONFN’DENTN’AG N’NFORF’ATN’ON AND ENH’URE VUH’N’NEH’H’ D’ONTN’NUN’TY THROUPH A ROVUH’T DATA MROTED’TN’ON H’TRATEPY. Y’E H’HOUGD D’OBER THE KEY D’OND’EMTH’ OF DATA MRN’BAD’Y AND DATA H’ED’URN’TY TO HEGM DN’FFERENTN’ATE THE TY’O. THE TERF’H’ DATA MRN’BAD’Y AND DATA H’ED’URN’TY ARE OFTEN F’N’H’UNDERH’TOOD AND UH’ED N’NTERD’HANPEAVGY.HOY’EBER, THEY ARE TY’O H’EMARATE D’OND’EMTH’ THAT Y’ORK N’N TANDEF’ TO KEEM DATA H’AFE. DATA MRN’BAD’Y FOD’UH’EH’ ON HOY’ N’NFORF’ATN’ON N’H’ HANDGED, H’TORED, AND UH’ED. Y’HN’GE DATA H’ED’URN’TY N’H’ D’OND’ERNED Y’N’TH MROTED’TN’NP THE AH’H’ET OF YOUR ORPANN’JATN’ON.
THEY ARE TY’O 推测 Y->W
AH’H’ET 推测为asset。即H->S
D’OF’MANN’ES ARE D’OGGED’TN’NP AND STORN’NP F’ORE N’NFORF’ATN’ON THAN EBER VEFORE,D’EF’ENTN’NP THE N’F’MORTAND’E OF VOTH DATA MRN’BAD’Y AND DATA SED’URN’TY. NOW F’ORE THAN EBER N’T N’S D’RN’TN’D’AG TO MROTED’T D’ONFN’DENTN’AG N’NFORF’ATN’ON AND ENSURE VUSN’NESS D’ONTN’NUN’TY THROUPH A ROVUST DATA MROTED’TN’ON STRATEPY. WE SHOUGD D’OBER THE KEY D’OND’EMTS OF DATA MRN’BAD’Y AND DATA SED’URN’TY TO HEGM DN’FFERENTN’ATE THE TWO. THE TERF’S DATA MRN’BAD’Y AND DATA SED’URN’TY ARE OFTEN F’N’SUNDERSTOOD AND USED N’NTERD’HANPEAVGY.HOWEBER, THEY ARE TWO SEMARATE D’OND’EMTS THAT WORK N’N TANDEF’ TO KEEM DATA SAFE. DATA MRN’BAD’Y FOD’USES ON HOW N’NFORF’ATN’ON N’S HANDGED, STORED, AND USED. WHN’GE DATA SED’URN’TY N’S D’OND’ERNED WN’TH MROTED’TN’NP THE ASSET OF YOUR ORPANN’JATN’ON.
EBER推测为EVER,即B->V
F’ORE推测为MORE,即F->M
D’OMM’ANN’ES ARE D’OGGED’TN’NP AND STORN’NP MORE N’NFORMATN’ON THAN EVER V’EFORE,D’EMENTN’NP THE N’MM’ORTAND’E OF V’OTH DATA M’RN’VAD’Y AND DATA SED’URN’TY. NOW MORE THAN EVER N’T N’S D’RN’TN’D’AG TO M’ROTED’T D’ONFN’DENTN’AG N’NFORMATN’ON AND ENSURE V’USN’NESS D’ONTN’NUN’TY THROUPH A ROV’UST DATA M’ROTED’TN’ON STRATEPY. WE SHOUGD D’OVER THE KEY D’OND’EM’TS OF DATA M’RN’VAD’Y AND DATA SED’URN’TY TO HEGM’ DN’FFERENTN’ATE THE TWO. THE TERMS DATA M’RN’VAD’Y AND DATA SED’URN’TY ARE OFTEN MN’SUNDERSTOOD AND USED N’NTERD’HANPEAV’GY.HOWEVER, THEY ARE TWO SEM’ARATE D’OND’EM’TS THAT WORK N’N TANDEM TO KEEM’ DATA SAFE. DATA M’RN’VAD’Y FOD’USES ON HOW N’NFORMATN’ON N’S HANDGED, STORED, AND USED. WHN’GE DATA SED’URN’TY N’S D’OND’ERNED WN’TH M’ROTED’TN’NP THE ASSET OF YOUR ORPANN’JATN’ON.
N’NFORMATN’ON推测为information,即N-I
V’EFORE推测为Before,即V->B
SEM’ARATE 推测为separate,即M->P
D’OMPANIES ARE D’OGGED’TINP’ AND STORINP’ MORE INFORMATION THAN EVER BEFORE,D’EMENTINP’ THE IMPORTAND’E OF BOTH DATA PRIVAD’Y AND DATA SED’URITY. NOW MORE THAN EVER IT IS D’RITID’AG TO PROTED’T D’ONFIDENTIAG INFORMATION AND ENSURE BUSINESS D’ONTINUITY THROUP’H A ROBUST DATA PROTED’TION STRATEP’Y. WE SHOUGD D’OVER THE KEY D’OND’EPTS OF DATA PRIVAD’Y AND DATA SED’URITY TO HEGP DIFFERENTIATE THE TWO. THE TERMS DATA PRIVAD’Y AND DATA SED’URITY ARE OFTEN MISUNDERSTOOD AND USED INTERD’HANP’EABGY.HOWEVER, THEY ARE TWO SEPARATE D’OND’EPTS THAT WORK IN TANDEM TO KEEP DATA SAFE. DATA PRIVAD’Y FOD’USES ON HOW INFORMATION IS HANDGED, STORED, AND USED. WHIGE DATA SED’URITY IS D’OND’ERNED WITH PROTED’TINP’ THE ASSET OF YOUR ORP’ANIJATION.
D’OMPANIES推测为companies,即D->C
STORINP’推测为storing,即P->G
D’OGGED’TINP’,推测为collecting,即G->L
COMPANIES ARE COLLECTING AND STORING MORE INFORMATION THAN EVER BEFORE,CEMENTING THE IMPORTANCE OF BOTH DATA PRIVACY AND DATA SECURITY. NOW MORE THAN EVER IT IS CRITICAL TO PROTECT CONFIDENTIAL INFORMATION AND ENSURE BUSINESS CONTINUITY THROUGH A ROBUST DATA PROTECTION STRATEGY. WE SHOULD COVER THE KEY CONCEPTS OF DATA PRIVACY AND DATA SECURITY TO HELP DIFFERENTIATE THE TWO. THE TERMS DATA PRIVACY AND DATA SECURITY ARE OFTEN MISUNDERSTOOD AND USED INTERCHANGEABLY.HOWEVER, THEY ARE TWO SEPARATE CONCEPTS THAT WORK IN TANDEM TO KEEP DATA SAFE. DATA PRIVACY FOCUSES ON HOW INFORMATION IS HANDLED, STORED, AND USED. WHILE DATA SECURITY IS CONCERNED WITH PROTECTING THE ASSET OF YOUR ORGANIZATION.