MCPcopy Index your code
hub / github.com/subbarayudu-j/TheAlgorithms-Python / readFromFileAndDecrypt

Function readFromFileAndDecrypt

ciphers/rsa_cipher.py:105–120  ·  view source on GitHub ↗
(messageFilename, keyFilename)

Source from the content-addressed store, hash-verified

103
104
105def 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
122if __name__ == '__main__':
123 main()

Callers 1

mainFunction · 0.85

Calls 3

readKeyFileFunction · 0.85
splitMethod · 0.80
decryptMessageFunction · 0.70

Tested by

no test coverage detected