Created
October 5, 2017 14:01
-
-
Save Gui13/5e5fe0c7c67d55373767d4965b163822 to your computer and use it in GitHub Desktop.
PaperKey with Bash
This file contains 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 | |
# Hello HN! | |
# to read back the chunks, use zbarcam. | |
if [ "$#" -ne "1" ]; then | |
echo "Please specify the private key file (should be in PEM format)" | |
exit 1 | |
fi | |
private_key=$1 | |
rm private_key_*.txt | |
rm private_key_split_*.txt.png | |
rm page_*.ps | |
# split key in 260 byte chunks, above that zbarcam has difficulty reading the Qr codes | |
split -a 2 --additional-suffix=.txt -b 256 -d "$private_key" private_key_split_ | |
# encode in qr code | |
for i in private_key_split_*.txt | |
do | |
echo "Encoding $1 in $i.png" | |
qrencode -l H -o "$i.png" < "$i" | |
done | |
# Do a 4x4 montage of pages | |
echo "Printing all images in ps files." | |
montage -label '%f' -tile 2x2 -geometry "100%x100%" ./*.png page_%d.ps | |
# shasum the key into a txt file | |
shasum=$(sha256sum "$private_key") | |
echo "sha256sum of $private_key is $shasum" > private_key_sha256.txt | |
# montage to print the actual base64 key with the SHA256 sum for last-resort | |
a2ps -4 -A fill private_key_split_*.txt private_key_sha256.txt -o page_clear.ps | |
nb_pages=$(find . -name "page_*.ps" | wc -l) | |
read -r -p "Do you want to print all $((nb_pages * 2 + 1)) pages [yN]" yesno | |
# prints all pages if user answers yes | |
if [ "$yesno" = "y" ]; then | |
for i in *.ps | |
do | |
lp "$i" | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment