Created
April 12, 2020 07:42
-
-
Save RaminMammadzada/de98c42a0f1ad35f0391efc6f6f164e0 to your computer and use it in GitHub Desktop.
The frequencies of the letter in the text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The following English text was encrypted using a substitution cipher that shuffles the alphabet rather than just shifting it. | |
Can you find what the following letters l and h stand for in the following text ? | |
hm al, mo tmh hm al, huvh gn hul jzlnhgmt: | |
qulhulo 'hgn tmaxlo gt hul cgty hm nzrrlo | |
hul nxgtsn vty voomqn mr mzhovslmzn rmohztl, | |
mo hm hvel vocn vsvgtnh v nlv mr homzaxln | |
vty ak mppmngts lty hulc? | |
hm ygl: hm nxllp; | |
tm cmol; vty, ak v nxllp hm nvk ql lty | |
hul ulvoh-vwul vty hul humznvty tvhzovx numwen | |
huvh rxlnu gn ulgo hm, 'hgn v wmtnzccvhgmt | |
yldmzhxk hm al qgnu'y. hm ygl, hm nxllp; | |
hm nxllp: plowuvtwl hm yolvc: vk, hulol'n hul oza; | |
rmo gt huvh nxllp mr ylvhu quvh yolvcn cvk wmcl | |
qult ql uvdl nuzrrxly mrr hugn cmohvx wmgx, | |
cznh sgdl zn pvznl | |
""" | |
from collections import OrderedDict | |
def findLetterFrequency(ciphertext): | |
frequencies = {} | |
for letter in ciphertext: | |
if( frequencies.get(letter) == None ): | |
frequencies[letter] = 1 | |
else: | |
frequencies[letter] += 1 | |
frequencies = OrderedDict(sorted(frequencies.items(), key=lambda x: x[1])) | |
# print all letter frequencies | |
for letter, frequency in frequencies.items(): | |
print(letter + ": " + str(frequency)) | |
ciphertext = "hm al, mo tmh hm al, huvh gn hul jzlnhgmt:" \ | |
"qulhulo 'hgn tmaxlo gt hul cgty hm nzrrlo" \ | |
"hul nxgtsn vty voomqn mr mzhovslmzn rmohztl," \ | |
"mo hm hvel vocn vsvgtnh v nlv mr homzaxln" \ | |
"vty ak mppmngts lty hulc?" \ | |
"hm ygl: hm nxllp;" \ | |
"tm cmol; vty, ak v nxllp hm nvk ql lty" \ | |
"hul ulvoh-vwul vty hul humznvty tvhzovx numwen" \ | |
"huvh rxlnu gn ulgo hm, 'hgn v wmtnzccvhgmt" \ | |
"yldmzhxk hm al qgnu'y. hm ygl, hm nxllp;" \ | |
"hm nxllp: plowuvtwl hm yolvc: vk, hulol'n hul oza;" \ | |
"rmo gt huvh nxllp mr ylvhu quvh yolvcn cvk wmcl" \ | |
"qult ql uvdl nuzrrxly mrr hugn cmohvx wmgx," \ | |
"cznh sgdl zn pvznl" | |
findLetterFrequency(ciphertext) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment