[HN Gopher] Creating a QR Code step by step
       ___________________________________________________________________
        
       Creating a QR Code step by step
        
       Author : creolabs
       Score  : 262 points
       Date   : 2020-08-11 11:10 UTC (11 hours ago)
        
 (HTM) web link (www.nayuki.io)
 (TXT) w3m dump (www.nayuki.io)
        
       | dontbenebby wrote:
       | Along similar lines is there any guides on making more artful QR
       | codes? I've seen ones that aren't square but still scan and found
       | them fascinating.
        
       | russellbeattie wrote:
       | Though QR codes are very interesting technically, they were
       | designed to be used by devices with orders of magnitude less
       | computational power than is currently the norm, and much lower
       | resolution optics as well. This is a good thing from an error-
       | prevention perspective, but I wonder if a more modern QR code
       | could be designed for today's smartphones.
       | 
       | I think an interesting new standard would take advantage of
       | higher resolution cameras and OCR functionality to make data
       | transparent to the consumer. I personally wonder what the hell is
       | going to pop up on my phone every time I use a QR code... Text?
       | URL? Link to an app store? Who knows. A standard which marks text
       | as "data" would let a user know what they're saving, and let them
       | point a camera in the general direction of some text, and all the
       | relevant info be extracted and organized. (Think addresses,
       | receipts, etc.) I already use my phone to remember lots of things
       | - like I take a picture of the back of my DSL router for the
       | access codes printed there, or take a picture of my bike tire to
       | remember the size of the tube I need, etc.
       | 
       | Or if transparency isn't important, given we have 4K cameras now,
       | imagine if there was a popular standard using steganography! I
       | can imagine movie posters having showtimes, director and actor
       | info, URLs for streaming it online, etc. all baked into the
       | image.
        
       | Bokanovsky wrote:
       | For those interested in the creation of the QR code. Japanese TV
       | Station NHK World have a 15 minute documentary charting it's
       | creation -
       | https://www3.nhk.or.jp/nhkworld/en/ondemand/video/2072031/
       | 
       | It also features interesting details such as how they figured out
       | the ratio of the marker squares should be.
        
       | layoutIfNeeded wrote:
       | >The math behind computing the Reed-Solomon error correction
       | codes is omitted because it is long, tedious, and not very
       | interesting.
       | 
       | LOL! That's probably the most difficult part of creating a QR
       | code, the rest is just framing/padding the data which is pretty
       | obvious.
        
         | mytailorisrich wrote:
         | I'd argue that while Reed-Solomon is used in QR codes, the math
         | behind it is not central to explaining how to create a QR code,
         | and there are plenty of material available on Reed-Solomon.
         | 
         | Specific framing/padding of the data is what makes a QR code.
         | This may be simpler than explaining how Reed-Solomon codes work
         | but it is not obvious.
         | 
         | I think it is good that this article stays on point.
        
           | nayuki wrote:
           | Other discussions on Hacker News and Reddit have requested me
           | to show the Reed-Solomon ECC calculations too (see
           | https://news.ycombinator.com/item?id=18370829 ).
           | 
           | mytailorisrich is correct; Reed-Solomon is used by many
           | different standards, so it's not difficult if you learned it
           | elsewhere. Whereas other parts of the QR Code standard are
           | idiosyncratic, i.e. unique to it. If you want to see for
           | yourself, go learn how Data Matrix works (another 2D barcode)
           | and notice how little knowledge you can carry between the two
           | standards.
           | 
           | As for showing the Reed-Solomon calculations, I stand by my
           | statement of them being long and tedious. Moreover, it
           | requires background knowledge of finite field arithmetic (as
           | opposed to ordinary arithmetic), which increases the
           | explanation length and makes the calculations even more
           | difficult to follow by hand.
           | 
           | The actual Reed-Solomon encoding is conceptually simple.
           | First you choose a generator element. Then you create a
           | divisor polynomial by multiplying monomial terms involving
           | powers of the generator. Then you encode the message as a
           | polynomial, and finally divide the message by the divisor to
           | yield the remainder polynomial, which is the final RS ECC
           | data.
           | 
           | If you want to see the cryptic verbosity of tons of numbers,
           | here are examples: https://www.backblaze.com/blog/reed-
           | solomon/ ; https://www.youtube.com/watch?v=H2LlHOw_ANg (AES)
        
         | jedimastert wrote:
         | For those curious, I've always found Computerphile has a
         | reasonable explanation for most things
         | 
         | https://www.youtube.com/watch?v=fBRMaEAFLE0
        
         | eru wrote:
         | And perhaps the most interesting part, too.
        
       | rsync wrote:
       | ... or you could just use an "Oh By" code.[1]
       | 
       | No app, no reader, and you can just chalk/write/scratch it
       | anywhere you like.
       | 
       | This message, for instance, is at: 0xH6VYP7 [2]
       | 
       | [1] https://0x.co/
       | 
       | [2] https://0x.co/H6VYP7
        
         | nayuki wrote:
         | What happens when the company goes out of business?
         | 
         | What happens when you try requesting random short URLs to peep
         | on other people's texts?
        
           | rsync wrote:
           | "What happens when you try requesting random short URLs to
           | peep on other people's texts?"
           | 
           | I think most use-cases involve a code that you chalk up, or
           | write, or paste publicly ... I am not sure that the codes
           | being secret will be a common use-case.
           | 
           | There's a fair amount of space in a 6-digit alpha-numeric
           | code, though (36^6, roughly) ... that's a lot of brute
           | forcing ...
        
             | nayuki wrote:
             | 36^6 = 2,176,782,336
        
               | rsync wrote:
               | Correct - thank you.
        
           | rsync wrote:
           | "What happens when the company goes out of business?"
           | 
           | That's the most frequently asked question.
           | 
           | rsync.net has been providing service, continuously, for 19
           | years, so it's not without a good track record that I say I
           | will keep "Oh By" running forever, even if it doesn't make
           | any money.
           | 
           | Interesting trivia: Oh By has actually made money ... as in,
           | people have paid for custom Oh By codes.
        
         | anamexis wrote:
         | I get an SSL error NET::ERR_CERT_COMMON_NAME_INVALID, with the
         | certificate's subject being dock.shp.mcafee.com
         | 
         | Edit: Never mind, it's my ISP (CenturyLink) being dumb and
         | saying it's malicious. Need to figure out how to disable that.
        
       | bartvk wrote:
       | Previous discussion:
       | https://news.ycombinator.com/item?id=18360847
        
       | asutekku wrote:
       | I appreciate the steps, but this fails to answer a question
       | which, imho, is way too often omitted in tech tutorials, and
       | that's "Why?".
       | 
       | Sure, I understand these are just the steps to create a QR code
       | and I could just Google why the QR code needs a masking pattern,
       | but that's besides the point. A good material would explain why I
       | need it, instead of just saying it should be done. Even one
       | sentence would be sufficient.
        
         | Slartie wrote:
         | The utility of the masking pattern becomes clear when following
         | the next steps, which calculate "penalty points" for dot
         | patterns in the QR code that might occur naturally, but are
         | known to make it harder to read and more prone to erroneous
         | reads. The masking pattern that, when applied to the "clean"
         | content, generates the least problematic output is chosen.
         | 
         | I found this pretty self-explanatory while just following the
         | individual steps. However, a few sentences detailing the
         | higher-level algorithm and its purpose right before the step
         | which first introduces the masking pattern probably wouldn't be
         | a bad idea either.
        
         | patrickg wrote:
         | I have written a QR encoder in Lua and documented it a bit.
         | Perhaps this goes into the direction?
         | 
         | http://speedata.github.io/luaqrcode/docs/qrencode.html
        
         | nayuki wrote:
         | I agree that the why is important, and it reinforces
         | understanding of the how. I share your frustration when I see
         | technical tutorials that show a bunch of screenshots or make
         | you type a bunch of command line actions without explaining
         | what it does and why you should do it.
         | 
         | In this case though, I chose to omit the why because other
         | written resources on QR Codes have covered the topics
         | extensively. Just to name a few:
         | https://en.wikipedia.org/wiki/QR_code ;
         | http://datagenetics.com/blog/november12013/index.html ;
         | https://en.wikipedia.org/wiki/Error_correction_code#Interlea...
         | ; https://en.wikipedia.org/wiki/Clock_recovery
        
       | amenghra wrote:
       | An artisanal QR code goes over the error correcting code by
       | manually calculating the long division:
       | https://www.quaxio.com/an_artisanal_qr_code.html
        
       | mare5x wrote:
       | This is a great resource. I used it along with another practical
       | tutorial (https://www.thonky.com/qr-code-tutorial/) to complement
       | the official QR code standard when I wrote my own QR code encoder
       | in Common Lisp: https://github.com/mare5x/LispQR
        
       | jrexilius wrote:
       | This was a good exploration of your approach. The interactive
       | usage inline with description was very helpful. As some have
       | pointed out, some expansion in certain areas could improve it,
       | but still good.
       | 
       | As a side note, I'm looking into using your libraries. They do
       | seem fairly solid and efficient.
       | 
       | Thanks for putting this out there!
        
       | ChrisMarshallNY wrote:
       | That's really cool! Thanks for sharing it!
        
       | NilsIRL wrote:
       | I found this video to be a lot clearer and with the combination
       | of the website makes understanding easier:
       | https://www.youtube.com/watch?v=KA8hDldvfv0
        
       | katsume3 wrote:
       | How small can you make a QR code until it can't be scanned by a
       | phone?
        
       | flixic wrote:
       | During quarantine I designed a paper-based system for making QR
       | codes by hand. Everything is very papery and bureaucratic, but
       | also fun. Tables to look up bytes, long forms for calculating
       | Reed-Solomon, and even transparent sheets of paper for comparing
       | different masking patterns.
       | 
       | My goal is to film a video of generating a QR code without any
       | computers or even calculators. It's possible, just might take two
       | hours or so.
        
         | dang wrote:
         | Please post it to HN when it's ready, and let us know at
         | hn@ycombinator.com.
        
         | latchkey wrote:
         | That's awesome. Reminds me of Ken Shirriff computing sha256
         | with pencil and paper...
         | 
         | http://www.righto.com/2014/09/mining-bitcoin-with-pencil-and...
        
           | flixic wrote:
           | This was the main inspiration! Also, the fact that I couldn't
           | find anyone going through EVERY step of QR code generation
           | manually (even if CPU-assisted) and in detail.
        
           | IanCal wrote:
           | It's a great way to learn. In my cryptography classes we did
           | all of the algorithms by hand (often shortened, so 16 rounds
           | of something would be dropped to 3 or min bytes dropped) on
           | pen and paper as homework. Hard but it really did make a lot
           | stick in my mind about how things worked.
        
         | MrZander wrote:
         | I'd be very interested in seeing this when you are done!
        
         | AimForTheBushes wrote:
         | This sounds pretty cool. Hope you share it when it's finished!
        
       ___________________________________________________________________
       (page generated 2020-08-11 23:01 UTC)