-
-
Save LudLaf/d1957b7c53d751c6eb5182c465a3c0cd to your computer and use it in GitHub Desktop.
Use Shamir's Secret Sharing Scheme to split a strong passphrase into five QR codes, any three of which will reconstruct the passphrase.
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/bash | |
| # | |
| # Use Shamir's Secret Sharing Scheme to split a strong passphrase into | |
| # five QR codes, any three of which will reconstruct the passphrase. | |
| # | |
| # Requires packages qrencode, ssss, and optionally zbarimg. | |
| PASSPHRASE_LENGTH=32 | |
| SHARES=5 # max 9 (fix single-digits below if you need more) | |
| MIN_TO_COMBINE=3 | |
| rm -f share-*-of-${SHARES}.png | |
| # Generate a passphrase. | |
| PASSPHRASE=`LC_CTYPE=C </dev/urandom tr -dc "[:alnum:]" | \ | |
| head -c${PASSPHRASE_LENGTH}` | |
| echo "Generated $PASSPHRASE" | |
| # Split the passphrase into shares, each of which is a text line. | |
| LINES=( $( echo $PASSPHRASE | ssss-split -t${MIN_TO_COMBINE} -n${SHARES} -Q ) ) | |
| # Make QR codes out of each text line. | |
| for line in "${LINES[@]}"; do | |
| qrencode -lQ -o share-${line:0:1}-of-${SHARES}.png $line; | |
| done | |
| # Now combine to verify that we get out what we put in. | |
| zbarimg --raw share-*-of-${SHARES}.png | ssss-combine -t${MIN_TO_COMBINE} -q |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment