Reformatting code
This commit is contained in:
parent
80ebb362a5
commit
f13b667e6c
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user