Using QR codes for coding files and text

POST_AT

The other day I discovery how change the Guard node (Entry node) in Tor for the Tor daemon, just delete all the files in /var/lib/tor/. This is a bad thing to do, for more information search in Duckduckgo.

Today we will learn how to use QR codes for encoding files. Sometimes we use virtual machines that have no means to interact with the host machine. Maybe due to security concerns or you don't want to mess with config files and command line options. Or simply because you are only allowed to send pictures but no files.

Whatever is your reason, you must be truly desperate to use it as this method is only limited to 3000 characters.

I also tried with OCR software, but that was a pretty bad idea, the QR codes works just well.

Let's we suppose that we want to encode a text file as QR pictures, these are the steps. You should use the base64 command for non plain text files (base64 binary > file.txt)

Step 1. Install zbar where you will decode the text.

You can find it in Ubuntu as zbar-tools and is available in AUR as zbar-headless. In AUR you will also found the QT and GTK version.

I actually compiled it manually and disabled some features at compile time as we only will need the cli.

./configure --without-gtk --without-qt --disable-video

Step 2. Install qrencode

Install this in the place where you will generate the QR pictures. This application is available in the Debian/Ubuntu and Arch repos.

Step 3. Split the file

This step is need only if you need to split the file in several parts as the limit is about 3000 characters With the following command you can split a file by number lines.

split file -l number

You can count the total lines with the following command

wc -l file

Step 4. Create the QR

Execute the following command in the same directory where you split the file:

for p in {a..z} ; do ( cat xa$p | qrencode -o qr$p.png ) ; done

Step 5. Decode the QR codes

Before continue you have to take pictures to the qr codes or taking screenshots, and then rename the pictures with their original names. Then cd to the directory containing the qr pictures.

for p in qr*.png ; do ( zbarimg --raw $p | sed '$ {/^$/d};' ) > ${p%.*}.txt; done

Step 6. Concatenate the files

cat qr*.txt > file

This method works if the qr images are being saved in the target machine with the same name as the source machine.