[{"data":1,"prerenderedAt":682},["ShallowReactive",2],{"navigation_docs":3,"-ciphers-four-square":304,"-ciphers-four-square-surround":677},[4,36],{"title":5,"path":6,"stem":7,"children":8,"icon":35},"Guide","\u002Fguide","1.guide\u002F01.index",[9,11,15,19,23,27,31],{"title":10,"path":6,"stem":7},"Getting Started",{"title":12,"path":13,"stem":14},"Encode and decode","\u002Fguide\u002Ftransform","1.guide\u002F02.transform",{"title":16,"path":17,"stem":18},"Analysis","\u002Fguide\u002Fanalysis","1.guide\u002F03.analysis",{"title":20,"path":21,"stem":22},"CLI","\u002Fguide\u002Fcli","1.guide\u002F04.cli",{"title":24,"path":25,"stem":26},"Agents","\u002Fguide\u002Fagents","1.guide\u002F05.agents",{"title":28,"path":29,"stem":30},"Custom ciphers","\u002Fguide\u002Fcustom","1.guide\u002F06.custom",{"title":32,"path":33,"stem":34},"Playground","\u002Fguide\u002Fplayground","1.guide\u002F07.playground","i-lucide-book-open",{"title":37,"path":38,"stem":39,"children":40,"icon":303},"Ciphers","\u002Fciphers","2.ciphers\u002F00.index",[41,43,47,51,55,59,63,67,71,75,79,83,87,91,95,99,103,107,111,115,119,123,127,131,135,139,143,147,151,155,159,163,167,171,175,179,183,187,191,195,199,203,207,211,215,219,223,227,231,235,239,243,247,251,255,259,263,267,271,275,279,283,287,291,295,299],{"title":42,"path":38,"stem":39},"Overview",{"title":44,"path":45,"stem":46},"Classical","\u002Fciphers\u002Fclassical","2.ciphers\u002F01.classical",{"title":48,"path":49,"stem":50},"Caesar","\u002Fciphers\u002Fcaesar","2.ciphers\u002F02.caesar",{"title":52,"path":53,"stem":54},"ROT-13","\u002Fciphers\u002Frot13","2.ciphers\u002F03.rot13",{"title":56,"path":57,"stem":58},"ROT-47","\u002Fciphers\u002Frot47","2.ciphers\u002F04.rot47",{"title":60,"path":61,"stem":62},"Atbash","\u002Fciphers\u002Fatbash","2.ciphers\u002F05.atbash",{"title":64,"path":65,"stem":66},"Affine","\u002Fciphers\u002Faffine","2.ciphers\u002F06.affine",{"title":68,"path":69,"stem":70},"Substitution","\u002Fciphers\u002Fsubstitution","2.ciphers\u002F07.substitution",{"title":72,"path":73,"stem":74},"Vigenère","\u002Fciphers\u002Fvigenere","2.ciphers\u002F08.vigenere",{"title":76,"path":77,"stem":78},"Gronsfeld","\u002Fciphers\u002Fgronsfeld","2.ciphers\u002F09.gronsfeld",{"title":80,"path":81,"stem":82},"Beaufort","\u002Fciphers\u002Fbeaufort","2.ciphers\u002F10.beaufort",{"title":84,"path":85,"stem":86},"Porta","\u002Fciphers\u002Fporta","2.ciphers\u002F11.porta",{"title":88,"path":89,"stem":90},"Autokey","\u002Fciphers\u002Fautokey","2.ciphers\u002F12.autokey",{"title":92,"path":93,"stem":94},"Running key","\u002Fciphers\u002Frunning-key","2.ciphers\u002F13.running-key",{"title":96,"path":97,"stem":98},"Trithemius","\u002Fciphers\u002Ftrithemius","2.ciphers\u002F14.trithemius",{"title":100,"path":101,"stem":102},"Alberti","\u002Fciphers\u002Falberti","2.ciphers\u002F15.alberti",{"title":104,"path":105,"stem":106},"Playfair","\u002Fciphers\u002Fplayfair","2.ciphers\u002F16.playfair",{"title":108,"path":109,"stem":110},"Four-square","\u002Fciphers\u002Ffour-square","2.ciphers\u002F17.four-square",{"title":112,"path":113,"stem":114},"Hill","\u002Fciphers\u002Fhill","2.ciphers\u002F18.hill",{"title":116,"path":117,"stem":118},"Polybius square","\u002Fciphers\u002Fpolybius","2.ciphers\u002F19.polybius",{"title":120,"path":121,"stem":122},"Nihilist","\u002Fciphers\u002Fnihilist","2.ciphers\u002F20.nihilist",{"title":124,"path":125,"stem":126},"Morse code","\u002Fciphers\u002Fmorse","2.ciphers\u002F21.morse",{"title":128,"path":129,"stem":130},"Bacon's cipher","\u002Fciphers\u002Fbacon","2.ciphers\u002F22.bacon",{"title":132,"path":133,"stem":134},"Tap code","\u002Fciphers\u002Ftap-code","2.ciphers\u002F23.tap-code",{"title":136,"path":137,"stem":138},"A1Z26","\u002Fciphers\u002Fa1z26","2.ciphers\u002F24.a1z26",{"title":140,"path":141,"stem":142},"Book cipher","\u002Fciphers\u002Fbook","2.ciphers\u002F25.book",{"title":144,"path":145,"stem":146},"ADFGVX","\u002Fciphers\u002Fadfgvx","2.ciphers\u002F26.adfgvx",{"title":148,"path":149,"stem":150},"Bifid","\u002Fciphers\u002Fbifid","2.ciphers\u002F27.bifid",{"title":152,"path":153,"stem":154},"Straddling checkerboard","\u002Fciphers\u002Fstraddling-checkerboard","2.ciphers\u002F28.straddling-checkerboard",{"title":156,"path":157,"stem":158},"Rail fence","\u002Fciphers\u002Frail-fence","2.ciphers\u002F29.rail-fence",{"title":160,"path":161,"stem":162},"Columnar transposition","\u002Fciphers\u002Fcolumnar","2.ciphers\u002F30.columnar",{"title":164,"path":165,"stem":166},"Route transposition","\u002Fciphers\u002Froute","2.ciphers\u002F31.route",{"title":168,"path":169,"stem":170},"Enigma M3","\u002Fciphers\u002Fenigma","2.ciphers\u002F32.enigma",{"title":172,"path":173,"stem":174},"Block","\u002Fciphers\u002Fblock","2.ciphers\u002F33.block",{"title":176,"path":177,"stem":178},"AES (ECB)","\u002Fciphers\u002Faes","2.ciphers\u002F34.aes",{"title":180,"path":181,"stem":182},"AES (CBC)","\u002Fciphers\u002Faes-cbc","2.ciphers\u002F35.aes-cbc",{"title":184,"path":185,"stem":186},"AES (CFB)","\u002Fciphers\u002Faes-cfb","2.ciphers\u002F36.aes-cfb",{"title":188,"path":189,"stem":190},"AES (OFB)","\u002Fciphers\u002Faes-ofb","2.ciphers\u002F37.aes-ofb",{"title":192,"path":193,"stem":194},"AES (CTR)","\u002Fciphers\u002Faes-ctr","2.ciphers\u002F38.aes-ctr",{"title":196,"path":197,"stem":198},"AES (CCM)","\u002Fciphers\u002Faes-ccm","2.ciphers\u002F39.aes-ccm",{"title":200,"path":201,"stem":202},"AES (OCB)","\u002Fciphers\u002Faes-ocb","2.ciphers\u002F40.aes-ocb",{"title":204,"path":205,"stem":206},"AES (LRW)","\u002Fciphers\u002Faes-lrw","2.ciphers\u002F41.aes-lrw",{"title":208,"path":209,"stem":210},"AES (XTS)","\u002Fciphers\u002Faes-xts","2.ciphers\u002F42.aes-xts",{"title":212,"path":213,"stem":214},"AES (CBC-MAC)","\u002Fciphers\u002Faes-cbc-mac","2.ciphers\u002F43.aes-cbc-mac",{"title":216,"path":217,"stem":218},"AES (passphrase)","\u002Fciphers\u002Faes-passphrase","2.ciphers\u002F44.aes-passphrase",{"title":220,"path":221,"stem":222},"Rijndael (ECB)","\u002Fciphers\u002Frijndael","2.ciphers\u002F45.rijndael",{"title":224,"path":225,"stem":226},"DES (ECB)","\u002Fciphers\u002Fdes","2.ciphers\u002F46.des",{"title":228,"path":229,"stem":230},"DESX (ECB)","\u002Fciphers\u002Fdesx","2.ciphers\u002F47.desx",{"title":232,"path":233,"stem":234},"Triple DES (ECB)","\u002Fciphers\u002Ftriple-des","2.ciphers\u002F48.triple-des",{"title":236,"path":237,"stem":238},"Triple DES (CBC)","\u002Fciphers\u002Ftriple-des-cbc","2.ciphers\u002F49.triple-des-cbc",{"title":240,"path":241,"stem":242},"Blowfish (ECB)","\u002Fciphers\u002Fblowfish","2.ciphers\u002F50.blowfish",{"title":244,"path":245,"stem":246},"IDEA (ECB)","\u002Fciphers\u002Fidea","2.ciphers\u002F51.idea",{"title":248,"path":249,"stem":250},"Lucifer (ECB)","\u002Fciphers\u002Flucifer","2.ciphers\u002F52.lucifer",{"title":252,"path":253,"stem":254},"MARS (ECB)","\u002Fciphers\u002Fmars","2.ciphers\u002F53.mars",{"title":256,"path":257,"stem":258},"Serpent (ECB)","\u002Fciphers\u002Fserpent","2.ciphers\u002F54.serpent",{"title":260,"path":261,"stem":262},"CAST5 (ECB)","\u002Fciphers\u002Fcast5","2.ciphers\u002F55.cast5",{"title":264,"path":265,"stem":266},"OpenPGP (passphrase)","\u002Fciphers\u002Fopenpgp","2.ciphers\u002F56.openpgp",{"title":268,"path":269,"stem":270},"Stream","\u002Fciphers\u002Fstream","2.ciphers\u002F57.stream",{"title":272,"path":273,"stem":274},"Rabbit","\u002Fciphers\u002Frabbit","2.ciphers\u002F58.rabbit",{"title":276,"path":277,"stem":278},"RC4","\u002Fciphers\u002Frc4","2.ciphers\u002F59.rc4",{"title":280,"path":281,"stem":282},"XOR","\u002Fciphers\u002Fxor","2.ciphers\u002F60.xor",{"title":284,"path":285,"stem":286},"Salsa20","\u002Fciphers\u002Fsalsa20","2.ciphers\u002F61.salsa20",{"title":288,"path":289,"stem":290},"XSalsa20","\u002Fciphers\u002Fxsalsa20","2.ciphers\u002F62.xsalsa20",{"title":292,"path":293,"stem":294},"ChaCha20","\u002Fciphers\u002Fchacha20","2.ciphers\u002F63.chacha20",{"title":296,"path":297,"stem":298},"XChaCha20","\u002Fciphers\u002Fxchacha20","2.ciphers\u002F64.xchacha20",{"title":300,"path":301,"stem":302},"ChaCha20-Poly1305","\u002Fciphers\u002Fchacha20-poly1305","2.ciphers\u002F65.chacha20-poly1305","i-lucide-library",{"id":305,"title":108,"body":306,"description":670,"extension":671,"links":672,"meta":673,"navigation":674,"path":109,"seo":675,"stem":110,"__hash__":676},"docs\u002F2.ciphers\u002F17.four-square.md",{"type":307,"value":308,"toc":664},"minimark",[309,313,317,421,432,437,455,466,470,489,565,571,585,589,600,624,634,638,650,660],[310,311],"cipher-facts",{"name":312},"four-square",[314,315,316],"p",{},"Félix Delastelle published this one in 1902. Four 5×5 squares sit in one big square. Top left and bottom right hold the plain alphabet. The other two are keyed. Find the first letter of a pair top left, the second bottom right. The other two corners of that rectangle are the ciphertext. Twice Playfair's keys, and one rule instead of three.",[318,319,324],"pre",{"className":320,"code":321,"language":322,"meta":323,"style":323},"language-ts shiki shiki-themes ciphers ciphers ciphers","const fourSquare = create(\"four-square\");\nconst squares = { key: \"zgptfoihmuwdrcnykeqaxvsbl\", secondKey: \"mfnbdcrhsaxyogvituewlqzkp\" };\nfourSquare.encode(\"attack at dawn\", squares).text; \u002F\u002F \"TIYBFHTIZBSY\"\nfourSquare.decode(\"TIYBFHTIZBSY\", squares).text; \u002F\u002F \"ATTACKATDAWN\"\n","ts","",[325,326,327,357,382,403],"code",{"__ignoreMap":323},[328,329,332,336,340,343,347,350,354],"span",{"class":330,"line":331},"line",1,[328,333,335],{"class":334},"skH_V","const",[328,337,339],{"class":338},"s38Sx"," fourSquare ",[328,341,342],{"class":334},"=",[328,344,346],{"class":345},"sK71F"," create",[328,348,349],{"class":338},"(",[328,351,353],{"class":352},"shU9J","\"four-square\"",[328,355,356],{"class":338},");\n",[328,358,360,362,365,367,370,373,376,379],{"class":330,"line":359},2,[328,361,335],{"class":334},[328,363,364],{"class":338}," squares ",[328,366,342],{"class":334},[328,368,369],{"class":338}," { key: ",[328,371,372],{"class":352},"\"zgptfoihmuwdrcnykeqaxvsbl\"",[328,374,375],{"class":338},", secondKey: ",[328,377,378],{"class":352},"\"mfnbdcrhsaxyogvituewlqzkp\"",[328,380,381],{"class":338}," };\n",[328,383,385,388,391,393,396,399],{"class":330,"line":384},3,[328,386,387],{"class":338},"fourSquare.",[328,389,390],{"class":345},"encode",[328,392,349],{"class":338},[328,394,395],{"class":352},"\"attack at dawn\"",[328,397,398],{"class":338},", squares).text; ",[328,400,402],{"class":401},"scIB-","\u002F\u002F \"TIYBFHTIZBSY\"\n",[328,404,406,408,411,413,416,418],{"class":330,"line":405},4,[328,407,387],{"class":338},[328,409,410],{"class":345},"decode",[328,412,349],{"class":338},[328,414,415],{"class":352},"\"TIYBFHTIZBSY\"",[328,417,398],{"class":338},[328,419,420],{"class":401},"\u002F\u002F \"ATTACKATDAWN\"\n",[314,422,423,424,431],{},"That's the ",[425,426,430],"a",{"href":427,"rel":428},"http:\u002F\u002Fpracticalcryptography.com\u002Fciphers\u002Fclassical-era\u002Ffour-square\u002F",[429],"nofollow","example on Practical Cryptography",". Its keys are whole squares, 25 letters each. A short keyword works too.",[433,434,436],"h2",{"id":435},"two-keys","Two keys",[314,438,439,442,443,446,447,450,451,454],{},[325,440,441],{},"key"," fills the square at the top right, the one that gives the first letter of each pair. ",[325,444,445],{},"secondKey"," fills the bottom left. Both build like Playfair's table: the keyword's letters, repeats dropped, then the rest of the alphabet. Both are required. A missing one is a ",[325,448,449],{},"MissingOptionError",", one without a single ASCII letter an ",[325,452,453],{},"InvalidOptionError",".",[314,456,457,458,461,462,465],{},"Same keyword twice? Allowed. But then ",[325,459,460],{},"AB"," and ",[325,463,464],{},"BA"," come out as mirror images, just like in Playfair. That's the one tell four-square was supposed to hide.",[433,467,469],{"id":468},"j-or-q","J or Q?",[314,471,472,473,475,476,461,479,481,482,461,485,488],{},"25 cells, 26 letters. Something has to go. By default J folds into I, as in ",[425,474,104],{"href":105},", ",[425,477,478],{"href":117},"Polybius",[425,480,148],{"href":149},". Wikipedia drops Q instead. Feed its ",[325,483,484],{},"EXAMPLE",[325,486,487],{},"KEYWORD"," example to the default squares and it agrees on the first pair, then wanders off:",[318,490,492],{"className":320,"code":491,"language":322,"meta":323,"style":323},"const keys = { key: \"EXAMPLE\", secondKey: \"KEYWORD\" };\nfourSquare.encode(\"help me obi wan kenobi\", keys).text;\n\u002F\u002F \"FYNFNEHWBXAFFOKHMD\"\nfourSquare.encode(\"help me obi wan kenobi\", { ...keys, omit: \"q\" }).text;\n\u002F\u002F \"FYGMKYHOBXMFKKKIMD\", Wikipedia's ciphertext\n",[325,493,494,515,529,534,559],{"__ignoreMap":323},[328,495,496,498,501,503,505,508,510,513],{"class":330,"line":331},[328,497,335],{"class":334},[328,499,500],{"class":338}," keys ",[328,502,342],{"class":334},[328,504,369],{"class":338},[328,506,507],{"class":352},"\"EXAMPLE\"",[328,509,375],{"class":338},[328,511,512],{"class":352},"\"KEYWORD\"",[328,514,381],{"class":338},[328,516,517,519,521,523,526],{"class":330,"line":359},[328,518,387],{"class":338},[328,520,390],{"class":345},[328,522,349],{"class":338},[328,524,525],{"class":352},"\"help me obi wan kenobi\"",[328,527,528],{"class":338},", keys).text;\n",[328,530,531],{"class":330,"line":384},[328,532,533],{"class":401},"\u002F\u002F \"FYNFNEHWBXAFFOKHMD\"\n",[328,535,536,538,540,542,544,547,550,553,556],{"class":330,"line":405},[328,537,387],{"class":338},[328,539,390],{"class":345},[328,541,349],{"class":338},[328,543,525],{"class":352},[328,545,546],{"class":338},", { ",[328,548,549],{"class":334},"...",[328,551,552],{"class":338},"keys, omit: ",[328,554,555],{"class":352},"\"q\"",[328,557,558],{"class":338}," }).text;\n",[328,560,562],{"class":330,"line":561},5,[328,563,564],{"class":401},"\u002F\u002F \"FYGMKYHOBXMFKKKIMD\", Wikipedia's ciphertext\n",[314,566,567,570],{},[325,568,569],{},"omit: \"q\""," builds all four squares without Q. J gets its own cell back, and a Q in the text or the keywords simply drops out. Q barely pulls its weight in English anyway. Mostly it just drags a U around. Neither choice is wrong. Different squares, different ciphertext.",[314,572,573,574,577,578,580,581,584],{},"Got a four-square that decodes into mush? Flip ",[325,575,576],{},"omit"," before you blame the keys. The result options carry ",[325,579,576],{}," only when it's ",[325,582,583],{},"q",", so a default call reports the two keys and nothing else.",[433,586,588],{"id":587},"no-x-between-doubles","No X between doubles",[314,590,591,592,595,596,599],{},"The text loses everything but letters and comes out in capitals. An odd length gets an X at the end, and that's the only X. Playfair has to split the ",[325,593,594],{},"LL"," in ",[325,597,598],{},"WALL",". Four-square doesn't, because the two letters sit in different squares:",[318,601,603],{"className":320,"code":602,"language":322,"meta":323,"style":323},"fourSquare.encode(\"defend the east wall of the castle\", squares).text;\n\u002F\u002F \"FBUMCNESFDPIKKZXCXMIUNZNQUNM\"\n",[325,604,605,619],{"__ignoreMap":323},[328,606,607,609,611,613,616],{"class":330,"line":331},[328,608,387],{"class":338},[328,610,390],{"class":345},[328,612,349],{"class":338},[328,614,615],{"class":352},"\"defend the east wall of the castle\"",[328,617,618],{"class":338},", squares).text;\n",[328,620,621],{"class":330,"line":359},[328,622,623],{"class":401},"\u002F\u002F \"FBUMCNESFDPIKKZXCXMIUNZNQUNM\"\n",[314,625,626,627,630,631,454],{},"See the ",[325,628,629],{},"KK","? Playfair never writes a pair like that. Decoding keeps the padding X, since only the sender knows it was padding. Ciphertext with an odd number of letters is a ",[325,632,633],{},"CipherError",[433,635,637],{"id":636},"spotting-one","Spotting one",[314,639,640,641,646,647,649],{},"No J, an even count, letters only. So far it looks like Playfair. Then a doubled pair shows up and Playfair is out. ",[425,642,643],{"href":17},[325,644,645],{},"guess"," names four-square on that. Bifid leaves the same traces, so the two come back side by side, bifid first. Squares without Q put J back into the ciphertext, and ",[325,648,645],{}," doesn't look for that one yet.",[314,651,652,653,461,656,659],{},"Want to settle it by hand? Count the pairs at even positions. A four-square keeps the plaintext's ",[325,654,655],{},"TH",[325,657,658],{},"HE",", only renamed, so the same pairs keep coming back. Bifid stirs its letters across five at a time and loses them.",[661,662,663],"style",{},"html pre.shiki code .skH_V, html code.shiki .skH_V{--shiki-light:var(--shiki-token-keyword);--shiki-default:var(--shiki-token-keyword);--shiki-dark:var(--shiki-token-keyword)}html pre.shiki code .s38Sx, html code.shiki .s38Sx{--shiki-light:var(--ui-text-highlighted);--shiki-default:var(--ui-text-highlighted);--shiki-dark:var(--ui-text-highlighted)}html pre.shiki code .sK71F, html code.shiki .sK71F{--shiki-light:var(--shiki-token-function);--shiki-default:var(--shiki-token-function);--shiki-dark:var(--shiki-token-function)}html pre.shiki code .shU9J, html code.shiki .shU9J{--shiki-light:var(--shiki-token-string);--shiki-default:var(--shiki-token-string);--shiki-dark:var(--shiki-token-string)}html pre.shiki code .scIB-, html code.shiki .scIB-{--shiki-light:var(--shiki-token-comment);--shiki-default:var(--shiki-token-comment);--shiki-dark:var(--shiki-token-comment)}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":323,"searchDepth":359,"depth":359,"links":665},[666,667,668,669],{"id":435,"depth":359,"text":436},{"id":468,"depth":359,"text":469},{"id":587,"depth":359,"text":588},{"id":636,"depth":359,"text":637},"Delastelle's four 5×5 squares, two plain and two keyed. Letter pairs go across the corners, and doubled letters come out the other side.","md",null,{},true,{"title":108,"description":670},"TqxTmJEZ_j4GZdDni6LUWsH9jXymXRE3YM8N2WqU8iY",[678,680],{"title":104,"path":105,"stem":106,"description":679,"children":-1},"Letter pairs through a keyed 5×5 table. J folds into I, doubled pairs are split with X, odd length is padded with X.",{"title":112,"path":113,"stem":114,"description":681,"children":-1},"Blocks of two or three letters go through a key matrix mod 26. Linear algebra in a puzzle. Nobody asked for it.",1791461058455]