Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 52 lines (37 sloc) 1.328 kb
f16b361b »
2012-08-19 Initial commit.
1 # Simple Substitution Keyword Cipher
2 # http://inventwithpython.com/codebreaker (BSD Licensed)
3
4 import pyperclip, simpleSubCipher
5
6 def main():
d95e7daa »
2012-08-27 Changes made while making unit tests.
7 myMessage = r"""Your cover is blown."""
f16b361b »
2012-08-19 Initial commit.
8 myKey = 'alphanumeric'
9 myMode = 'encrypt' # set to 'encrypt' or 'decrypt'
10
11
12 print('The key used is:')
13 print(makeSimpleSubKey(myKey))
14
15 if myMode == 'encrypt':
16 translated = encryptMessage(myKey, myMessage)
17 elif myMode == 'decrypt':
18 translated = decryptMessage(myKey, myMessage)
19
20 print('The %sed message is:' % (myMode))
21 print(translated)
22
23 pyperclip.copy(translated)
24 print()
25 print('This message has been copied to the clipboard.')
26
27
28 def encryptMessage(key, message):
29 key = makeSimpleSubKey(key)
30 return simpleSubCipher.encryptMessage(key, message)
31
32
33 def decryptMessage(key, message):
34 key = makeSimpleSubKey(key)
35 return simpleSubCipher.decryptMessage(key, message)
36
37
38 def makeSimpleSubKey(keyword):
39 # create the key from the keyword
40 newKey = ''
d95e7daa »
2012-08-27 Changes made while making unit tests.
41 keyword = keyword.upper()
42 keyAlphabet = list(simpleSubCipher.LETTERS)
f16b361b »
2012-08-19 Initial commit.
43 for i in range(len(keyword)):
44 if keyword[i] not in newKey:
45 newKey += keyword[i]
46 keyAlphabet.remove(keyword[i])
47 key = newKey + ''.join(keyAlphabet)
48 return key
49
50
51 if __name__ == '__main__':
52 main()
Something went wrong with that request. Please try again.