Advertisement
otorp2

code 1

Dec 27th, 2019
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. message = 'hello'
  2. mode = 'encrypt'
  3.  
  4. key = 1
  5.  
  6. SYMBOLS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 !?.'
  7.  
  8.  
  9.  
  10. translated = ''
  11.  
  12. for symbol in message:
  13.     if symbol in SYMBOLS:
  14.         symbolIndex = SYMBOLS.find(symbol)
  15.        
  16.         if mode == 'encrypt':
  17.             tranlatedIndex = symbolIndex + key
  18.         elif mode == 'decrypt':
  19.             tranlatedIndex = symbolIndex - key
  20.         if tranlatedIndex >= len(SYMBOLS):
  21.             tranlatedIndex = tranlatedIndex - len(SYMBOLS)
  22.         elif tranlatedIndex < 0:
  23.             tranlatedIndex = tranlatedIndex + len(SYMBOLS)
  24.         translated = translated + SYMBOLS[tranlatedIndex]
  25.     else:
  26.         translated = translated + symbol
  27. print(translated)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement