-
Notifications
You must be signed in to change notification settings - Fork 148
/
simpleSubKeyword.py
52 lines (37 loc) · 1.29 KB
/
simpleSubKeyword.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Simple Substitution Keyword Cipher
# http://inventwithpython.com/hacking (BSD Licensed)
import pyperclip, simpleSubCipher
def main():
myMessage = r"""Your cover is blown."""
myKey = 'alphanumeric'
myMode = 'encrypt' # set to 'encrypt' or 'decrypt'
print('The key used is:')
print(makeSimpleSubKey(myKey))
if myMode == 'encrypt':
translated = encryptMessage(myKey, myMessage)
elif myMode == 'decrypt':
translated = decryptMessage(myKey, myMessage)
print('The %sed message is:' % (myMode))
print(translated)
pyperclip.copy(translated)
print()
print('This message has been copied to the clipboard.')
def encryptMessage(key, message):
key = makeSimpleSubKey(key)
return simpleSubCipher.encryptMessage(key, message)
def decryptMessage(key, message):
key = makeSimpleSubKey(key)
return simpleSubCipher.decryptMessage(key, message)
def makeSimpleSubKey(keyword):
# create the key from the keyword
newKey = ''
keyword = keyword.upper()
keyAlphabet = list(simpleSubCipher.LETTERS)
for i in range(len(keyword)):
if keyword[i] not in newKey:
newKey += keyword[i]
keyAlphabet.remove(keyword[i])
key = newKey + ''.join(keyAlphabet)
return key
if __name__ == '__main__':
main()