Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # Filename: kryptos_c1_decoder.py
- # Author: Jeoi Reqi
- # Decoder for The Kryptos Ciphers C1
- # Define the alphabet and key
- ALPHABET = "KRYPTOSABCDEFGHIJLMNQUVWXZ"
- KEY = "PALIMPSEST"
- # Function for the vigenere cryptography
- def vigenere_decoder(ciphertext, key, alphabet):
- """
- Decrypt a Vigenere cipher using the specified key and alphabet.
- Parameters:
- ciphertext (str): The text to decrypt.
- key (str): The key to use for decryption.
- alphabet (str): The alphabet to use for decryption.
- Returns:
- str: The decrypted plaintext.
- """
- # Convert the key and ciphertext to uppercase
- key = key.upper()
- ciphertext = ciphertext.upper()
- # Calculate the length of the key and ciphertext
- key_length = len(key)
- ciphertext_length = len(ciphertext)
- # Generate the repeated key
- repeated_key = ""
- for i in range(ciphertext_length):
- repeated_key += key[i % key_length]
- # Decrypt the ciphertext using the repeated key
- plaintext = ""
- for i in range(ciphertext_length):
- ciphertext_char = ciphertext[i]
- key_char = repeated_key[i]
- # Find the position of the key and ciphertext characters in the alphabet
- key_pos = alphabet.find(key_char)
- ciphertext_pos = alphabet.find(ciphertext_char)
- # Subtract the key position from the ciphertext position to get the plaintext position
- plaintext_pos = (ciphertext_pos - key_pos) % len(alphabet)
- # Get the plaintext character from the alphabet
- plaintext_char = alphabet[plaintext_pos]
- plaintext += plaintext_char
- return plaintext
- # Decrypt the ciphertext using the given key and alphabet
- ciphertext = "EMUFPHZLRFAXYUSDJKZLDKRNSHGNFIVJYQTQUXQBQVYUVLLTREVJYQTMKYRDMFD"
- key = "PALIMPSEST"
- alphabet = "KRYPTOSABCDEFGHIJLMNQUVWXZ"
- plaintext = vigenere_decoder(ciphertext, key, alphabet)
- # Print the decrypted plaintext
- print(plaintext)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement