Sit down at a restaurant, point your phone at a small square of black-and-white speckle on the table, and a menu appears. It takes less than a second. You do not frame the shot, tap a button or wait for anything to load. You have probably done it hundreds of times without wondering how it works.
It is worth wondering. That square is a small masterpiece of information engineering. A well-made code can be read upside down, at an angle, and even with some dirt or damage. With enough error correction and careful design, a small logo in the middle may still leave it readable. It holds a complete, self-checking, self-repairing message, and it was designed more than thirty years ago to count car parts.
There is also a trap for the unwary. Because a QR code looks mysterious, people assume it is protected. It is not: anyone with a phone can read what is inside. But precisely because it is such a good carrier, a QR code makes a surprisingly good envelope for messages that are protected. This article explains how the square is built, then how to use it to move encrypted text from one person to another.
A Barcode That Ran Out of Room
The story starts in a car factory. In the early 1990s, Denso, a major supplier in the Toyota group, tracked parts with ordinary barcodes: rows of thin and thick stripes that a laser sweeps across. They worked, but they had two limits. A one-dimensional barcode holds only a couple of dozen characters, and it has to be scanned from the right direction. Factories wanted to label parts with more information, including Japanese characters, and to read it quickly however a part happened to be lying.
A team at Denso, in the division that later became Denso Wave and led by an engineer named Masahiro Hara, built something better. They announced the Quick Response code in 1994. The "quick" was the point: the team's main goal was fast reading, and speed shaped almost every design choice.
The most charming of those choices is the three big squares in the corners. A scanner has to find a code before it can read it, so the team wanted a target that stood out from everything else printed on a box or label. They surveyed printed material for the least common ratio of black to white and built the target around it. That ratio turned out to be 1:1:3:1:1: one unit of black, one of white, three of black, one of white, one of black. Slice through the middle of a QR corner target in any direction and you cross exactly that rhythm. Very little else in the printed world does, so a scanner can spot a code almost instantly. (Hara has also said the idea of a grid came to him from the board game Go, where stones sit on a lattice of lines.)
Then came a decision that changed the square's fate. Denso Wave made the specification public and committed not to exercise its relevant patent rights against QR codes that follow the JIS or ISO standards. That made standards-compliant generators and readers widely accessible. The format was adopted as an international standard, ISO/IEC 18004, in 2000, and the current edition dates from 2024. In Japan, phones began reading QR codes in the early 2000s, and public use took off around 2002. Elsewhere the turning point was the camera app: the iPhone's camera learned to read codes natively with iOS 11 in 2017, and contactless menus did the rest. A square invented for factories had become public infrastructure.
QR Codes at a Glance
| Feature | QR Code |
|---|---|
| Type | Two-dimensional matrix barcode: a way of encoding data, not a cipher |
| Main idea | Turn bytes into a grid of dark and light modules, plus repair bytes so damage can be fixed |
| Invented | 1994, by a team led by Masahiro Hara at Denso (now Denso Wave), Japan |
| Standard | ISO/IEC 18004 (current edition 2024) |
| Size | Versions 1 to 40, from 21 × 21 up to 177 × 177 modules (17 + 4 × version) |
| Data modes | Numeric, alphanumeric, byte, Kanji |
| Largest capacity | 7,089 digits, 4,296 alphanumeric characters, 2,953 bytes, or 1,817 Kanji (version 40, lowest error correction) |
| Error correction | Reed–Solomon codes at four levels, recovering roughly 7%, 15%, 25% or 30% of the code's codewords (data plus repair bytes) |
| Security | None by itself. Any scanner reads the content. |
| Best use | Links, Wi-Fi, contacts, tickets, short offline transfers, and carrying text that was already encrypted |
Why Three Corners?
Look at a QR code and you will see targets in three corners but not the fourth. That absence is deliberate. Three targets are enough to tell a scanner two things: where the code sits, and which way is up. Rotate the code any way you like and the scanner can still work out the orientation, which is why you can scan from the side or upside down.
The rest of the structure is just as functional. Two lines of alternating dark and light squares, the timing patterns, run between the targets like the marks on a ruler, so the scanner can calibrate the spacing. Larger codes include smaller alignment targets that help correct for a curved bottle or a tilted poster. A strip of format information records the error-correction level and the mask pattern, written twice in case one copy is damaged. From version 7 upward, version information is added so larger codes announce their own size. And a blank margin four squares wide, the quiet zone, stops the surroundings being mistaken for part of the code. Forgetting it is one of the most common reasons a homemade code fails.
The diagram shows a version 7 code (45 × 45 modules), the smallest size that includes every part.
| Part | What it does |
|---|---|
| Finder patterns | Three nested squares that tell the scanner where the code is and how it is rotated |
| Separators | A one-module light border isolating each finder from the data |
| Timing patterns | Alternating dark and light lines that calibrate the grid spacing |
| Alignment patterns | Small targets (version 2 and up) that correct for distortion |
| Format information | Error-correction level and mask number, stored twice and protected by its own error-correcting code |
| Version information | Present from version 7, so larger codes announce their own size |
| Data and error correction | Your message and its repair bytes |
| Quiet zone | A blank margin, 4 modules wide |
How a Scanner Reads a Tilted Photo
Real scanning is messier than reading a flat printout. The code might be photographed from an angle, on a curved bottle, in uneven light. Here is the usual sequence, though individual scanners differ in the details.
First, the camera image is reduced to black and white, typically by comparing each region with its own surroundings so that a shadow across one side does not turn it all dark. Then the scanner sweeps along the image's rows looking for runs that match the 1:1:3:1:1 rhythm, and checks candidates in other directions to rule out coincidences. Three confirmed targets give it three corners and, from their positions, the code's rough size and orientation.
The tilt is the interesting part. A square seen at an angle becomes a four-sided shape with converging edges. Knowing where three corners are, and estimating the fourth, the scanner works out the geometric transformation that would flatten the shape back into a perfect square. Alignment patterns in larger codes give it extra reference points to refine that correction across the grid. With the transformation in hand, it can lay an imaginary perfect grid over the photo, look at the centre of each cell, and read dark or light. The timing patterns give it a check that the grid lines up.
All of that happens in a fraction of a second, which is why a code can be scanned from a moving hand.
A Grid of Yes and No
What remains is data, and the data is nothing more exotic than a grid of bits. Each small square, called a module, is dark (one) or light (zero). The scanner reads the bits and rebuilds the message.
How much can fit? The largest QR code, version 40, is 177 squares across. At the lowest error-correction level it can hold 2,953 bytes of ordinary text, roughly a page of typing. The smallest, version 1, is 21 squares across. Each version adds four squares to each side. Smaller codes are easier to scan: at the same printed size, a bigger version means smaller squares, and past a certain point a phone camera cannot resolve them. The shorter your message, the more reliable your code.
Inside, the generator picks one of four modes depending on the content. Digits only? Numeric mode packs three digits into ten bits. Capital letters, digits and a few symbols? Alphanumeric mode packs two characters into eleven bits. Anything else, including lowercase letters, goes in byte mode at eight bits per byte. (A Kanji mode exists too.) The generator also picks the smallest version that fits.
A Worked Example: Encoding "Hi"
Take the two-letter message Hi, at the lowest error-correction level. It contains a lowercase letter, so it uses byte mode. For version 1 the character-count field is eight bits. The generator writes a four-bit tag for the mode, the count, the data, and a short run of zeros to mark the end:
0100 00000010 01001000 01101001 0000
| Bits | Part | Meaning |
|---|---|---|
0100 |
Mode indicator | Byte mode |
00000010 |
Character count | Two bytes follow |
01001000 |
Data | 72, which is H |
01101001 |
Data | 105, which is i |
0000 |
Terminator | End of data |
Regroup those 32 bits into bytes and you get 40 24 86 90. A version 1 code at this level holds 19 data bytes, so the remaining 15 are filled with an alternating pair of pad bytes, EC and 11:
40 24 86 90 EC 11 EC 11 EC 11 EC 11 EC 11 EC 11 EC 11 EC
Then seven error-correction bytes, calculated from the data, are appended. For this message they are 7C B8 54 FB 46 11 5F. The total is 26 bytes, or 208 bits, and those are what get spread across the 21 × 21 grid. In all, that is two bytes of content, two of header, fifteen of padding and seven of repair. The generator then applies a mask (this one chose mask 2), and the scanner undoes it.
Why There Are Eight Masks
Look closely at that padding: EC 11 EC 11 EC 11. It is perfectly regular. Written straight into the grid, it would produce stripes, and a message that happens to be all zeros would produce a big featureless block. Large uniform areas are bad for scanners. They give the camera nothing to calibrate against, and regular stripes can mimic the rhythm of the corner targets and fool the search.
The fix is the mask. The standard defines eight masks, each a simple rule based on a module's row and column, such as "flip every module where row plus column is even" or "flip every third column". Applying a mask flips the data modules it selects (never the corner targets or other fixed patterns), which breaks up the regularity.
The clever part is that the generator does not pick one in advance. It tries all eight and scores each result against four penalty rules: long runs of same-coloured modules in a row or column, 2 × 2 blocks of the same colour, patterns that look like a corner target, and an imbalance between dark and light modules. The lowest score wins. The winning mask's number is written into the format information, so the scanner knows which flips to undo.
The Trick That Lets It Survive Damage
If you tear a corner off a QR code, scratch it, spill coffee on it or print a logo across the middle, it often still scans. That is because of the repair bytes, and the mathematics behind them is one of the great ideas of twentieth-century information theory.
In 1960 two American mathematicians, Irving Reed and Gustave Solomon, described a way to add carefully calculated check values to a block of data so that, even if some of it goes missing or is corrupted, the original can be rebuilt. The same Reed–Solomon codes protect the music on a compact disc, so that a scratch does not produce a click, and they have been used to send images back from deep-space probes, where a bit of cosmic noise must not ruin a photograph.
Think of sending someone a book and tucking in a few extra pages that are not part of the story but are written by a special rule from all the other pages. If a few pages are lost in the post, the recipient can use the extra pages to work out exactly what was on the missing ones. The more extra pages, the more damage survived, and the heavier the parcel.
A QR code lets you choose how heavy. There are four levels, able to restore roughly 7, 15, 25 or 30 percent of the code's codewords. For a version 1 code the split looks like this:
| Level | Nominal recovery | Data bytes | Repair bytes | Codewords restorable (of 26) |
|---|---|---|---|---|
| L (Low) | 7% | 19 | 7 | 3 |
| M (Medium) | 15% | 16 | 10 | 5 |
| Q (Quartile) | 25% | 13 | 13 | 6 |
| H (High) | 30% | 9 | 17 | 8 |
One precision matters here. The familiar percentages are nominal recovery levels for codewords, the bytes the code is built from, counting both data and repair bytes. They are not exact limits for every version, and they are not a share of the printed area. Correcting a codeword error at an unknown position uses two repair codewords, so version 1-L's seven repair codewords can correct three such errors; version 1-H's seventeen can correct eight. How many codewords a scratch destroys depends on where it falls. Larger versions split their data into several blocks, each with its own repair budget, and interleave them across the grid so that local damage is spread thin. (Version 1 is small enough to use a single block, so there is nothing to interleave.) Treat the figures as a budget, not a guarantee that "30% of the square can be covered."
These pictures were tested with a software decoder. Real phones, lighting and printing vary, so treat them as demonstrations, not guarantees.
Higher levels protect more, but the repair bytes take up room, so the same text needs a bigger code:
| Payload | L | M | Q | H |
|---|---|---|---|---|
| 26 bytes | v2 (25 × 25) | v2 (25 × 25) | v3 (29 × 29) | v4 (33 × 33) |
| 100 bytes | v5 (37 × 37) | v6 (41 × 41) | v8 (49 × 49) | v10 (57 × 57) |
| 300 bytes | v11 (61 × 61) | v13 (69 × 69) | v16 (81 × 81) | v18 (89 × 89) |
This is also why a logo in the middle of a code can work at all: the logo hides some modules, and the repair bytes quietly rebuild them. It is a clever use of the safety margin, but a margin it remains. A large logo plus a smudged print plus an old phone can overspend it.
How Much Can One Square Hold?
The ceiling falls as the error-correction level rises. In byte mode at version 40, the maximum is 2,953 bytes at level L, 2,331 at M, 1,663 at Q and 1,273 at H. Those are the largest codes, with modules so small that most phones struggle unless they are printed large. For everyday use, aim far lower:
| Payload size | Level M | Practical advice |
|---|---|---|
| 10 to 30 bytes | v1 to v3 | Short links and codes. Very easy to scan. |
| 100 bytes | v6 (41 × 41) | A longer link or a short note. Comfortable. |
| 300 bytes | v13 (69 × 69) | Fine on a screen or a large print. |
| 1,000 bytes | v26 (121 × 121) | Needs a big, sharp, well-lit code. |
| 2,000 bytes | v38 (169 × 169) | Technically possible, rarely sensible. |
Numeric and alphanumeric modes pack data more tightly than byte mode, so a link written entirely in capitals can make a smaller code in generators that switch modes automatically. The QR Code Toolkit encodes everything in byte mode, so it does not apply that optimisation; for typical links the difference is small.
A Square Is Just Data
What can a QR code hold? Bytes. The standard can carry any sequence of bytes, including binary data, but most phone scanners hand over what they find as text, and that is what the camera app acts on. So in practice, what the phone does depends on the text it gets. If it begins with https://, the phone offers to open a website. If it begins with tel:, it offers to call. The format of the string tells the phone what to do:
| Type | Example payload | What a phone does |
|---|---|---|
| Website | https://cipherregister.com |
Offers to open the link |
| Plain text | Hello from a QR code |
Shows the text |
| Wi-Fi | WIFI:T:WPA;S:Guest;P:welcome123;H:false;; |
Offers to join the network |
mailto:[email protected]?subject=Hello |
Opens a draft email | |
| Phone | tel:+447700900123 |
Offers to call |
| SMS | SMSTO:+447700900123:Hi there! |
Opens a pre-filled text message |
| Contact | BEGIN:VCARD … END:VCARD |
Offers to save a contact |
| Location | geo:51.5007,-0.1246 |
Opens a map pin |
| Calendar event | BEGIN:VEVENT … END:VEVENT |
Offers to add an event |
Two details catch people out. The special characters in a Wi-Fi string (\ ; , : ") must be escaped with a backslash, or a password containing them will not parse. And characters outside plain ASCII, such as accents or emoji, take several bytes in UTF-8, and some scanners guess the character set. If a message must survive every scanner, keep it to plain ASCII or test it.
Making a Code That Actually Scans
A QR code is a communication channel between a printed or displayed square and a camera, and anything that weakens the signal weakens the channel.
| Choice | Risk | Advice |
|---|---|---|
| Contrast | The most common reason a code fails | Dark modules on a light background. Aim for strong contrast; a colour ratio alone cannot guarantee a successful scan. |
| Inverted colours | Light-on-dark codes are not read by every scanner | Stay dark-on-light unless you can test the devices you care about. |
| Quiet zone | Under 4 modules can stop a scanner finding the code | Keep the standard 4-module border. |
| Logo | Spends the repair budget | Keep it to roughly a quarter of the width or less, with Quartile or High correction. |
| Dots, rounded or fluid modules | Less sharp than squares | Usually fine, but test. Square modules and classic corners are safest. |
| Gradients | The light end lowers contrast | Keep both ends dark enough. |
| Printed size | Too small and modules blur together | A common rule of thumb is that a code can be scanned from about ten times its width. |
| Transparent background | The code reads against whatever is behind it | Place it on a plain, light surface. |
For print, export a vector SVG so the edges stay sharp at any size. For screens, a large PNG is enough. And test the final artwork on a real phone, in the light where it will be used.
Static and Dynamic Codes
A static code contains the data itself. A dynamic code contains a short link to a service, which redirects to the real destination. That allows destination editing and request tracking, but it depends on the service staying online. The service can record visits when someone opens the redirect link; simply decoding a code offline does not contact it.
A static code is as durable as a printed page: the square will always decode to the same text. But what the text points to can change. A static code containing a link keeps reading perfectly even if the website behind it has vanished. A static code containing Wi-Fi details or encrypted text carries all of its own data, though joining the network still needs that network to exist, and decrypting the text still needs the key. The flip side is that a printed static code can never be corrected; change the content and you make a new code.
Try It in the QR Code Toolkit
The QR Code Toolkit lets you try most of the ideas in this article in one page. Here is a five-minute tour:
- Create. Choose a type (website, Wi-Fi, contact and six others), type your content, and the preview updates as you go. Change colours, pick a module style, add a logo or a caption frame.
- Check it. Beside the preview, a checklist flags weak contrast, a thin quiet zone or an oversized logo, and a scan test runs a real decoder on the finished design, logo and all.
- Export. Download a PNG (up to 4,096 pixels) or an SVG for print.
- Bulk. Paste a list of links and download a ZIP of codes in the same style.
- Reader. Upload or drop an image, use Paste image or Ctrl/Command + V, or start the camera. Wi-Fi, contact and event codes are broken into labelled fields, passwords stay hidden until you click Show, and links are never opened for you. After scanning, Save a clean QR code lets you copy a fresh QR image or download a pristine PNG or SVG. It keeps the full decoded text, including any passwords, but removes the original styling and damage; the square pattern may change. For an archive, this exports that one page, not the restored file.
Your QR content is processed on your device and is not uploaded. The toolkit's QR encoder, reader library and interface runtime are served by CipherRegister, rather than fetched from a third-party CDN. Optional camera access needs your permission, and opening a decoded website naturally contacts that website. The QR Code Toolkit also deliberately does not encrypt anything. It encodes exactly what you give it, which makes it a clean last step after encryption.
Not a Lock
Here is where most people go wrong. Because a human cannot read the pattern, the information inside seems tucked away. It is not. Every phone camera is a free decoder, and the format is public. If a café prints its Wi-Fi password in a QR code on the wall, everyone in the café has the password, and so does anyone who photographs the wall.
The right comparison is with other encodings. Hexadecimal turns bytes into pairs of digits. Base64 turns them into printable characters so they can travel through text-based systems. A QR code turns them into squares so they can travel from paper or a screen into a camera. All three change how data looks. None changes who can read it.
| Method | Needs a secret to reverse? | What it is for |
|---|---|---|
| Hex | No | Showing raw bytes as readable text |
| Base64 | No | Carrying binary data through text-only systems |
| QR code | No | Carrying data from paper or a screen to a camera |
| Caesar, Vigenère, substitution | Yes, but trivially breakable | Puzzles and learning |
| XOR with a short repeating key | Yes, but weak | Learning how bytes and keys combine |
| AES-GCM with a strong key | Yes, and strong | Real confidentiality and tamper detection |
That gives three jobs people often blur together. Encryption decides who can read a message. Encoding decides how it is represented. Transport decides how it gets from A to B. A QR code is encoding and transport in a neat square. The first job needs a key.
Putting a Secret in the Envelope
Once you see the three jobs apart, the idea is straightforward. Encrypt a message first, put the scrambled result into a QR code, and the code becomes a camera-readable envelope. Anyone can scan it, but all they get is gibberish. Only someone with the key can open it.
The recipe has five steps. Encrypt the message. Convert the encrypted bytes to printable text, using Base64 or hex, because most scanner apps hand over text. Paste that text into a QR generator as a plain Text code and save the image. Share it. The recipient scans it to get the scrambled text back, and decrypts it with the key, which reached them by a different route.
Choosing the cipher
| Option | Strength | Good for |
|---|---|---|
| Caesar, Vigenère, substitution | Weak. Broken by frequency analysis. | Escape rooms, treasure hunts, classroom puzzles. The output is letters, so it can go straight into the code. |
| XOR with a short repeating key | Weak. Known-plaintext and key-length attacks work. | Learning how bytes and keys combine. Show the bytes as hex. |
| XOR one-time pad | Perfect, if the key is truly random, as long as the message, used once and kept secret | Rare, high-effort cases where the key can be handed over in person. |
| AES-256-GCM with a strong passphrase | Strong, and it detects tampering | Real confidential notes. See the example below. |
| Public-key encryption (for example age or PGP) | Strong, with no shared passphrase | One-way messages to someone who has published a public key. |
A toy version
Try the XOR Cipher tool with MEET AT NOON and the repeating key KEY. The twelve bytes become:
06 00 1C 1F 65 18 1F 65 17 04 0A 17
As Base64 that is BgAcH2UYH2UXBAoX. Put either into a Text code and you get a tiny, scannable square. Scan it, apply KEY, and the message reappears. It is a lovely demonstration of the pipeline and a poor way to keep a secret: a short repeating key leaves fingerprints that cryptanalysts have exploited for a century. Treat it as a puzzle, not protection.
A real version
For a practical browser workflow, the File & Message Encryptor and its supporting guide explain how to encrypt and recover a message. Paste the complete encrypted output into the QR toolkit's Text mode, then scan it back and decrypt it in the same encryptor. The custom packet below is a separate teaching example, not the encryptor's message format.
For something that must stay private, use modern authenticated encryption: AES with GCM mode, and a key stretched from a passphrase by a deliberately slow process, so that every wrong guess costs an attacker time. A web browser can do all of this on its own.
The result is a block of Base64 text that bundles a random 16-byte salt (so separate encryptions normally derive different keys from the same passphrase), a random 12-byte one-time number, the scrambled message, and a 16-byte authentication tag. The authentication tag lets decryption detect an incorrect passphrase or an altered encrypted packet instead of quietly returning modified plaintext.
Here is a real one. Scanning this code gives the string below it:
dQv9VZJwUzxrki1emZL04tHxPpW/jA5Z6bCpGPzf2DdyJiQD4A5HaT4vXdt3FwHMf+6+22tLOVshtKT+7eXinIl0KcroUs2JD8W5
To read it, run it through the script at the end of this article with the passphrase correct horse battery staple 83. (The passphrase is published only because this is a demonstration. In real use it is the whole secret.)
Encryption adds weight, so the code grows faster than the message. This table uses ASCII text, where each character takes one UTF-8 byte; accented characters, other scripts and emoji can take more. At error-correction level M:
| Message | Packet bytes | Base64 characters | QR version |
|---|---|---|---|
| 12 ASCII characters | 56 | 76 | v5 |
| 31 ASCII characters (the demo) | 75 | 100 | v6 (41 × 41) |
| 100 ASCII characters | 144 | 192 | v10 (57 × 57) |
| 250 ASCII characters | 294 | 392 | v15 (77 × 77) |
| 500 ASCII characters | 544 | 728 | v22 (105 × 105) |
| 1,000 ASCII characters | 1,044 | 1,392 | v31 (141 × 141) |
The absolute ceiling depends on the error-correction level, because the whole packet must fit in one code as text:
| Level | Largest code (bytes) | Largest message in this packet format |
|---|---|---|
| L | 2,953 | about 2,170 bytes |
| M | 2,331 | about 1,702 bytes |
| Q | 1,663 | about 1,201 bytes |
| H | 1,273 | about 910 bytes |
In practice, keep a single code to a few hundred characters of message so that it stays easy to scan, and split anything longer, as the next section explains.
The rules that decide whether it protects anything
Never put the key next to the code. A QR code with its passphrase printed underneath is a QR code with no encryption. Send the passphrase a different way: say it aloud, hand it over in person, or use a separate channel you trust.
- The passphrase is the security. Anyone who photographs the code can try guesses offline for as long as they like. A long, randomly chosen passphrase, such as six or more random words, is what stands between them and the message. A clever-sounding sentence is not good enough.
- Use a real cipher for real secrets. AES-GCM or an equivalent detects tampering. A classical cipher cannot.
- Use a fresh random salt and one-time number every time. Reusing the one-time number under the same key badly breaks GCM. The example generates both afresh.
- Remember what stays visible. The code cannot hide that a message exists, or roughly how long it is. It is an envelope, not an invisibility cloak.
The example is a teaching tool, built from standard browser functions, not an independently reviewed encryption protocol. For information that truly matters, use an established tool such as age or a well-reviewed library, and treat the QR code as the courier.
When One Square Is Not Enough
A single code tops out at a few kilobytes, and much sooner if you want comfortable phone scanning. The toolkit's Documents tab offers two different ways to work with something longer. They are deliberately separate because reading one page of text and rebuilding an exact file are not the same task.
Readable text pages: read any page on its own
Readable text pages is the default. Paste your text, or upload a UTF-8 text or Markdown file, and the toolkit divides it into ordinary text QR codes. Each starts with a short title and a heading such as QR text page 2 of 12, followed by that page's part of the text. Scan any one of them with a text-capable reader and that part appears immediately. You do not need the other eleven pages, and there is no archive to rebuild.
The density setting targets 300, 600 or 950 UTF-8 bytes of text per code, plus its heading. Smaller chunks are usually easier to scan. These are bytes, not necessarily characters: emoji and many non-English characters use more than one byte. Splitting prefers whitespace boundaries and preserves the text; it does not extract text from a PDF, EPUB or other binary document. Use the original text or a UTF-8 export if you want independently readable pages.
Whole-file archive: every piece is needed
Whole-file archive is the advanced option for preserving a file's exact bytes. It optionally compresses the file when that saves space, packages its bytes as Base64url, and divides the result among numbered QR codes. These pages use the toolkit's own QRP1 format, not the QR standard's structured append facility, which is limited to sixteen symbols.
A single archive page is one piece of a file, not a readable passage. The Reader's Whole-file archive collector accepts pages in any order, shows which ones are missing, and restores the file only when every required page has arrived. Think of it as a jigsaw made from one file: one piece is useful to the collector, but is not the complete picture. The stored size and CRC-32 checksum help detect accidental corruption; they do not authenticate a file or protect it from deliberate tampering.
Both modes accept inputs up to 3 MiB and up to 5,000 QR pages. A long book can therefore mean hundreds of scans: interesting as a technical experiment, but not a convenient way to distribute a novel. Existing QRP1 pages remain archive pieces. To make independently readable pages instead, regenerate them from the original text with Readable text pages selected.
For a long secret, encrypt first, then split. The resulting pages carry ciphertext, not readable passages; collect or join the complete encrypted output before decrypting it. If you need compression, do it before encryption, because properly encrypted data does not normally compress well. Neither document mode encrypts its contents. A CRC checksum catches accidents; authenticated encryption is what detects tampering.
Where Encrypted QR Codes Make Sense
They are no replacement for a secure messaging app. Their strength is that they move data across a gap with no network at all, using nothing but light. That suits puzzles and games, where a scanned code is the first clue in a chain; teaching, as a concrete demonstration that encoding, encryption and transport are separate jobs; offline transfers between devices that are never connected, which is how some hardware wallets and other air-gapped devices work; and paper backups, such as a note encrypted with a strong passphrase and printed as a code, with the passphrase kept somewhere else entirely.
Scanning Unknown Codes
The mirror image of all this is just as important. A code can carry any text, and a phone may act on it. Criminals have stuck their own codes over legitimate ones on parking meters and posters so that a scan leads to a fake payment page, a trick known as "quishing". The pattern gives you no clue where a link goes, and a code can also ask a phone to join a network, place a call or add a contact. The habit worth building is simple: read the address or prompt your phone shows before you approve it, exactly as you would with a link in an email. That is also why the QR Code Toolkit's Reader shows the raw decoded text and only opens a link when you click Open.
A Short Experiment: Encrypt, Then Convert to Base64
This script runs in a browser console on a secure page (HTTPS or localhost), using only the browser's built-in cryptography. It turns a message and a passphrase into one Base64 string ready for a QR code, and reverses it. It performs encryption and Base64 conversion only; making the QR code is the next step, in the QR Code Toolkit.
JavaScript exampleShow code
const enc = new TextEncoder();
const dec = new TextDecoder();
async function deriveKey(passphrase, salt) {
const base = await crypto.subtle.importKey("raw", enc.encode(passphrase), "PBKDF2", false, ["deriveKey"]);
return crypto.subtle.deriveKey(
{ name: "PBKDF2", salt, iterations: 600000, hash: "SHA-256" },
base,
{ name: "AES-GCM", length: 256 },
false,
["encrypt", "decrypt"]
);
}
function toBase64(bytes) {
// Convert in chunks: spreading a very large array into one call overflows the call stack.
let binary = "";
for (let i = 0; i < bytes.length; i += 8192) {
binary += String.fromCharCode(...bytes.subarray(i, i + 8192));
}
return btoa(binary);
}
async function encryptToBase64(message, passphrase) {
const salt = crypto.getRandomValues(new Uint8Array(16));
const iv = crypto.getRandomValues(new Uint8Array(12));
const key = await deriveKey(passphrase, salt);
const ciphertext = new Uint8Array(
await crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, enc.encode(message))
);
const packed = new Uint8Array(16 + 12 + ciphertext.length);
packed.set(salt, 0);
packed.set(iv, 16);
packed.set(ciphertext, 28);
return toBase64(packed);
}
async function decryptFromBase64(text, passphrase) {
const packed = Uint8Array.from(atob(text), (c) => c.charCodeAt(0));
const salt = packed.slice(0, 16);
const iv = packed.slice(16, 28);
const ciphertext = packed.slice(28);
const key = await deriveKey(passphrase, salt);
const plain = await crypto.subtle.decrypt({ name: "AES-GCM", iv }, key, ciphertext);
return dec.decode(plain);
}
Call await encryptToBase64("Meet at the old bridge at noon.", "your passphrase") and you get a string that differs every time, because the salt and the one-time number are random. Paste it into a QR code. Call decryptFromBase64 with the same passphrase and the message returns. Use the wrong passphrase, or change one character of the packet, and it throws an error instead.
The lines that matter: getRandomValues draws the salt from the system's cryptographic random source (never use Math.random() for this); iterations: 600000 makes each passphrase guess more expensive, though it cannot rescue a weak password; the AES-GCM call appends the 16-byte tag, which decrypt checks; and toBase64 converts in chunks so a longer text does not overflow a function call's argument limit. This example encrypts text, not arbitrary file bytes; use a file-aware tool and format for binary documents.
Common Questions About QR Codes
How much data can a QR code hold? Up to 2,953 bytes at the lowest error correction, falling to 1,273 at the highest. For reliable phone scanning, a few hundred bytes is a much better target.
Is it safe to put a Wi-Fi password in a QR code? It is as safe as showing the password to everyone who can see the code. Fine for a guest network, a poor idea for a private one.
Why won't my QR code scan? The usual causes are low contrast, inverted colours, a missing quiet zone, a code printed too small, too much data, an oversized logo, or glare.
Can a QR code contain a virus? Scanning a code does not normally run malware by itself: the pattern is just data. The risk is what that data leads to, such as a malicious website, a rogue Wi-Fi network or a fake payment page. Rare bugs in scanner software are possible too, so keep your phone updated. Read the prompt before approving, and be wary of codes stuck over other codes.
Can I put a logo in a QR code? Often, but not reliably with every logo or scanner. Error correction may recover data covered by a small logo; it does not make every covered area safe. Keep the logo modest, leave the finder patterns and quiet zone intact, use Quartile or High correction, and test on real phones.
The Lesson in the Square
A QR code is not a safe, and was never meant to be. It was designed to be read quickly by a machine, from any angle, even when damaged, and it does that better than almost any other everyday technology.
What makes it interesting to anyone who cares about codes and ciphers is how cleanly it separates three jobs we usually blur together. A cipher decides who can read. An encoding decides how it looks. A transport decides how it travels. Once you can see where each starts and stops, you can build the whole chain on purpose: encrypt, encode, scan, decrypt, and keep the key somewhere the square is not.
The next time you scan a menu, spare a thought for the three targets in the corners, chosen because almost nothing else in print looks like them, and for the extra pages tucked into the parcel by two mathematicians in 1960. Then think about what you would put inside one, and what you would lock it with first.