Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import string
- ALPHABET = string.ascii_uppercase
- def convert_to_alphabet_indices(word):
- alphabet_indices = list()
- for character in list(word):
- character_index = ALPHABET.index(character)
- alphabet_indices.append(character_index)
- return alphabet_indices
- def convert_to_alphabet_letters(indices):
- alphabet_letters = list()
- for index in indices:
- alphabet_letters.append(ALPHABET[index])
- return ''.join(alphabet_letters)
- def sum_list_values(first_list, second_list):
- result = list()
- for x, y in zip(first_list, second_list):
- total = x + y
- alphabet_length = len(ALPHABET)
- if total >= alphabet_length:
- total %= alphabet_length
- result.append(total)
- return result
- def subtract_list_values(first_list, second_list):
- return [x - y for x, y in zip(first_list, second_list)]
- plaintext = "GEHEIMTEXT"
- one_time_pad_text = "PADUGSNQHG"
- plaintext_indices = convert_to_alphabet_indices(plaintext)
- print("Klartext-Indizes:", plaintext_indices)
- one_time_pad_text_indices = convert_to_alphabet_indices(one_time_pad_text)
- print("OTP-Indizes:", one_time_pad_text_indices)
- cyphertext_indices = sum_list_values(plaintext_indices, one_time_pad_text_indices)
- print("Geheimtext-Indizes:", cyphertext_indices)
- cyphertext = convert_to_alphabet_letters(cyphertext_indices)
- print("Geheimtext:", cyphertext)
- difference_cyphertext_indices_and_otp_indices = subtract_list_values(cyphertext_indices, one_time_pad_text_indices)
- print("Differenz zwischen Geheimtext-Indizes und OTP-Indizes:", difference_cyphertext_indices_and_otp_indices)
- encrypted_text = convert_to_alphabet_letters(difference_cyphertext_indices_and_otp_indices)
- print("EntschlĂĽsselter Text:", encrypted_text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement