code-break-party/code/frequency.py

28 lines
472 B
Python
Raw Normal View History

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()