chatgpt/shared-secret/chatgpt-example.py

31 lines
772 B
Python
Executable File

#!/usr/bin/python3
from secretsharing import PlaintextToHexSecretSharer
# The secret that we want to split
secret = "my_secret_password"
# The number of shares that we want to generate
n_shares = 5
# The threshold (i.e., the minimum number of shares required to reconstruct the secret)
threshold = 3
# Generate the shares
shares = PlaintextToHexSecretSharer.split_secret(secret, n_shares, threshold)
# Print the shares
for share in shares:
print(share)
# To reconstruct the secret, we need at least the threshold number of shares
# Let's say we have these three shares:
shares_to_reconstruct = [shares[0], shares[2], shares[4]]
# Reconstruct the secret
secret = PlaintextToHexSecretSharer.recover_secret(shares_to_reconstruct)
# Print the secret
print(secret)