-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranspositionFileCipher.py
More file actions
executable file
·55 lines (37 loc) · 1.21 KB
/
transpositionFileCipher.py
File metadata and controls
executable file
·55 lines (37 loc) · 1.21 KB
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
#!/usr/bin/python3
from transpositionEncrypt import encrypt, decrypt
import sys, time, os.path as path
def main():
inFile = 'frankenstein.txt'
outFile = 'frankenstein.encrypted.txt'
mode = 'encrypt'
inFile = 'frankenstein.encrypted.txt'
outFile = 'frankenstein.decrypted.txt'
mode = 'decrypt'
key = 10
if not path.exists(inFile):
print('The %s file does not exust.' % inFile)
sys.exit()
if path.exists(outFile):
response = input(
'''This will overwrite the file %s.
(C)ontinue or (Q)uite? ''' % outFile)
if not response.upper().startswith('C'):
sys.exit()
print('%sing...' % mode.title())
startTime = time.time()
fd = open(inFile)
text = fd.read()
fd.close()
if mode == 'encrypt':
translated = encrypt(text, key)
elif mode == 'decrypt':
translated = decrypt(text, key)
print('%sion time: %s seconds' % (mode.title(), round(time.time() - startTime, 2)))
fd = open(outFile, 'w')
fd.write(translated)
fd.close()
print('Done %sing %s (%s characters).' % (mode, inFile, len(translated)))
print('%sed file is %s.' % (mode.title(), outFile))
if __name__ == "__main__":
main()