mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Cryptography Algorithm
This commit is contained in:
parent
5b72d5e0a1
commit
8926cc0a30
7193
ciphers/Prehistoric Men.txt
Normal file
7193
ciphers/Prehistoric Men.txt
Normal file
File diff suppressed because it is too large
Load Diff
35
ciphers/transposition_cipher_encrypt-decrypt_file.py
Normal file
35
ciphers/transposition_cipher_encrypt-decrypt_file.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import time, os, sys
|
||||
import transposition_cipher as transCipher
|
||||
|
||||
def main():
|
||||
inputFile = 'Prehistoric Men.txt'
|
||||
outputFile = 'Output.txt'
|
||||
key = int(input('Enter key: '))
|
||||
mode = input('Encrypt/Decrypt [e/d]: ')
|
||||
|
||||
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)
|
||||
response = input('> ')
|
||||
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)
|
||||
print('Done (', totalTime, 'seconds )')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user