Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pyperclip
- alphabet = 'abcdefghijklmnopqrstuvwxyz'
- def main():
- Message = """"though the cold war has passed, decoded soviet cables have intensified the long running debate on
- whether the soviet union employed american citizens as spies"""
- Key = 'venom'
- Mode = 'encrypt'
- if Mode == 'encrypt':
- translated = encryptMessage(Key, Message)
- elif Mode == 'decrypt':
- translated = decryptMessage(Key, Message)
- print('%sed message:' % (Mode.title()))
- print(translated)
- pyperclip.copy(translated)
- print()
- print('The message has been copied.')
- def encryptMessage(key, message):
- return translateMessage(key, message, 'encrypt')
- def decryptMessage(key, message):
- return translateMessage(key, message, 'decrypt')
- def translateMessage(key, message, mode):
- translated = []
- keyIndex = 0
- key = key.upper()
- for symbol in message:
- num = alphabet.find(symbol.upper())
- if num != -1:
- if mode == 'encrypt':
- num += alphabet.find(key[keyIndex])
- elif mode == 'decrypt':
- num -= alphabet.find(key[keyIndex])
- num %= len(alphabet)
- if symbol.isupper():
- translated.append(alphabet[num])
- elif symbol.islower():
- translated.append(alphabet[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