Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ALPHABET = 'adbcefghijklmnopqrstuvwxyz0123456789!@#$%/.'
- def caesar(message, key, mode):
- ciphertext = ''
- for character in message:
- index = ALPHABET.find(character)
- if index == -1:
- ciphertext += character
- continue
- if mode == 'encrypt':
- cipherIndex = (index + key) % len(ALPHABET)
- elif mode == 'decrypt':
- cipherIndex = (index - key) % len(ALPHABET)
- elif mode == 'alternate':
- mod = index % 2
- cipherIndex = (index - key[mod]) % len(ALPHABET)
- ciphertext += ALPHABET[cipherIndex]
- return ciphertext
- #ciphertext = caesar('a plaintext message!', 30, 'encrypt')
- #print(ciphertext)
- # plaintext = caesar('Usw!s9 u07zw9 0! s @.7w 6x s !#t!@0@#@065 u07zw9 69 4656s37zstw@0u u07zw9 %zw9w w$w9. 3w@@w9 05 @zw 4w!!syw 0! 9w73suwv t. !64w 6@zw9 3w@@w9 x0/wv 5#4tw9 6x 76!0@065! v6%5 @zw s37zstw@r @zw 5#4tw9 6x !z0x@ 76!0@065! 0! @zw 2w.r', 18, 'decrypt')
- plaintext = caesar('Usw!s9 u07zw9 0! s @.7w 6x s !#t!@0@#@065 u07zw9 69 4656s37zstw@0u u07zw9 %zw9w w$w9. 3w@@w9 05 @zw 4w!!syw 0! 9w73suwv t. !64w 6@zw9 3w@@w9 x0/wv 5#4tw9 6x 76!0@065! v6%5 @zw s37zstw@r @zw 5#4tw9 6x !z0x@ 76!0@065! 0! @zw 2w.r', [2, 3], 'alternate')
- print(plaintext)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement