For a few years, my family and I’ve done some birthday trolling of a kid my wife and I have watched grow up. This year, he graduated high school, and it seemed like maybe it’d be the beginning of the end of the times during which we’d do big involved birthday things for him (he’ll grow up, move away, no longer be a kid you can really troll, etc.). So I decided to do a more elaborate setup than usual. I sent him on a multi-stepped puzzle scavenger hunt for which I acquired props such as a hollowed-out book, a cipher wheel, a wooden puzzle box, and a cryptex. I came up with a few riddles and lined up the puzzles in such a way that one, once solved, pointed to the next.
The first puzzle was a sheet of paper with only this printed on it:
Huh? What the heck is that? I also had this ready to share in case he needed it:
You can begin to see that there’s a pattern. If you know that it’s a birthday thing, you can maybe begin to see that the patterns might read (in part) “Happy B-Day” if the squares with the slants pointing from bottom left to upper right are filled in. Eureka! You’ll now know that you need to shade in the equivalent squares on the other sheet. And when you do that, you’ll get something like this in place of the first image above (slightly modified, so it doesn’t point to anything real):
That’s pretty quickly recognizable as a QR code. It linked to a little web site I set up that offered a riddle that, when solved, pointed him to the next clue, and so on.
I fancy myself a bit of a nerd, but this felt like really nerdy stuff indeed. But that’s not all!
See, when I first made the QR code thing, I drew it by hand, using drawing software on my computer. First I had to make a 25×25 grid, and then I had to print out the QR code I had created for the web site and copy its filled-in squares onto the grid as diagonals. Then I had to fill in all the other diagonals going in the opposite direction. Then I had to print it out, fill in the squares by hand using a Sharpie (to test real life operating conditions), and hope I hadn’t gotten any of the 625 little diagonal marks mixed up (spoiler: I messed them up a number of times because it was a tedious, manual process). Then I’d lather, rinse, repeat until I got it right. It was tedious, but finally I had a file that worked.
And then the QR code that I created using an online generator expired. I hadn’t realized it would have an expiry. This meant I’d need to make a new QR code and repeat the tedious (and actually sort of painful, repetitive-stress-injury-inducing) process all over again.
I wrote code for many years professionally and for side projects, so at this point, the lazy programmer in me woke up. I figured it wouldn’t be too hard to write some little program that’d output the QR code for me and save me lots of frustration — and also be pretty easy to reuse later should I have another QR code expiry issue or another weird project for which this pretty narrowly-focused output would be useful.
I knew how to output image files, and I knew how to use php code to draw simple lines and shapes. The rest was just figuring out how to input the QR code data and how to make it fairly configurable, so that I could run the same code with different options set and output either diagonals or filled-in squares, saving me both drawing and testing time any time I needed to tweak the QR code.
It’s not especially elegant code, but what I came up with is here. A next update should I ever go back to it would have me figuring out how to just turn a url into a QR code and automatically outputting the image based on a url input, whereas right now, you still have to fill in a data array using ones and zeroes to sort of map out the squares in the code. But for now, it’s a fun little piece of code with a practical — if rarely practical — application. Should you ever have a need to generate such a thing, the code is yours for the taking. It really does make it very easy to map out a QR code and easily display either the shaded version or the more cryptic diagonal version.
Mostly I wanted to share it as an example of how a silly/fun idea can turn into a neat little code project that can later save time, as I spent less time and much less frustration writing the code for this than I did creating the original version manually.
One thought on “QR Code Puzzle”