Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
- def main():
- myMessage = """When you try your best, but you don't succeed
- When you get what you want, but not what you need
- When you feel so tired, but you can't sleep
- Stuck in reverse
- And the tears come streaming down your face
- When you lose something you can't replace
- When you love someone, but it goes to waste
- Could it be worse?
- Lights will guide you home
- And ignite your bones
- I will try to fix you
- High up above or down below
- When you're too in love to let it go
- But if you never try you'll never know
- Just what you're worth
- Lights will guide you home
- And ignite your bones
- I will try to fix you
- Tears stream down your face
- When you lose something you cannot replace
- Tears stream down your face and I
- Tears stream down your face
- I promise you I will learn from my mistakes
- Tears stream down your face and I
- Lights will guide you home
- And ignite your bones
- And I will try to fix you"""
- myKey = 'ASIMOV'
- myMode = 'encrypt'
- def encryptMessage(key, message):
- return translateMessage(key, message, 'encrypt')
- def decryptMessage(key, message):
- return translateMessage(key, message, 'decrypt')
- def translateMessage(key, message, mode):
- translated = []
- if myMode == 'encrypt':
- translated = encryptMessage(myKey, myMessage)
- elif myMode == 'decrypt':
- translated = decryptMessage(myKey, myMessage)
- print('%sed message:' % (myMode.title()))
- print(translated)
- keyIndex = 0
- key = key.upper()
- for symbol in message:
- num = LETTERS.find(symbol.upper())
- if num != -1:
- if mode == 'encrypt':
- num += LETTERS.find(key[keyIndex])
- elif mode == 'decrypt':
- num -= LETTERS.find(key[keyIndex])
- num %= len(LETTERS)
- if symbol.isupper():
- translated.append(LETTERS[num])
- elif symbol.islower():
- translated.append(LETTERS[num].lower())
- keyIndex += 1
- if keyIndex == len(key):
- keyIndex = 0
- else:
- translated.append(symbol)
- return ''.join(translated)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement