X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=cipher.py;h=248155edb8a54956df51348a64fc26c9532db339;hb=3d8f7067b9c3a48ef140d7cff834d18ee91f58b3;hp=b3ab488db74c3af8090aefcc2396c2d503725064;hpb=3b82269b94de43fa0150fe5b34ca39b4ba3b6ba4;p=cipher-tools.git diff --git a/cipher.py b/cipher.py index b3ab488..248155e 100644 --- a/cipher.py +++ b/cipher.py @@ -1,39 +1,31 @@ -import string -import collections +# import string +# import collections +# import math +# from enum import Enum +# from itertools import zip_longest, cycle, chain, count +# import numpy as np +# from numpy import matrix +# from numpy import linalg +# from language_models import * +# import pprint -english_counts = collections.defaultdict(int) -with open('count_1l.txt', 'r') as f: - for line in f: - (letter, count) = line.split("\t") - english_counts[letter] = int(count) -def sanitise(text): - sanitised = [c.lower() for c in text if c in string.ascii_letters] - return ''.join(sanitised) -def letter_frequencies(message): - frequencies = collections.defaultdict(int) - for letter in sanitise(message): - frequencies[letter]+=1 - return frequencies +from utilities import * +from segment import * +from text_prettify import * +from plot_frequency_histogram import * -def caesar_cipher_letter(letter, shift): - if letter in string.ascii_letters: - if letter in string.ascii_lowercase: - return chr((ord(letter) - ord('a') + shift) % 26 + ord('a')) - else: - new_letter = letter.lower() - yolo = chr((ord(new_letter) - ord('a') + shift) % 26 + ord('a')) - return yolo.upper() - else: - return letter +from caesar import * +from affine import * +from keyword import * +from polybius import * +from column_transposition import * +from railfence import * +from cadenus import * +from hill import * +from amsco import * +from bifid import * +from autokey import * +from pocket_enigma import * -def caesar_decipher_letter(letter, shift): - return caesar_cipher_letter(letter, -shift) - -def caesar_cipher_message(message, shift): - big_cipher = [caesar_cipher_letter(l, shift) for l in message] - return ''.join(big_cipher) - -def caesar_decipher_message(message, shift): - return caesar_cipher_message(message, -shift)