MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / main

Function main

ciphers/rsa_cipher.py:7–37  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5BYTE_SIZE = 256
6
7def 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
40def getBlocksFromText(message, blockSize=DEFAULT_BLOCK_SIZE):

Callers 1

rsa_cipher.pyFile · 0.70

Calls 2

encryptAndWriteToFileFunction · 0.85
readFromFileAndDecryptFunction · 0.85

Tested by

no test coverage detected