2017-11-25 09:23:50 +00:00
|
|
|
from __future__ import print_function
|
2016-08-02 08:11:36 +00:00
|
|
|
import time, os, sys
|
|
|
|
import transposition_cipher as transCipher
|
|
|
|
|
|
|
|
def main():
|
|
|
|
inputFile = 'Prehistoric Men.txt'
|
|
|
|
outputFile = 'Output.txt'
|
2018-10-19 08:30:31 +00:00
|
|
|
key = int(raw_input('Enter key: '))
|
|
|
|
mode = raw_input('Encrypt/Decrypt [e/d]: ')
|
2016-08-02 08:11:36 +00:00
|
|
|
|
|
|
|
if not os.path.exists(inputFile):
|
|
|
|
print('File %s does not exist. Quitting...' % inputFile)
|
|
|
|
sys.exit()
|
|
|
|
if os.path.exists(outputFile):
|
|
|
|
print('Overwrite %s? [y/n]' % outputFile)
|
2018-10-19 08:30:31 +00:00
|
|
|
response = raw_input('> ')
|
2016-08-02 08:11:36 +00:00
|
|
|
if not response.lower().startswith('y'):
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
startTime = time.time()
|
|
|
|
if mode.lower().startswith('e'):
|
|
|
|
content = open(inputFile).read()
|
|
|
|
translated = transCipher.encryptMessage(key, content)
|
|
|
|
elif mode.lower().startswith('d'):
|
|
|
|
content = open(outputFile).read()
|
|
|
|
translated =transCipher .decryptMessage(key, content)
|
|
|
|
|
|
|
|
outputObj = open(outputFile, 'w')
|
|
|
|
outputObj.write(translated)
|
|
|
|
outputObj.close()
|
|
|
|
|
|
|
|
totalTime = round(time.time() - startTime, 2)
|
2017-11-25 09:23:50 +00:00
|
|
|
print(('Done (', totalTime, 'seconds )'))
|
2016-08-02 08:11:36 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|