From 38f3707a2337652adf616b47b2f35f3f20d433bd Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 25 Oct 2013 10:58:15 +0100 Subject: [PATCH] Tidied affine cipher and decipher --- cipher.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cipher.py b/cipher.py index 0e89a9c..273da46 100644 --- a/cipher.py +++ b/cipher.py @@ -194,7 +194,6 @@ def affine_encipher_letter(letter, multiplier=1, adder=0, one_based=True): if one_based: letter_number += 1 raw_cipher_number = (letter_number * multiplier + adder) - cipher_number = 0 if one_based: cipher_number = (raw_cipher_number - 1) % 26 else: @@ -217,13 +216,9 @@ def affine_decipher_letter(letter, multiplier=1, adder=0, one_based=True): else: alphabet_start = ord('a') cipher_number = ord(letter) - alphabet_start - if one_based: - cipher_number += 1 - plaintext_number = 0 if one_based: - plaintext_number = (modular_division_table_one_based[multiplier][(cipher_number - adder + 26) % 26] - 1) % 26 + plaintext_number = (modular_division_table_one_based[multiplier][(cipher_number + 1 - adder + 26) % 26] - 1) % 26 else: - #plaintext_number = (modular_division_table[multiplier][cipher_number] - adder) % 26 plaintext_number = modular_division_table[multiplier][(cipher_number - adder + 26) % 26] return chr(plaintext_number + alphabet_start) else: -- 2.34.1