(messageFilename, keyFilename)
| 103 | |
| 104 | |
| 105 | def readFromFileAndDecrypt(messageFilename, keyFilename): |
| 106 | keySize, n, d = readKeyFile(keyFilename) |
| 107 | with open(messageFilename) as fo: |
| 108 | content = fo.read() |
| 109 | messageLength, blockSize, encryptedMessage = content.split('_') |
| 110 | messageLength = int(messageLength) |
| 111 | blockSize = int(blockSize) |
| 112 | |
| 113 | if keySize < blockSize * 8: |
| 114 | sys.exit('ERROR: Block size is %s bits and key size is %s bits. The RSA cipher requires the block size to be equal to or greater than the key size. Did you specify the correct key file and encrypted file?' % (blockSize * 8, keySize)) |
| 115 | |
| 116 | encryptedBlocks = [] |
| 117 | for block in encryptedMessage.split(','): |
| 118 | encryptedBlocks.append(int(block)) |
| 119 | |
| 120 | return decryptMessage(encryptedBlocks, messageLength, (n, d), blockSize) |
| 121 | |
| 122 | if __name__ == '__main__': |
| 123 | main() |
no test coverage detected