()
| 5 | BYTE_SIZE = 256 |
| 6 | |
| 7 | def main(): |
| 8 | filename = 'encrypted_file.txt' |
| 9 | response = input(r'Encrypte\Decrypt [e\d]: ') |
| 10 | |
| 11 | if response.lower().startswith('e'): |
| 12 | mode = 'encrypt' |
| 13 | elif response.lower().startswith('d'): |
| 14 | mode = 'decrypt' |
| 15 | |
| 16 | if mode == 'encrypt': |
| 17 | if not os.path.exists('rsa_pubkey.txt'): |
| 18 | rkg.makeKeyFiles('rsa', 1024) |
| 19 | |
| 20 | message = input('\nEnter message: ') |
| 21 | pubKeyFilename = 'rsa_pubkey.txt' |
| 22 | print('Encrypting and writing to %s...' % (filename)) |
| 23 | encryptedText = encryptAndWriteToFile(filename, pubKeyFilename, message) |
| 24 | |
| 25 | print('\nEncrypted text:') |
| 26 | print(encryptedText) |
| 27 | |
| 28 | elif mode == 'decrypt': |
| 29 | privKeyFilename = 'rsa_privkey.txt' |
| 30 | print('Reading from %s and decrypting...' % (filename)) |
| 31 | decryptedText = readFromFileAndDecrypt(filename, privKeyFilename) |
| 32 | print('writing decryption to rsa_decryption.txt...') |
| 33 | with open('rsa_decryption.txt', 'w') as dec: |
| 34 | dec.write(decryptedText) |
| 35 | |
| 36 | print('\nDecryption:') |
| 37 | print(decryptedText) |
| 38 | |
| 39 | |
| 40 | def getBlocksFromText(message, blockSize=DEFAULT_BLOCK_SIZE): |
no test coverage detected