#7: Implementing Schlüsselwort-Chiffre
This commit is contained in:
parent
8373534224
commit
80ebb362a5
|
@ -39,16 +39,33 @@ def decrypt_text(ciphertext: str, key: [int]):
|
|||
return resulting
|
||||
|
||||
|
||||
def _generate_key():
|
||||
def generate_key():
|
||||
"""
|
||||
Generates a key that can be used for this cipher.
|
||||
:return: The key as a list of indices
|
||||
"""
|
||||
indices = [i for i in range(26)]
|
||||
|
||||
random.shuffle(indices)
|
||||
|
||||
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)
|
||||
|
||||
remainingIndices = [i for i in range(26-len(result))]
|
||||
|
||||
result.extend(remainingIndices)
|
||||
|
||||
return result
|
||||
|
||||
if __name__ == '__main__':
|
||||
key = _generate_key()
|
||||
key = generate_key_with_keyword('patrick')
|
||||
print(key)
|
||||
encrypted = encrypt_text('BonkRocks', key)
|
||||
print(encrypted)
|
||||
|
|
Loading…
Reference in New Issue
Block a user