From e6aea9194297e503e6b2887f1756ce5dc4d6f078 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Thu, 3 Oct 2013 20:34:21 +0100 Subject: [PATCH] Can now do frequency analysis --- cipher.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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 + -- 2.34.1