Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- message = 'hello'
- mode = 'encrypt'
- key = 1
- SYMBOLS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 !?.'
- translated = ''
- for symbol in message:
- if symbol in SYMBOLS:
- symbolIndex = SYMBOLS.find(symbol)
- if mode == 'encrypt':
- tranlatedIndex = symbolIndex + key
- elif mode == 'decrypt':
- tranlatedIndex = symbolIndex - key
- if tranlatedIndex >= len(SYMBOLS):
- tranlatedIndex = tranlatedIndex - len(SYMBOLS)
- elif tranlatedIndex < 0:
- tranlatedIndex = tranlatedIndex + len(SYMBOLS)
- translated = translated + SYMBOLS[tranlatedIndex]
- else:
- translated = translated + symbol
- print(translated)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement