frequency_analysis(频率分析)

frequency_analysis

In cryptanalysis, frequency analysis is the study of the frequency of letters or groups of letters in a ciphertext. The method is used as an aid(0.0) to breaking classical ciphers.

Frequency analysis is based on the fact that, in any given stretch(范围) of written language, certain letters and combinations of letters occur with varying frequencies. Moreover, there is a characteristic distribution of letters that is roughly the same for almost all samples of that language. For instance, given a section of English language, E, T, A and O are the most common, while Z, Q and X are rare. Likewise, TH, ER, ON, and AN are the most common pairs of letters (termed bigrams or digraphs), and SS, EE, TT, and FF are the most common repeats. The nonsense phrase "ETAOIN SHRDLU" represents the 12 most frequent letters in typical English language text.

In some ciphers, such properties of the natural language plaintext are preserved in the ciphertext, and these patterns have the potential to be exploited in a ciphertext-only attack.

代码区:

统计:

def start():
filename=input("输入文件名称:")
print("-----文件名: "+filename+"-------")
with open(filename, 'r') as f:
file = f.read()
d={}
for i in file:
if(i.isalpha()):
if(d.get(i) == None):
d[i] = 0
d[i] = d.get(i) + 1
filename = filename+"_result"
with open(filename,"w") as f:
for k,v in d.items():
string =str(v)+" "+k+"\n" #将values写在前面有助于sort(偷懒)
f.write(string)
return "done"

使用 sort 进行排序
sort -n -r file

可以参考频率表

频率分析网站 http://www.richkni.co.uk/php/crypta/freq.php
然后猜猜猜(划重点)
然而对于我来说是太难了 0.0
毕竟母语不是英文,对单词模式没有辨识度


今日诗词
posted @   兔子春  阅读(72)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示