Reformatting code

This commit is contained in:
Patrick Müller 2021-10-15 17:57:35 +02:00
parent 80ebb362a5
commit f13b667e6c
3 changed files with 23 additions and 21 deletions

View File

@ -18,8 +18,8 @@ def encrypt_text(cleartext: str, key: int):
for char in cleartext:
index = au.get_index_of_letter(char)
newIndex = (index * key) % 26
resulting += au.get_letter_at_index(newIndex)
new_index = (index * key) % 26
resulting += au.get_letter_at_index(new_index)
return resulting
@ -41,8 +41,8 @@ def decrypt_text(ciphertext: str, key: int):
for char in ciphertext:
index = au.get_index_of_letter(char)
newIndex = (index * decrypt_key) % 26
resulting += au.get_letter_at_index(newIndex)
new_index = (index * decrypt_key) % 26
resulting += au.get_letter_at_index(new_index)
return resulting

View File

@ -13,10 +13,10 @@ def encrypt_text(cleartext: str, key: [int]):
resulting = ''
for char in cleartext:
charIndex = au.get_index_of_letter(char)
cipherIndex = key.index(charIndex)
cipherChar = au.get_letter_at_index(cipherIndex)
resulting += cipherChar
char_index = au.get_index_of_letter(char)
cipher_index = key.index(char_index)
cipher_char = au.get_letter_at_index(cipher_index)
resulting += cipher_char
return resulting
@ -31,10 +31,10 @@ def decrypt_text(ciphertext: str, key: [int]):
resulting = ''
for char in ciphertext:
charIndex = au.get_index_of_letter(char)
clearIndex = key[charIndex]
clearChar = au.get_letter_at_index(clearIndex)
resulting += clearChar
char_index = au.get_index_of_letter(char)
clear_index = key[char_index]
clear_char = au.get_letter_at_index(clear_index)
resulting += clear_char
return resulting
@ -50,20 +50,22 @@ def generate_key():
return indices
def generate_key_with_keyword(keyword: str):
result = []
for char in keyword:
charIndex = au.get_index_of_letter(char)
if charIndex not in result:
result.append(charIndex)
char_index = au.get_index_of_letter(char)
if char_index not in result:
result.append(char_index)
remainingIndices = [i for i in range(26-len(result))]
remaining_indices = [i for i in range(26 - len(result))]
result.extend(remainingIndices)
result.extend(remaining_indices)
return result
if __name__ == '__main__':
key = generate_key_with_keyword('patrick')
print(key)

View File

@ -23,8 +23,8 @@ def encrypt_text(cleartext: str, key1: int, key2: int):
for char in cleartext:
index = au.get_index_of_letter(char)
newIndex = (index * key1 + key2) % 26
resulting += au.get_letter_at_index(newIndex)
new_index = (index * key1 + key2) % 26
resulting += au.get_letter_at_index(new_index)
return resulting
@ -51,8 +51,8 @@ def decrypt_text(ciphertext: str, key1: int, key2: int):
for char in ciphertext:
index = au.get_index_of_letter(char)
newIndex = ((index - key2) * decrypt_key1) % 26
resulting += au.get_letter_at_index(newIndex)
new_index = ((index - key2) * decrypt_key1) % 26
resulting += au.get_letter_at_index(new_index)
return resulting