example for for computing letter frequency
This commit is contained in:
parent
8639088565
commit
a93eb46871
1
code/ciphertext.txt
Normal file
1
code/ciphertext.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Tg stgsf Djia tf Ejnsg, nm dseqs stg Ajeetq. Gtiaq tg stgsf csriaqsg, piafrqythsg Djia, vj sp gmia Fjnso otsiaq rgn Vrofytkcsd ujg nsg Vmsgnsg asomeamsghsg, rgn mria gtiaq tg stgso qojibsgsg, bmadsg Pmgnhores jags Qtpias rgn Pqrsads, vj fmg ptia yrf Sppsg atgpsqysg bjsggqs: gstg, nmp Djia vmo stgs Ajeetqajsads, rgn nmp astppq, sp vmo psao bjfcjoqmesd.
|
27
code/frequency.py
Normal file
27
code/frequency.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import matplotlib.pyplot as plt
|
||||
|
||||
f = open('ciphertext.txt')
|
||||
|
||||
ciphertext = f.readline().upper()
|
||||
|
||||
letter_count = {}
|
||||
|
||||
letters = [chr(i) for i in range(ord('A'), ord('Z')+1)]
|
||||
|
||||
for c in letters:
|
||||
letter_count[c] = 0
|
||||
|
||||
for c in ciphertext:
|
||||
if c in letter_count.keys():
|
||||
letter_count[c] += 1
|
||||
|
||||
print(letter_count)
|
||||
|
||||
x = range(0,26)
|
||||
y = [letter_count[chr(ord('A')+i)] for i in range(0,26)]
|
||||
|
||||
plt.bar(x, y)
|
||||
plt.xticks(x, letters) # Set locations and labels
|
||||
|
||||
|
||||
plt.show()
|
Loading…
Reference in New Issue
Block a user