MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / make_key_files

Function make_key_files

ciphers/rsa_key_generator.py:43–59  ·  view source on GitHub ↗
(name: str, key_size: int)

Source from the content-addressed store, hash-verified

41
42
43def make_key_files(name: str, key_size: int) -> None:
44 if os.path.exists(f"{name}_pubkey.txt") or os.path.exists(f"{name}_privkey.txt"):
45 print("\nWARNING:")
46 print(
47 f'"{name}_pubkey.txt" or "{name}_privkey.txt" already exists. \n'
48 "Use a different name or delete these files and re-run this program."
49 )
50 sys.exit()
51
52 public_key, private_key = generate_key(key_size)
53 print(f"\nWriting public key to file {name}_pubkey.txt...")
54 with open(f"{name}_pubkey.txt", "w") as out_file:
55 out_file.write(f"{key_size},{public_key[0]},{public_key[1]}")
56
57 print(f"Writing private key to file {name}_privkey.txt...")
58 with open(f"{name}_privkey.txt", "w") as out_file:
59 out_file.write(f"{key_size},{private_key[0]},{private_key[1]}")
60
61
62if __name__ == "__main__":

Callers 1

mainFunction · 0.70

Calls 2

generate_keyFunction · 0.70
existsMethod · 0.45

Tested by

no test coverage detected