-
Notifications
You must be signed in to change notification settings - Fork 1
/
decipher.py
55 lines (46 loc) · 1.6 KB
/
decipher.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
53
54
55
# Author: James Campbell
# What: Deciphers text using pigpen plaintext standard cipher
# Requirements: Python 3.x and above
import json
import sys
def get_file(filename):
with open(filename) as f:
jsondict = json.loads(f.read())
return jsondict
# //// tests
# print(jsondict['a'])
pypigpen = """
,.
(_|,.
,' /, )_______ _
__j o``-' `.'-)'
(") \\'
`-j |
`-._( /
|_\ |--^. /
/_]'|_| /_)_/
/_]' /_]'
"""
print(pypigpen)
print('Welcome. \nThis will print plaintext to a text file called decipher.txt. \nUse cipher.py to encipher.\n')
if len(sys.argv) < 2:
print('usage: python3 decipher.py [full path and name of text file to decipher]\n')
exit()
jsondict = get_file('jsondata.json')
with open(sys.argv[1],'w') as d:
with open(sys.argv[1],"r") as f:
listofcipherletters = f.read().split()
# tests
# print(listofcipherletters)
#exit('working so far')
for letter in listofcipherletters:
# print("\n{}".format(letter))
if letter == '\n':
print('\n')
d.write('\n')
continue
name = [alphabet for alphabet, cipher in jsondict.items() if cipher == letter]
print(''.join(name),end="")
writeable = str(''.join(name))
d.write(writeable)
exit('\nthanks for playing\nsaved as decipher.txt')