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

Function makeKeyFiles

ciphers/rsa_key_generator.py:30–43  ·  view source on GitHub ↗
(name, keySize)

Source from the content-addressed store, hash-verified

28 return (publicKey, privateKey)
29
30def makeKeyFiles(name, keySize):
31 if os.path.exists('%s_pubkey.txt' % (name)) or os.path.exists('%s_privkey.txt' % (name)):
32 print('\nWARNING:')
33 print('"%s_pubkey.txt" or "%s_privkey.txt" already exists. \nUse a different name or delete these files and re-run this program.' % (name, name))
34 sys.exit()
35
36 publicKey, privateKey = generateKey(keySize)
37 print('\nWriting public key to file %s_pubkey.txt...' % name)
38 with open('%s_pubkey.txt' % name, 'w') as fo:
39 fo.write('%s,%s,%s' % (keySize, publicKey[0], publicKey[1]))
40
41 print('Writing private key to file %s_privkey.txt...' % name)
42 with open('%s_privkey.txt' % name, 'w') as fo:
43 fo.write('%s,%s,%s' % (keySize, privateKey[0], privateKey[1]))
44
45if __name__ == '__main__':
46 main()

Callers 1

mainFunction · 0.70

Calls 1

generateKeyFunction · 0.70

Tested by

no test coverage detected