from logger import logger
-modular_division_table = [[0]*26 for _ in range(26)]
-for a in range(26):
- for b in range(26):
- c = (a * b) % 26
- modular_division_table[b][c] = a
+# modular_division_table = [[0]*26 for _ in range(26)]
+# for a in range(26):
+# for b in range(26):
+# c = (a * b) % 26
+# modular_division_table[b][c] = a
+modular_division_table = {
+ (multiplier, (multiplier * plaintext) % 26): plaintext
+ for plaintext in range(26)
+ for multiplier in range(26)
+ }
+
def affine_encipher_letter(accented_letter, multiplier=1, adder=0, one_based=True):
if letter in string.ascii_letters:
cipher_number = pos(letter)
if one_based: cipher_number += 1
+ # plaintext_number = (
+ # modular_division_table[multiplier]
+ # [(cipher_number - adder) % 26])
plaintext_number = (
- modular_division_table[multiplier]
- [(cipher_number - adder) % 26])
+ modular_division_table[multiplier, (cipher_number - adder) % 26]
+ )
if one_based: plaintext_number -= 1
if letter in string.ascii_uppercase:
return unpos(plaintext_number).upper()
'hellothereaa'
"""
adjoint = linalg.det(matrix)*linalg.inv(matrix)
- inverse_determinant = modular_division_table[int(round(linalg.det(matrix))) % 26][1]
+ inverse_determinant = modular_division_table[int(round(linalg.det(matrix))) % 26, 1]
inverse_matrix = (inverse_determinant * adjoint) % 26
return hill_encipher(inverse_matrix, message, fillvalue)