Skip to content

Instantly share code, notes, and snippets.

@sowbug
Created October 12, 2015 04:12
Show Gist options
  • Save sowbug/7ede7a62a972e1174f2e to your computer and use it in GitHub Desktop.
Save sowbug/7ede7a62a972e1174f2e 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.
#!/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