From: Neil Smith Date: Thu, 3 Oct 2013 19:34:21 +0000 (+0100) Subject: Can now do frequency analysis X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=e6aea9194297e503e6b2887f1756ce5dc4d6f078;p=cipher-tools.git Can now do frequency analysis --- diff --git a/cipher.py b/cipher.py index f938f36..c4b28ba 100644 --- a/cipher.py +++ b/cipher.py @@ -1,4 +1,5 @@ import string +import collections def caesar_cipher_letter(letter, shift): @@ -21,3 +22,11 @@ def caesar_cipher_message(message, shift): def caesar_decipher_message(message, shift): return caesar_cipher_message(message, -shift) + +def letter_frequencies(message): + frequencies = collections.defaultdict(int) + for letter in message: + if letter in string.ascii_letters: + frequencies[letter.lower()]+=1 + return frequencies +