Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # Filename: kryptos_c1_c2_decoder.py
- # Author: Jeoi Reqi
- # Decoder for The Kryptos Ciphers C1 & C2
- # 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.
- """
- plaintext = ''
- key_index = 0
- key_length = len(key)
- ciphertext_length = len(ciphertext)
- for i in range(ciphertext_length):
- if ciphertext[i] not in alphabet:
- plaintext += ciphertext[i]
- continue
- # Calculate the shift
- shift = alphabet.index(key[key_index])
- key_index = (key_index + 1) % key_length
- # Decrypt the character
- ciphertext_char = ciphertext[i]
- ciphertext_pos = alphabet.find(ciphertext_char)
- plaintext_pos = (ciphertext_pos - shift) % len(alphabet)
- plaintext += alphabet[plaintext_pos]
- return plaintext
- # Test the combined function with the given ciphertexts and keys
- ciphertext1 = "EMUFPHZLRFAXYUSDJKZLDKRNSHGNFIVJYQTQUXQBQVYUVLLTREVJYQTMKYRDMFD"
- key1 = "PALIMPSEST"
- alphabet1 = "KRYPTOSABCDEFGHIJLMNQUVWXZ"
- plaintext1 = vigenere_decoder(ciphertext1, key1, alphabet1)
- print("Cipher 1:")
- print(plaintext1)
- print("\n\n")
- ciphertext2 = "VFPJUDEEHZWETZYVGWHKKQETGFQJNCEGGWHKKDQMCPFQZDQMMIAGPFXHQRLGTIMVMZJANQLVKQEDAGDVFRPJUNGEUNAQZGZLECGYUXUEENJTBJLBQCRTBJDFHRRYIZETKZEMVDUFKSJHKFWHKUWQLSZFTIHHDDDUVH?DWKBFUFPWNTDFIYCUQZEREEVLDKFEZMOQQJLTTUGSYQPFEUNLAVIDXFLGGTEZ?FKZBSFDQVGOGIPUFXHHDRKFFHQNTGPUAECNUVPDJMQCLQUMUNEDFQELZZVRRGKFFVOEEXBDMVPNFQXEZLGREDNQFMPNZGLFLPMRJQYALMGNUVPDXVKPDQUMEBEDMHDAFMJGZNUPLGEWJLLAETG"
- key2 = "ABSCISSA"
- alphabet2 = "KRYPTOSABCDEFGHIJLMNQUVWXZ"
- plaintext2 = vigenere_decoder(ciphertext2, key2, alphabet2)
- print("Cipher 2:")
- # Print the decrypted plaintext
- print(plaintext2)
- print("\n\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement