This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
myMessage = input('Text to cipher: ').upper() | |
myKey = int(input('rail fence key: ')) | |
ciphertext = transpoMessage(myKey, myMessage) | |
print(ciphertext) | |
def transpoMessage(key, plaintext): | |
ciphertext = [''] * key | |
for col in range(key): | |
pointer = col |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 0 1 1 0 0 1 0 1 1 0 1 1 1 <- Plain Text | |
1 1 0 1 0 0 0 1 1 0 1 0 0 1 <- Key | |
--------------------------- XOR enkripsi | |
0 1 1 0 0 0 1 1 0 1 1 1 1 0 <- cipher Text | |
1 1 0 1 0 0 0 1 1 0 1 0 0 1 <- Key | |
--------------------------- XOR dekripsi | |
1 0 1 1 0 0 1 0 1 1 0 1 1 1 <- Plain Text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from string import ascii_letters | |
cipher_letters = 'defghijklmnopqrstuvwxyzabcDEFGHIJKLMNOPQRSTUVWXYZABC' | |
trans = str.maketrans(ascii_letters, cipher_letters) | |
trans_rev = str.maketrans(cipher_letters, ascii_letters) | |
text_to_cipher = input('Text to cipher: ') | |
ciphered = text_to_cipher.translate(trans) |