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

Function makeKeyFiles

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

Source from the content-addressed store, hash-verified

41
42
43def makeKeyFiles(name, keySize):
44 if os.path.exists('%s_pubkey.txt' % name) or os.path.exists('%s_privkey.txt' % name):
45 print('\nWARNING:')
46 print('"%s_pubkey.txt" or "%s_privkey.txt" already exists. \n'
47 'Use a different name or delete these files and re-run this program.' %
48 (name, name))
49 sys.exit()
50
51 publicKey, privateKey = generateKey(keySize)
52 print('\nWriting public key to file %s_pubkey.txt...' % name)
53 with open('%s_pubkey.txt' % name, 'w') as fo:
54 fo.write('%d,%d,%d,%d' % (publicKey[0], publicKey[1], publicKey[2], publicKey[3]))
55
56 print('Writing private key to file %s_privkey.txt...' % name)
57 with open('%s_privkey.txt' % name, 'w') as fo:
58 fo.write('%d,%d' % (privateKey[0], privateKey[1]))
59
60
61if __name__ == '__main__':

Callers 1

mainFunction · 0.70

Calls 1

generateKeyFunction · 0.70

Tested by

no test coverage detected