SHARE
TWEET

Untitled

a guest Sep 11th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Caesar Cipher
  2. # from class on 09/11
  3.  
  4. import pyperclip.py
  5.  
  6. # store string to be encrypted/decrypted
  7. message = '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'
  8.  
  9. # encryption/decryption Key
  10. key = 18
  11.  
  12. # set program mode
  13. mode = 'decrypt' # set mode to encrypt or decrypt
  14.  
  15. # store all possible symbols
  16. SYMBOLS = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%/.'
  17.  
  18. # store encrypted/decyprted message
  19. translated = ''
  20.  
  21. for symbol in message:
  22.     # note: only symbols in the SYMBOLS string can be encrypted/decrypted
  23.     if symbol in SYMBOLS:
  24.         symbolIndex = SYMBOLS.find(symbol)
  25.  
  26.         # perform encryption or decryption
  27.         if mode == 'encrypt':
  28.             translatedIndex = symbolIndex + key
  29.         elif mode == 'decrypt':
  30.             translatedIndex = symbolIndex - key
  31.        
  32.         # handle wraparound, if needed:
  33.         if translatedIndex >= len(SYMBOLS):
  34.             translatedIndex = translatedIndex = len(SYMBOLS)
  35.         elif translatedIndex < 0:
  36.             translatedIndex = translatedIndex + len(SYMBOLS)
  37.  
  38.         translated = translated + SYMBOLS[translatedIndex]
  39.     else:
  40.         # append the symbol wihout encrypting/decrypting:
  41.         translated = translated + symbol
  42.    
  43. # output the translated string:
  44. print(translated)
  45. pyperclip.copy(translated)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top