Skip to content

Instantly share code, notes, and snippets.

@Gui13
Created October 5, 2017 14:01
Show Gist options
  • Save Gui13/5e5fe0c7c67d55373767d4965b163822 to your computer and use it in GitHub Desktop.
Save Gui13/5e5fe0c7c67d55373767d4965b163822 to your computer and use it in GitHub Desktop.
PaperKey with Bash
#!/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