[{"data":1,"prerenderedAt":509},["ShallowReactive",2],{"navigation_docs":3,"-ciphers-aes-lrw":156,"-ciphers-aes-lrw-surround":504},[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-solar-book-2-linear",{"title":37,"path":38,"stem":39,"children":40,"icon":155},"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],{"title":42,"path":38,"stem":39},"Overview",{"title":44,"path":45,"stem":46},"Caesar","\u002Fciphers\u002Fcaesar","2.ciphers\u002F01.caesar",{"title":48,"path":49,"stem":50},"ROT-13","\u002Fciphers\u002Frot13","2.ciphers\u002F02.rot13",{"title":52,"path":53,"stem":54},"ROT-47","\u002Fciphers\u002Frot47","2.ciphers\u002F03.rot47",{"title":56,"path":57,"stem":58},"Atbash","\u002Fciphers\u002Fatbash","2.ciphers\u002F04.atbash",{"title":60,"path":61,"stem":62},"Affine","\u002Fciphers\u002Faffine","2.ciphers\u002F05.affine",{"title":64,"path":65,"stem":66},"Vigenère","\u002Fciphers\u002Fvigenere","2.ciphers\u002F06.vigenere",{"title":68,"path":69,"stem":70},"Trithemius","\u002Fciphers\u002Ftrithemius","2.ciphers\u002F07.trithemius",{"title":72,"path":73,"stem":74},"Alberti","\u002Fciphers\u002Falberti","2.ciphers\u002F08.alberti",{"title":76,"path":77,"stem":78},"Playfair","\u002Fciphers\u002Fplayfair","2.ciphers\u002F09.playfair",{"title":80,"path":81,"stem":82},"Polybius square","\u002Fciphers\u002Fpolybius","2.ciphers\u002F10.polybius",{"title":84,"path":85,"stem":86},"Morse code","\u002Fciphers\u002Fmorse","2.ciphers\u002F11.morse",{"title":88,"path":89,"stem":90},"Bacon's cipher","\u002Fciphers\u002Fbacon","2.ciphers\u002F12.bacon",{"title":92,"path":93,"stem":94},"Tap code","\u002Fciphers\u002Ftap-code","2.ciphers\u002F13.tap-code",{"title":96,"path":97,"stem":98},"ADFGVX","\u002Fciphers\u002Fadfgvx","2.ciphers\u002F14.adfgvx",{"title":100,"path":101,"stem":102},"Bifid","\u002Fciphers\u002Fbifid","2.ciphers\u002F15.bifid",{"title":104,"path":105,"stem":106},"Rail fence","\u002Fciphers\u002Frail-fence","2.ciphers\u002F16.rail-fence",{"title":108,"path":109,"stem":110},"Columnar transposition","\u002Fciphers\u002Fcolumnar","2.ciphers\u002F17.columnar",{"title":112,"path":113,"stem":114},"Enigma M3","\u002Fciphers\u002Fenigma","2.ciphers\u002F18.enigma",{"title":116,"path":117,"stem":118},"Beaufort","\u002Fciphers\u002Fbeaufort","2.ciphers\u002F19.beaufort",{"title":120,"path":121,"stem":122},"Autokey","\u002Fciphers\u002Fautokey","2.ciphers\u002F20.autokey",{"title":124,"path":125,"stem":126},"AES (ECB)","\u002Fciphers\u002Faes","2.ciphers\u002F21.aes",{"title":128,"path":129,"stem":130},"Triple DES (ECB)","\u002Fciphers\u002Ftriple-des","2.ciphers\u002F22.triple-des",{"title":132,"path":133,"stem":134},"AES (LRW)","\u002Fciphers\u002Faes-lrw","2.ciphers\u002F23.aes-lrw",{"title":136,"path":137,"stem":138},"AES (CBC)","\u002Fciphers\u002Faes-cbc","2.ciphers\u002F24.aes-cbc",{"title":140,"path":141,"stem":142},"AES (CFB)","\u002Fciphers\u002Faes-cfb","2.ciphers\u002F25.aes-cfb",{"title":144,"path":145,"stem":146},"AES (CTR)","\u002Fciphers\u002Faes-ctr","2.ciphers\u002F26.aes-ctr",{"title":148,"path":149,"stem":150},"AES (CCM)","\u002Fciphers\u002Faes-ccm","2.ciphers\u002F27.aes-ccm",{"title":152,"path":153,"stem":154},"AES (OFB)","\u002Fciphers\u002Faes-ofb","2.ciphers\u002F28.aes-ofb","i-solar-library-linear",{"id":157,"title":132,"body":158,"description":497,"extension":498,"links":499,"meta":500,"navigation":501,"path":133,"seo":502,"stem":134,"__hash__":503},"docs\u002F2.ciphers\u002F23.aes-lrw.md",{"type":159,"value":160,"toc":494},"minimark",[161,165,190,209,393,403,408,415,463,466,487,490],[162,163],"cipher-facts",{"name":164},"aes-lrw",[166,167,168,169,173,174,178,179,182,183,186,187,189],"p",{},"LRW is Liskov, Rivest and Wagner, the tweakable mode the IEEE P1619 drafts picked for disk sectors. It's ",[170,171,172],"a",{"href":125},"AES"," with one extra step around every block. Block number ",[175,176,177],"code",{},"i"," gets a mask ",[175,180,181],{},"T = K2 ⊗ i",", a multiplication in GF(2^128). The block is XORed with ",[175,184,185],{},"T",", encrypted, and XORed with ",[175,188,185],{}," again. Same AES key, but a different mask at every position.",[166,191,192,193,196,197,200,201,204,205,208],{},"The key is hex and carries both parts. First the AES key, 32, 48 or 64 digits, then 32 more digits for the tweak key K2. So 64, 80 or 96 digits in total, the same layout Linux uses for ",[175,194,195],{},"lrw(aes)",". ",[175,198,199],{},"tweak"," is the index of the first block, up to 32 hex digits, default 1. The next block is one more, and after ",[175,202,203],{},"ff…ff"," it wraps to 0. Text and ciphertext work as in AES: UTF-8 with PKCS#7 padding in, lowercase hex out, and ",[175,206,207],{},"decode"," wants hex back.",[210,211,216],"pre",{"className":212,"code":213,"language":214,"meta":215,"style":215},"language-ts shiki shiki-themes github-light github-light poimandres","const lrw = create(\"aes-lrw\");\nconst key = \"4562ac25f828176d4c268414b5680185258e2a05e73e9d03ee5a830ccc094c87\";\nlrw.encode(\"ATTACK AT DAWN\", { key }).text; \u002F\u002F \"1b3e1004e52c450fda5b2bca03bca338\"\nlrw.encode(\"ATTACK AT DAWN\", { key, tweak: \"200000000\" }).text; \u002F\u002F \"f319a072c39498a1e0c6c8213de2facc\"\nlrw.decode(\"1b3e1004e52c450fda5b2bca03bca338\", { key }).text; \u002F\u002F \"ATTACK AT DAWN\"\n","ts","",[175,217,218,254,275,315,362],{"__ignoreMap":215},[219,220,223,227,231,234,238,242,246,249,251],"span",{"class":221,"line":222},"line",1,[219,224,226],{"class":225},"s1TYA","const",[219,228,230],{"class":229},"saoiD"," lrw",[219,232,233],{"class":225}," =",[219,235,237],{"class":236},"sULi6"," create",[219,239,241],{"class":240},"sKlNE","(",[219,243,245],{"class":244},"scVjq","\"",[219,247,164],{"class":248},"sQ7BG",[219,250,245],{"class":244},[219,252,253],{"class":240},");\n",[219,255,257,259,262,264,267,270,272],{"class":221,"line":256},2,[219,258,226],{"class":225},[219,260,261],{"class":229}," key",[219,263,233],{"class":225},[219,265,266],{"class":244}," \"",[219,268,269],{"class":248},"4562ac25f828176d4c268414b5680185258e2a05e73e9d03ee5a830ccc094c87",[219,271,245],{"class":244},[219,273,274],{"class":240},";\n",[219,276,278,282,285,288,290,292,295,297,300,302,305,308,311],{"class":221,"line":277},3,[219,279,281],{"class":280},"spVlQ","lrw",[219,283,284],{"class":240},".",[219,286,287],{"class":236},"encode",[219,289,241],{"class":240},[219,291,245],{"class":244},[219,293,294],{"class":248},"ATTACK AT DAWN",[219,296,245],{"class":244},[219,298,299],{"class":240},", {",[219,301,261],{"class":280},[219,303,304],{"class":240}," }).",[219,306,307],{"class":280},"text",[219,309,310],{"class":240},"; ",[219,312,314],{"class":313},"sjhu3","\u002F\u002F \"1b3e1004e52c450fda5b2bca03bca338\"\n",[219,316,318,320,322,324,326,328,330,332,334,336,339,343,346,348,351,353,355,357,359],{"class":221,"line":317},4,[219,319,281],{"class":280},[219,321,284],{"class":240},[219,323,287],{"class":236},[219,325,241],{"class":240},[219,327,245],{"class":244},[219,329,294],{"class":248},[219,331,245],{"class":244},[219,333,299],{"class":240},[219,335,261],{"class":280},[219,337,338],{"class":240},",",[219,340,342],{"class":341},"snHMy"," tweak",[219,344,345],{"class":240},":",[219,347,266],{"class":244},[219,349,350],{"class":248},"200000000",[219,352,245],{"class":244},[219,354,304],{"class":240},[219,356,307],{"class":280},[219,358,310],{"class":240},[219,360,361],{"class":313},"\u002F\u002F \"f319a072c39498a1e0c6c8213de2facc\"\n",[219,363,365,367,369,371,373,375,378,380,382,384,386,388,390],{"class":221,"line":364},5,[219,366,281],{"class":280},[219,368,284],{"class":240},[219,370,207],{"class":236},[219,372,241],{"class":240},[219,374,245],{"class":244},[219,376,377],{"class":248},"1b3e1004e52c450fda5b2bca03bca338",[219,379,245],{"class":244},[219,381,299],{"class":240},[219,383,261],{"class":280},[219,385,304],{"class":240},[219,387,307],{"class":280},[219,389,310],{"class":240},[219,391,392],{"class":313},"\u002F\u002F \"ATTACK AT DAWN\"\n",[166,394,395,396,398,399,402],{},"OpenSSL has no LRW, so these bytes come from the Linux kernel's own ",[175,397,195],{}," through AF_ALG, with the padding added before it. The block function is tested against the IEEE P1619 LRW-AES vectors that the kernel's ",[175,400,401],{},"testmgr.h"," carries, the counter wrap at 2^128 included.",[404,405,407],"h2",{"id":406},"what-the-tweak-fixes","What the tweak fixes",[166,409,410,411,414],{},"Thirty-two ",[175,412,413],{},"A","s again, two equal blocks of plaintext. In ECB that's two equal blocks of ciphertext. Here:",[210,416,418],{"className":212,"code":417,"language":214,"meta":215,"style":215},"lrw.encode(\"A\".repeat(32), { key }).text;\n\u002F\u002F 709a0bafa03db466980baedc25c44ea7 c622af990436ec152db2ae69dc4d779d 52b4776b71f7dd0556849ba9297439ac\n",[175,419,420,458],{"__ignoreMap":215},[219,421,422,424,426,428,430,432,434,436,438,441,443,447,450,452,454,456],{"class":221,"line":222},[219,423,281],{"class":280},[219,425,284],{"class":240},[219,427,287],{"class":236},[219,429,241],{"class":240},[219,431,245],{"class":244},[219,433,413],{"class":248},[219,435,245],{"class":244},[219,437,284],{"class":240},[219,439,440],{"class":236},"repeat",[219,442,241],{"class":240},[219,444,446],{"class":445},"siHFe","32",[219,448,449],{"class":240},"), {",[219,451,261],{"class":280},[219,453,304],{"class":240},[219,455,307],{"class":280},[219,457,274],{"class":240},[219,459,460],{"class":221,"line":256},[219,461,462],{"class":313},"\u002F\u002F 709a0bafa03db466980baedc25c44ea7 c622af990436ec152db2ae69dc4d779d 52b4776b71f7dd0556849ba9297439ac\n",[166,464,465],{},"Spaces added here to show the blocks. Nothing repeats, because block 1 and block 2 got different masks. But move the same plaintext block to the same position under the same key and the ciphertext is the same again. That's by design, a disk sector encrypts the same way every time it's written. LRW hides which blocks repeat inside a message, not whether a message changed.",[166,467,468,469,472,473,475,476,479,480,482,483,486],{},"A key that isn't 64, 80 or 96 hex digits is an ",[175,470,471],{},"InvalidOptionError",", and so is a ",[175,474,199],{}," that isn't 1 to 32 hex digits. A missing key is a ",[175,477,478],{},"MissingOptionError",". On ",[175,481,207],{},", hex that isn't whole 16-byte blocks is a ",[175,484,485],{},"CipherError",". So is a wrong key or a wrong tweak, since the padding almost never survives either.",[166,488,489],{},"IEEE dropped LRW from the final P1619 and went with XTS. LRW breaks when the tweak key ends up encrypted under itself, which is easy to do on a disk. It also has no integrity check, so flipped bits decrypt to garbage without a word. Same as the ECB ciphers, this is plain TypeScript, not constant time, for puzzles and for seeing what a tweak does. Don't protect anything real with it.",[491,492,493],"style",{},"html pre.shiki code .s1TYA, html code.shiki .s1TYA{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#91B4D5}html pre.shiki code .saoiD, html code.shiki .saoiD{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#E4F0FB}html pre.shiki code .sULi6, html code.shiki .sULi6{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#E4F0FBD0}html pre.shiki code .sKlNE, html code.shiki .sKlNE{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#A6ACCD}html pre.shiki code .scVjq, html code.shiki .scVjq{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#A6ACCD}html pre.shiki code .sQ7BG, html code.shiki .sQ7BG{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#5DE4C7}html pre.shiki code .spVlQ, html code.shiki .spVlQ{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#E4F0FB}html pre.shiki code .sjhu3, html code.shiki .sjhu3{--shiki-light:#6A737D;--shiki-light-font-style:inherit;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#767C9DB0;--shiki-dark-font-style:italic}html pre.shiki code .snHMy, html code.shiki .snHMy{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#ADD7FF}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);}html pre.shiki code .siHFe, html code.shiki .siHFe{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#5DE4C7}",{"title":215,"searchDepth":256,"depth":256,"links":495},[496],{"id":406,"depth":256,"text":407},"AES with a tweak. Every 16-byte block is masked by its own position, so equal blocks stop looking equal. UTF-8 text in, hex out.","md",null,{},true,{"title":132,"description":497},"hhRNdZaWBJJv__z6S7zme_oOLpxuBvjZO87hwCH7HYw",[505,507],{"title":128,"path":129,"stem":130,"description":506,"children":-1},"DES three times, encrypt, decrypt and encrypt again. UTF-8 text in, hex out, and every 8-byte block encrypted on its own.",{"title":136,"path":137,"stem":138,"description":508,"children":-1},"AES with the blocks chained. Every 16-byte block is mixed with the ciphertext before it, so equal blocks stop looking equal. UTF-8 text in, hex out.",1790272611310]