Last active
February 26, 2022 23:57
-
-
Save m-ocean-it/9f73f4a508812dfd1496395bc7d78fb3 to your computer and use it in GitHub Desktop.
Split a secret using Shamir Secret Sharing Scheme and then put each share in its own file with a specified note
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
''' | |
Split a secret using Shamir Secret Sharing Scheme and then put each | |
share in its own file with a specified note. | |
Uses: ssss v0.5 | |
''' | |
import subprocess | |
import os | |
N = int(input('Total number of shares: ')) | |
T = int(input('Threshold (sufficient number of shares to recover the secret): ')) | |
OUTPUT_DIR = input('Directory path for the shares: ') | |
TAG = input('Add a tag (or leave blank): ') | |
if TAG: | |
TAG_ARG = f'-w {TAG}' | |
else: | |
TAG_ARG = '' | |
NOTE = f'''!!! DO NOT DELETE !!! | |
This is one of the shares of my secret that I split using Shamir Secret Sharing Scheme. | |
Total shares: {N}. | |
Threshold {T} | |
Tag: {TAG} | |
''' | |
output = subprocess.check_output( | |
f'ssss-split -t {T} -n {N} {TAG_ARG}', | |
shell=True).decode() | |
lines = output.split('\n') | |
shares = lines[1:-1] | |
assert len(shares) == N | |
for i, share in enumerate(shares): | |
share_with_note = NOTE + '\n' + share + '\n' | |
print(share_with_note) | |
file_path = os.path.join(OUTPUT_DIR, f'{i+1}_share.txt') | |
with open(file_path, 'w') as f: | |
f.write(share_with_note) |
Author
m-ocean-it
commented
Feb 26, 2022
- Add code for combining files and recovering the secret.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment