Advertisement
krames12

cipherdipher

Oct 20th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. ALPHABET = 'adbcefghijklmnopqrstuvwxyz0123456789!@#$%/.'
  2.  
  3.  
  4. def caesar(message, key, mode):
  5. ciphertext = ''
  6. for character in message:
  7.  
  8. index = ALPHABET.find(character)
  9.  
  10. if index == -1:
  11. ciphertext += character
  12. continue
  13.  
  14. if mode == 'encrypt':
  15. cipherIndex = (index + key) % len(ALPHABET)
  16. elif mode == 'decrypt':
  17. cipherIndex = (index - key) % len(ALPHABET)
  18. elif mode == 'alternate':
  19. mod = index % 2
  20. cipherIndex = (index - key[mod]) % len(ALPHABET)
  21.  
  22. ciphertext += ALPHABET[cipherIndex]
  23.  
  24. return ciphertext
  25.  
  26. #ciphertext = caesar('a plaintext message!', 30, 'encrypt')
  27. #print(ciphertext)
  28. # 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')
  29. 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')
  30. print(plaintext)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement