-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecipher.py
53 lines (38 loc) · 1.26 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
#!/usr/bin/python
import sys, getopt
basicTuple = ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z')
def main(argv):
inputfile = ''
outputfile = ''
try:
opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
except getopt.GetoptError:
print ('test.py -i <inputfile> -o <outputfile>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print ('test.py -i <inputfile> -o <outputfile>')
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
elif opt in ("-o", "--ofile"):
outputfile = arg
f2 = open(outputfile, "w")
with open(inputfile) as f:
while True:
c = f.read(1)
if not c:
break
if c.isalpha():
c = c.upper()
temp = 0
if basicTuple.index(c) + 3 >= 26:
temp = basicTuple.index(c) + 3 - 26
else:
temp = basicTuple.index(c) + 3
f2.write(basicTuple[temp])
else:
f2.write(c)
f2.close()
if __name__ == "__main__":
main(sys.argv[1:])