Ciphers · Classical ciphers
The pigpen cipher
Draw the lines around a letter's cell and you have its symbol. The Freemasons' cipher, with a tool that draws it and decodes it.
The pigpen cipher replaces each letter with a small drawing: the part of a tic-tac-toe grid or an X that surrounds the letter, with or without a dot. It's also called the Freemasons' cipher, because Masonic lodges used it to keep records in the eighteenth century. It's one of the easiest ciphers to learn, to draw and to read once you know the key. It's a substitution cipher in the old sense, with new symbols and the same English statistics underneath.
Try it
Decode: click the symbols in order
Nothing you type here leaves your browser.
The top box draws any text as pigpen symbols, and the keypad below turns symbols you're reading back into letters. Our own code draws the symbols, not a font, so you can download them as an SVG.
How the key works
The alphabet is written into four shapes. Two are tic-tac-toe grids (#): the first holds A to I, and the second holds J to R with its letters carrying a dot. Two are X shapes: the first holds S to V, and the second holds W to Z, with a dot. To encrypt a letter, draw the lines that bound its cell, and the dot if it has one. The letter A, in the top-left cell, is bounded by a line on its right and a line below, so it looks like ┘. The middle cell of the grid, E, is a full square. In an X, the cell at the top is bounded by the two arms of a V, the left cell by >, the right cell by < and the bottom cell by ∧.
There's no single official key. The arrangement above is the one most people draw, but books use others: grids first and then X shapes, or X shapes in between, or the letters running down a grid instead of across. If you want more secrecy you can scramble the order of the alphabet or use a different set of symbols, and then you have a keyed simple substitution.
Where it comes from
The origins are murky and often exaggerated. People sometimes say it's a Hebrew system the Knights Templar used, and the evidence for that is thin. Better documented: Cornelius Agrippa described a similar scheme for the Hebrew alphabet in 1531, Rosicrucians used a single nine-cell grid, and in the early eighteenth century Freemasons began using it to write down rites and to correspond. The best-known surviving example is a headstone in the Trinity Church cemetery in New York City, whose pigpen inscription reads "Remember death".
It had a second life in war. Union prisoners held in Confederate prisons during the American Civil War are reported to have used pigpen to write messages guards couldn't easily read. A legend of the pirate Olivier Levasseur says he threw a scrap of paper written in pigpen into a crowd at his execution in 1730, hinting at a hidden treasure nobody has found. That's a story, not a documented fact.
Today it's a staple of children's cipher books, escape rooms and puzzle hunts. Its popularity has nothing to do with its strength.
Why it isn't secure
A pigpen message is a monoalphabetic substitution: one symbol per letter, always the same one. If you know the standard key, you simply read it. If you don't, you break it like any simple substitution. Count the symbols, assume the commonest is E, and look for short words. If the key isn't the standard one, you can transcribe the symbols into letters from the keypad above and feed them straight into the substitution solver. The index of coincidence is unchanged, and the frequency analysis tool shows an English profile.
The cipher's one real defense is that its symbols look unfamiliar. A guard, a teacher or a curious sibling who has never seen it won't recognize it as writing. That's hiding, not encryption, and it stops working the moment someone has seen the key once.
The code
Where each letter sits in the pigpen key. The tool above draws the lines from this position.
// Pigpen: where a letter sits. A-I fill a tic-tac-toe grid, J-R the same grid with a dot, S-V an X, W-Z the X with a dot.
// The symbol you draw is the part of the lines that surrounds that cell, plus the dot.
function pigpen(letter) {
var i = letter.toUpperCase().charCodeAt(0) - 65;
var dot = (i >= 9 && i < 18) || i >= 22;
if (i < 18) return { shape: 'grid', row: Math.floor((i % 9) / 3), col: i % 3, dot: dot };
return { shape: 'x', cell: ['top', 'left', 'right', 'bottom'][(i - 18) % 4], dot: dot };
}Common questions
Why is it called the pigpen cipher?
The symbols are the walls of the grid cells, and a cell with lines on some sides looks like a pen for animals. It's also called the Freemasons' cipher, the masonic cipher and the Rosicrucian cipher.
Is there only one pigpen alphabet?
No. The commonest layout puts A to I in a grid, J to R in a grid with dots, then S to V and W to Z in two X shapes. Other layouts reorder the shapes or the letters, and some puzzles run the alphabet backwards, so check the key that goes with a puzzle.
How do I decode pigpen without the key?
Assume the standard key first, since most puzzles use it. If that doesn't give words, copy each symbol to a letter in order of first appearance and solve it as a substitution cipher.
Is pigpen the same as the Templar cipher?
The Templar cipher is a variant built on a Maltese cross, and the claim that the Knights Templar used it isn't well supported. The Freemasons' version is the one with documented use.
On the timeline
- Early 1700s Freemasons use the pigpen cipher.