Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/AES+CTR?V=1
QUERY_STRINGV=1
CONTENT_TYPE
DOCUMENT_URI/revision/AES+CTR
DOCUMENT_ROOT/var/www/nikit/nikit/nginx/../docroot
SCGI1
SERVER_PROTOCOLHTTP/1.1
HTTPSon
REMOTE_ADDR172.70.38.52
REMOTE_PORT25118
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip, br
HTTP_X_FORWARDED_FOR3.85.211.2
HTTP_CF_RAY86bac87edb4d874c-IAD
HTTP_X_FORWARDED_PROTOhttps
HTTP_CF_VISITOR{"scheme":"https"}
HTTP_ACCEPT*/*
HTTP_USER_AGENTclaudebot
HTTP_CF_CONNECTING_IP3.85.211.2
HTTP_CDN_LOOPcloudflare
HTTP_CF_IPCOUNTRYUS

Body


Error

Unknow state transition: LINE -> END

-code

1

-level

0

-errorstack

INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit {AES CTR} Working\ on\ web\ programs\ I\ found\ a\ need\ to\ exchange\ encrypted\ content.\ \ On\ the\ browser\ side\ finding\ javascript\ crypto\ libraries\ wasn't\ difficult.\ \ After\ some\ experimenting,\ I\ settled\ on\ the\ AES-CTR\ \"reference\ implementation\"\ by\ Chris\ Veness.\ \ \[https://github.com/chrisveness/crypto\]\n\nThe\ server\ was\ harder.\ \ I'd\ written\ a\ server\ in\ Tcl,\ but\ there\ weren't\ any\ Tcl\ AES-CTR\ implementations\ to\ be\ found.\ \ The\ tcllib\ AES\ handles\ CBC\ but\ not\ CTR\ mode.\ \ After\ I\ modified\ it\ to\ do\ CTR,\ the\ tcllib\ code\ would\ encrypt/decrypt\ OK.\ \ Problem\ was\ it\ wouldn't\ work\ with\ text\ encrypted\ by\ the\ JS\ (or\ another)\ AES-CTR\ program.\n\nTherefore\ I\ was\ inspired\ to\ build\ a\ Tcl\ version\ that\ works\ with\ the\ javascript\ implementation\ I\ was\ using.\ \ The\ result\ was\ a\ Tcl\ AES-CTR\ implementation\ that\ decrypts\ text\ encrypted\ with\ JS\ in\ the\ browser\ and\ vice\ versa.\n\nPretty\ straightforward\ to\ use.\ Loading\ aes.js\ and\ aes-ctr.js\ in\ the\ web\ page\ allows\ access\ to\ the\ encrypt/decrypt\ functions.\ \ Sourcing\ aesctr.tcl\ in\ Tcl\ exposes\ similar\ encrypt\ and\ decrypt\ commands.\ \ \n\nIn\ Tcl,\ calling\ encrypt/decrypt:\n======\n\ \ encrypt\ \"This\ is\ text\ to\ be\ encrypted\"\ \"A\ password\"\ 256\ \n\ \ ==>\ 4ACtkN/r7lRmY/sfmtulg1KSGPu/0E0YSfYzBIIu0otrGOD5\n\n\ \ decrypt\ 4ACtkN/r7lRmY/sfmtulg1KSGPu/0E0YSfYzBIIu0otrGOD5\ \"A\ password\"\ 256\n\ \ ==>\ This\ is\ text\ to\ be\ encrypted\n======\n\nIn\ javascript:\n======\n\ \ AesCtr.decrypt(\"4ACtkN/r7lRmY/sfmtulg1KSGPu/0E0YSfYzBIIu0otrGOD5\",\ \"A\ password\",\ 256)\;\n\ \ ==>\ \"This\ is\ text\ to\ be\ encrypted\"\n\n\ \ AesCtr.encrypt(\"This\ is\ text\ to\ be\ encrypted\",\ \"A\ password\",\ 256)\;\n\ \ ==>\ \"4ACtkN/r7lRmY/sfmtulg1KSGPu/0E0YSfYzBIIu0otrGOD5\"\n======\n\nThe\ Tcl\ AES-CTR\ commands\ work\ correctly\ but\ no\ doubt\ could\ be\ better\ optimized.\ \ As\ an\ informal\ benchmark,\ on\ my\ Surface\ Pro\ 2,\ the\ Tcl\ encrypt\ example\ above\ runs\ in\ 8.80\ millisec.\ \ The\ decrypt\ command\ consumed\ 8.86\ millisec.\ \ I\ didn't\ test\ other\ implementations.\n\n======\n##\ aesctr.tcl\n\n##\ AES\ CTR\ in\ Tcl.\n##\ (C)\ 2015\ J.\ Altfas\n##\n##\ This\ Tcl\ implementation\ is\ intended\ to\ be\ compatible\ with\ the\ JS\n##\ version\ referenced\ below,\ that\ is,\ text\ encrypted\ using\ JS\ can\ be\n##\ decrypted\ in\ Tcl\ and\ vice\ versa.\ \ \n##\n##\ Usage:\ \n##\ \ \ \ \ \ encrypt\ <input\ text\ (string)>\ <password\ (string)>\ 128|192|256\n##\ \ \ \ \ \ decrypt\ <encryp\ msg\ (string)>\ <password\ (string)>\ 128|192|256\n##\ \n##\ Reference\ code:\ aes.js,\ aes-ctr.js\ \n##\ \ \ \"AES\ Counter-mode\ implementation\ in\ JavaScript\"\n##\ \ \ (c)\ Chris\ Veness\ 2005-2014\ /\ MIT\ Licence\n##\ \ \ https://github.com/chrisveness/crypto\n\nset\ sBox\ \{\n\ \ \ \ 0x63\ 0x7c\ 0x77\ 0x7b\ 0xf2\ 0x6b\ 0x6f\ 0xc5\ 0x30\ 0x01\ 0x67\ 0x2b\ 0xfe\ 0xd7\ 0xab\ 0x76\n\ \ \ \ 0xca\ 0x82\ 0xc9\ 0x7d\ 0xfa\ 0x59\ 0x47\ 0xf0\ 0xad\ 0xd4\ 0xa2\ 0xaf\ 0x9c\ 0xa4\ 0x72\ 0xc0\n\ \ \ \ 0xb7\ 0xfd\ 0x93\ 0x26\ 0x36\ 0x3f\ 0xf7\ 0xcc\ 0x34\ 0xa5\ 0xe5\ 0xf1\ 0x71\ 0xd8\ 0x31\ 0x15\n\ \ \ \ 0x04\ 0xc7\ 0x23\ 0xc3\ 0x18\ 0x96\ 0x05\ 0x9a\ 0x07\ 0x12\ 0x80\ 0xe2\ 0xeb\ 0x27\ 0xb2\ 0x75\n\ \ \ \ 0x09\ 0x83\ 0x2c\ 0x1a\ 0x1b\ 0x6e\ 0x5a\ 0xa0\ 0x52\ 0x3b\ 0xd6\ 0xb3\ 0x29\ 0xe3\ 0x2f\ 0x84\n\ \ \ \ 0x53\ 0xd1\ 0x00\ 0xed\ 0x20\ 0xfc\ 0xb1\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 \$Nr\}\ \{incr\ round\}\ \{\n\ \ \ \ \ \ \ \ set\ state\ \[subBytes\ \$state\ \$Nb\]\n\ \ \ \ \ \ \ \ set\ state\ \[shiftRows\ \$state\ \$Nb\]\n\ \ \ \ \ \ \ \ set\ state\ \[mixColumns\ \$state\ \$Nb\]\n\ \ \ \ \ \ \ \ set\ state\ \[addRoundKey\ \$state\ \$w\ \$round\ \$Nb\]\n\ \ \ \ \}\ \ \ \n\ \ \ \ set\ state\ \[subBytes\ \$state\ \$Nb\]\n\ \ \ \ set\ state\ \[shiftRows\ \$state\ \$Nb\]\n\ \ \ \ set\ state\ \[addRoundKey\ \$state\ \$w\ \$Nr\ \$Nb\]\n\ \ \ \ \n\ \ \ \ set\ output\ \[lrepeat\ \[*\ 4\ \$Nb\]\ 0\]\n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ \[*\ 4\ \$Nb\]\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ output\ \$i\ \[lindex\ \$state\ \[%\ \$i\ 4\]\ \[int\ \[floor\ \[/\ \$i\ 4.0\]\]\]\]\n\ \ \ \ \}\n\ \ \ \ return\ \$output\n\}\n\nproc\ keyExpansion\ \{key\}\ \{\n\ \ \ \ set\ Nb\ 4\n\ \ \ \ set\ Nk\ \[/\ \[llength\ \$key\]\ 4\]\ \;#\ 4,6,8\ for\ 128,192,256B\ key\n\ \ \ \ set\ Nr\ \[+\ \$Nk\ 6\]\ \ \n\ \ \ \ set\ w\ \[lrepeat\ \[*\ \$Nb\ \[+\ \$Nr\ 1\]\]\ 0\]\n\ \ \ \ set\ temp\ \[lrepeat\ 4\ 0\]\n\ \ \ \ \n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ \$Nk\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ set\ i4\ \[*\ \$i\ 4\]\n\ \ \ \ \ \ \ \ set\ r\ \[list\ \[lindex\ \$key\ \$i4\]\ \[lindex\ \$key\ \[+\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$a\ 2\]\ \[lindex\ \$b\ 3\]\ \]\n\ \ \ \ \}\n\ \ \ \ return\ \$s\n\}\n\n##\ state\ is\ list\ of\ 4\ lists\ of\ 4\ elem:\ \{\{r0c0\ r0c1\ ...\}\ \{r1c0\ ...\}\ ...\}\nproc\ addRoundKey\ \{state\ w\ rnd\ Nb\}\ \{\n\ \ \ \ for\ \{set\ r\ 0\}\ \{\$r\ <\ 4\}\ \{incr\ r\}\ \{\n\ \ \ \ \ \ \ \ for\ \{set\ c\ 0\}\ \{\$c\ <\ \$Nb\}\ \{incr\ c\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ ##\ state\[r\]\[c\]\ ^=\ w\[rnd*4+c\]\[r\]\n\ \ \ \ \ \ \ \ \ \ \ \ lset\ state\ \$r\ \$c\ \[^\ \[lindex\ \$state\ \$r\ \$c\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[lindex\ \$w\ \[+\ \[*\ \$rnd\ 4\]\ \$c\]\ \$r\]\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ return\ \$state\n\}\n\n#\ Apply\ SBox\ to\ 4-byte\ word\ w4\nproc\ subWord\ \{w4\}\ \{\n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 4\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ w4\ \$i\ \[lindex\ \$::sBox\ \[lindex\ \$w4\ \$i\]\]\;\n\ \ \ \ \}\n\ \ \ \ return\ \$w4\n\}\n\nproc\ rotWord\ \{w4\}\ \{\n\ \ \ \ set\ tmp\ \[lindex\ \$w4\ 0\]\n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 3\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ w4\ \$i\ \[lindex\ \$w4\ \[+\ \$i\ 1\]\]\n\ \ \ \ \}\n\ \ \ \ lset\ w4\ 3\ \$tmp\n\ \ \ \ return\ \$w4\n\}\n\nproc\ str->bytes\ \{str\ \{keysz\ 0\}\}\ \{\n\ \ \ \ set\ keysz\ \[expr\ \{!\$keysz\ ?\ \[string\ length\ \$str\]\ :\ \$keysz\}\]\ \n\ \ \ \ concat\ \[lmap\ c\ \[lrange\ \[split\ \$str\ \"\"\]\ 0\ \$keysz-1\]\ \{\n\ \ \ \ \ \ \ \ scan\ \$c\ %c\n\ \ \ \ \}\]\ \[expr\ \{\$keysz\ >\ \[string\ length\ \$str\]\ ?\n\ \ \ \ \ \ \ \ \ \ \ \[lrepeat\ \[-\ \$keysz\ \[string\ length\ \$str\]\]\ 0\]\ :\ \{\}\ \}\]\n\}\n\nproc\ encrypt\ \{plaintxt\ passwd\ nBits\}\ \{\n\ \ \ \ set\ blockSize\ 16\n\ \ \ \ if\ \{\[ni\ \$nBits\ \{128\ 192\ 256\}\]\}\ \{\n\ \ \ \ \ \ \ \ return\ \"\"\n\ \ \ \ \}\n\ \ \ \ set\ plain\ \[encoding\ convertto\ utf-8\ \$plaintxt\]\n\ \ \ \ set\ pw\ \[encoding\ convertto\ utf-8\ \$passwd\]\ \ \ \ \n\ \ \ \ set\ nBytes\ \[/\ \$nBits\ 8\]\n\ \ \ \ set\ pwBytes\ \[str->bytes\ \$pw\ \$nBytes\]\n\ \ \ \ \n\ \ \ \ set\ key\ \[cipher\ \$pwBytes\ \[keyExpansion\ \$pwBytes\]\]\n\ \ \ \ lappend\ key\ \{*\}\[lrange\ \$key\ 0\ \[-\ \$nBytes\ 16\]\]\n\ \ \ \ \n\ \ \ \ set\ counterBlock\ \[lrepeat\ \$blockSize\ 0\]\ \ \ \n\ \ \ \ set\ nonce\ \[clock\ milliseconds\]\n\ \ \ \ set\ nonceMs\ \[%\ \$nonce\ 1000\]\n\ \ \ \ set\ nonceSec\ \[int\ \[/\ \$nonce\ 1000\]\]\n\ \ \ \ set\ nonceRnd\ \[int\ \[*\ \[rand\]\ 0xffff\]\]\n\ \ \ \ \n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 2\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ counterBlock\ \$i\ \[&\ \[>>\ \$nonceMs\ \[*\ \$i\ 8\]\]\ 0xff\]\n\ \ \ \ \}\n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 2\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ counterBlock\ \[+\ \$i\ 2\]\ \[&\ \[>>\ \$nonceRnd\ \[*\ \$i\ 8\]\]\ 0xff\]\n\ \ \ \ \}\n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 4\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ counterBlock\ \[+\ \$i\ 4\]\ \[&\ \[>>\ \$nonceSec\ \[*\ \$i\ 8\]\]\ 0xff\]\n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ ##\ save\ 1st\ 8\ bytes\ of\ counterBlock\ as\ text--used\ in\ output\n\ \ \ \ set\ ctrTxt\ \[join\ \[lmap\ x\ \[lrange\ \$counterBlock\ 0\ 7\]\ \{\n\ \ \ \ \ \ \ \ format\ %c\ \$x\n\ \ \ \ \}\]\ \"\"\]\ \ \n\ \ \ \ set\ keySchedule\ \[keyExpansion\ \$key\]\ \ \ \ \n\ \ \ \ set\ blockCount\ \[int\ \[ceil\ \[/\ \[double\ \[string\ length\ \$plain\]\]\ \$blockSize\]\]\]\n\ \ \ \ set\ ciphertxt\ \[lrepeat\ \$blockCount\ 0\]\n\ \ \ \ \n\ \ \ \ for\ \{set\ b\ 0\}\ \{\$b\ <\ \$blockCount\}\ \{incr\ b\}\ \{\n\ \ \ \ \ \ \ \ for\ \{set\ c\ 0\}\ \{\$c\ <\ 4\}\ \{incr\ c\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lset\ counterBlock\ \[-\ 15\ \$c\]\ \[&\ \[>>\ \$b\ \[*\ \$c\ 8\]\]\ 0xff\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ for\ \{set\ c\ 0\}\ \{\$c\ <\ 4\}\ \{incr\ c\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lset\ counterBlock\ \[-\ 15\ \$c\ 4\]\ \[>>\ \[/\ \$b\ 0x100000000\]\ \[*\ \$c\ 8\]\]\n\ \ \ \ \ \ \ \ \}\ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ cipherCntr\ \[cipher\ \$counterBlock\ \$keySchedule\]\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ blockLength\ \[expr\ \{\$b\ <\ (\$blockCount\ -\ 1)\ ?\ \$blockSize\ -\ 1\ :\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ((\[string\ length\ \$plain\]\ -\ 1)\ %\ \$blockSize)\}\]\ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ st\ \[*\ \$b\ \$blockSize\]\ \;#\ start\ of\ plaintext\ segment\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ ##\ xor\ chars\ from\ plaintext\ segment\ and\ cipherCntr\ \ \n\ \ \ \ \ \ \ \ set\ cipherChar\ \[\n\ \ \ \ \ \ \ \ \ \ lmap\ p\ \[split\ \[string\ range\ \$plain\ \$st\ \$st+\$blockLength\]\ \"\"\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ciph\ \[lrange\ \$cipherCntr\ 0\ \$blockLength\]\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ format\ %c\ \[^\ \$ciph\ \[scan\ \$p\ %c\]\]\n\ \ \ \ \ \ \ \ \}\]\ \ \ \n\ \ \ \ \ \ \ \ lset\ ciphertxt\ \$b\ \[join\ \$cipherChar\ \"\"\]\n\ \ \ \ \}\ \ \ \n\ \ \ \ ##\ prepend\ saved\ counterBlock\ text,\ needed\ for\ decryption\n\ \ \ \ binary\ encode\ base64\ \[string\ cat\ \$ctrTxt\ \[join\ \$ciphertxt\ \"\"\]\]\n\}\n\ \ \ \ \ \ \ \ \ \ \nproc\ decrypt\ \{ciphertext\ passwd\ nBits\}\ \{\n\ \ \ \ set\ blockSize\ 16\n\ \ \ \ if\ \{\[ni\ \$nBits\ \{128\ 192\ 256\}\]\}\ \{\n\ \ \ \ \ \ \ \ return\ \"\"\n\ \ \ \ \}\ \ \ \n\ \ \ \ set\ ciphertext\ \[binary\ decode\ base64\ \$ciphertext\]\n\ \ \ \ set\ pw\ \[encoding\ convertto\ utf-8\ \$passwd\]\ \ \ \ \n\ \ \ \ set\ nBytes\ \[/\ \$nBits\ 8\]\n\ \ \ \ set\ pwBytes\ \[str->bytes\ \$pw\ \$nBytes\]\n\ \ \ \ \n\ \ \ \ set\ key\ \[cipher\ \$pwBytes\ \[keyExpansion\ \$pwBytes\]\]\n\ \ \ \ lappend\ key\ \{*\}\[lrange\ \$key\ 0\ \[-\ \$nBytes\ 16\]\]\n\ \ \ \ \n\ \ \ \ set\ ctrTxt\ \[string\ range\ \$ciphertext\ 0\ 8\]\n\ \ \ \ set\ counterBlock\ \[lrepeat\ 16\ 0\]\n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 8\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ counterBlock\ \$i\ \[scan\ \[string\ index\ \$ctrTxt\ \$i\]\ %c\]\n\ \ \ \ \}\ \n\ \ \ \ set\ keySchedule\ \[keyExpansion\ \$key\]\n\ \ \ \ \n\ \ \ \ ##\ re:\ ceil:\ using\ 8.0\ to\ make\ sure\ result\ is\ double\n\ \ \ \ set\ nBlocks\ \[int\ \[ceil\ \[/\ \[-\ \[string\ length\ \$ciphertext\]\ 8.0\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$blockSize\]\]\]\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \n\ \ \ \ set\ ct\ \[lrepeat\ \$nBlocks\ 0\]\n\ \ \ \ for\ \{set\ b\ 0\}\ \{\$b\ <\ \$nBlocks\}\ \{incr\ b\}\ \{\n\ \ \ \ \ \ \ \ set\ pos\ \[+\ 8\ \[*\ \$b\ \$blockSize\]\]\n\ \ \ \ \ \ \ \ lset\ ct\ \$b\ \[string\ range\ \$ciphertext\ \$pos\ \[+\ \$pos\ \$blockSize\ -1\]\]\n\ \ \ \ \}\ \ \ \ \n\ \ \ \ set\ ciphertext\ \$ct\n\ \ \ \ set\ plaintxt\ \[lrepeat\ \[llength\ \$ciphertext\]\ 0\]\n\ \ \ \ \n\ \ \ \ for\ \{set\ b\ 0\}\ \{\$b\ <\ \$nBlocks\}\ \{incr\ b\}\ \{\n\ \ \ \ \ \ \ \ for\ \{set\ c\ 0\}\ \{\$c\ <\ 4\}\ \{incr\ c\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lset\ counterBlock\ \[-\ 15\ \$c\]\ \[&\ \[>>\ \$b\ \[*\ \$c\ 8\]\]\ 0xff\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ for\ \{set\ c\ 0\}\ \{\$c\ <\ 4\}\ \{incr\ c\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lset\ counterBlock\ \[-\ 15\ \$c\ 4\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \[&\ 0xff\ \[>>\ \[-\ \[int\ \[ceil\ \[/\ \[+\ \$b\ 1.0\]\ 0x100000000\]\]\]\ 1\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[*\ \$c\ 8\]\]\]\n\ \ \ \ \ \ \ \ \ \ \ \ #\ This\ \[expr\ ...\]\ is\ equiv\ to\ the\ above\ prefix\ format.\ \ \n\ \ \ \ \ \ \ \ \ \ \ \ #\ AFAICT\ performance\ is\ about\ the\ same.\ (Expected\ expr\ to\n\ \ \ \ \ \ \ \ \ \ \ \ #\ be\ faster--seems\ it\ isn't.)\n\ \ \ \ \ \ \ \ \ \ \ \ #\ \[expr\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ #\ \ \ \ \ ((int(ceil((\$b+1.0)/0x100000000))-1)\ >>\ \$c*8)\ &\ 0xff\n\ \ \ \ \ \ \ \ \ \ \ \ #\ \}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ set\ cipherCntr\ \[cipher\ \$counterBlock\ \$keySchedule\]\n\ \ \ \ \ \ \ \ set\ ctstr\ \[lindex\ \$ciphertext\ \$b\]\ \;#\ <=\ 16\ bytes\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ plaintxtByte\ \[lmap\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ciph\ \[lrange\ \$cipherCntr\ 0\ \[string\ length\ \$ctstr\]-1\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ t\ \[str->bytes\ \$ctstr\ \]\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ format\ %c\ \[^\ \$ciph\ \$t\]\n\ \ \ \ \ \ \ \ \}\]\n\ \ \ \ \ \ \ \ lset\ plaintxt\ \$b\ \[join\ \$plaintxtByte\ \"\"\]\n\ \ \ \ \}\n\ \ \ \ encoding\ convertfrom\ utf-8\ \[join\ \$plaintxt\ \"\"\]\ \ \ \ \n\}\n\ \ \ \ \n\n<<categories>>\ Cryptography\ |\ Aes regexp2} CALL {my render {AES CTR} Working\ on\ web\ programs\ I\ found\ a\ need\ to\ exchange\ encrypted\ content.\ \ On\ the\ browser\ side\ finding\ javascript\ crypto\ libraries\ wasn't\ difficult.\ \ After\ some\ experimenting,\ I\ settled\ on\ the\ AES-CTR\ \"reference\ implementation\"\ by\ Chris\ Veness.\ \ \[https://github.com/chrisveness/crypto\]\n\nThe\ server\ was\ harder.\ \ I'd\ written\ a\ server\ in\ Tcl,\ but\ there\ weren't\ any\ Tcl\ AES-CTR\ implementations\ to\ be\ found.\ \ The\ tcllib\ AES\ handles\ CBC\ but\ not\ CTR\ mode.\ \ After\ I\ modified\ it\ to\ do\ CTR,\ the\ tcllib\ code\ would\ encrypt/decrypt\ OK.\ \ Problem\ was\ it\ wouldn't\ work\ with\ text\ encrypted\ by\ the\ JS\ (or\ another)\ AES-CTR\ program.\n\nTherefore\ I\ was\ inspired\ to\ build\ a\ Tcl\ version\ that\ works\ with\ the\ javascript\ implementation\ I\ was\ using.\ \ The\ result\ was\ a\ Tcl\ AES-CTR\ implementation\ that\ decrypts\ text\ encrypted\ with\ JS\ in\ the\ browser\ and\ vice\ versa.\n\nPretty\ straightforward\ to\ use.\ Loading\ aes.js\ and\ aes-ctr.js\ in\ the\ web\ page\ allows\ access\ to\ the\ encrypt/decrypt\ functions.\ \ Sourcing\ aesctr.tcl\ in\ Tcl\ exposes\ similar\ encrypt\ and\ decrypt\ commands.\ \ \n\nIn\ Tcl,\ calling\ encrypt/decrypt:\n======\n\ \ encrypt\ \"This\ is\ text\ to\ be\ encrypted\"\ \"A\ password\"\ 256\ \n\ \ ==>\ 4ACtkN/r7lRmY/sfmtulg1KSGPu/0E0YSfYzBIIu0otrGOD5\n\n\ \ decrypt\ 4ACtkN/r7lRmY/sfmtulg1KSGPu/0E0YSfYzBIIu0otrGOD5\ \"A\ password\"\ 256\n\ \ ==>\ This\ is\ text\ to\ be\ encrypted\n======\n\nIn\ javascript:\n======\n\ \ AesCtr.decrypt(\"4ACtkN/r7lRmY/sfmtulg1KSGPu/0E0YSfYzBIIu0otrGOD5\",\ \"A\ password\",\ 256)\;\n\ \ ==>\ \"This\ is\ text\ to\ be\ encrypted\"\n\n\ \ AesCtr.encrypt(\"This\ is\ text\ to\ be\ encrypted\",\ \"A\ password\",\ 256)\;\n\ \ ==>\ \"4ACtkN/r7lRmY/sfmtulg1KSGPu/0E0YSfYzBIIu0otrGOD5\"\n======\n\nThe\ Tcl\ AES-CTR\ commands\ work\ correctly\ but\ no\ doubt\ could\ be\ better\ optimized.\ \ As\ an\ informal\ benchmark,\ on\ my\ Surface\ Pro\ 2,\ the\ Tcl\ encrypt\ example\ above\ runs\ in\ 8.80\ millisec.\ \ The\ decrypt\ command\ consumed\ 8.86\ millisec.\ \ I\ didn't\ test\ other\ implementations.\n\n======\n##\ aesctr.tcl\n\n##\ AES\ CTR\ in\ Tcl.\n##\ (C)\ 2015\ J.\ Altfas\n##\n##\ This\ Tcl\ implementation\ is\ intended\ to\ be\ compatible\ with\ the\ JS\n##\ version\ referenced\ below,\ that\ is,\ text\ encrypted\ using\ JS\ can\ be\n##\ decrypted\ in\ Tcl\ and\ vice\ versa.\ \ \n##\n##\ Usage:\ \n##\ \ \ \ \ \ encrypt\ <input\ text\ (string)>\ <password\ (string)>\ 128|192|256\n##\ \ \ \ \ \ decrypt\ <encryp\ msg\ (string)>\ <password\ (string)>\ 128|192|256\n##\ \n##\ Reference\ code:\ aes.js,\ aes-ctr.js\ \n##\ \ \ \"AES\ Counter-mode\ implementation\ in\ JavaScript\"\n##\ \ \ (c)\ Chris\ Veness\ 2005-2014\ /\ MIT\ Licence\n##\ \ \ https://github.com/chrisveness/crypto\n\nset\ sBox\ \{\n\ \ \ \ 0x63\ 0x7c\ 0x77\ 0x7b\ 0xf2\ 0x6b\ 0x6f\ 0xc5\ 0x30\ 0x01\ 0x67\ 0x2b\ 0xfe\ 0xd7\ 0xab\ 0x76\n\ \ \ \ 0xca\ 0x82\ 0xc9\ 0x7d\ 0xfa\ 0x59\ 0x47\ 0xf0\ 0xad\ 0xd4\ 0xa2\ 0xaf\ 0x9c\ 0xa4\ 0x72\ 0xc0\n\ \ \ \ 0xb7\ 0xfd\ 0x93\ 0x26\ 0x36\ 0x3f\ 0xf7\ 0xcc\ 0x34\ 0xa5\ 0xe5\ 0xf1\ 0x71\ 0xd8\ 0x31\ 0x15\n\ \ \ \ 0x04\ 0xc7\ 0x23\ 0xc3\ 0x18\ 0x96\ 0x05\ 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\ \$Nb\ 4\]\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ state\ \[%\ \$i\ 4\]\ \[int\ \[floor\ \[/\ \$i\ 4.0\]\]\]\ \[lindex\ \$input\ \$i\]\n\ \ \ \ \}\n\ \ \ \ set\ state\ \[addRoundKey\ \$state\ \$w\ 0\ \$Nb\]\ \ \ \ \n\ \ \ \ for\ \{set\ round\ 1\}\ \{\$round\ <\ \$Nr\}\ \{incr\ round\}\ \{\n\ \ \ \ \ \ \ \ set\ state\ \[subBytes\ \$state\ \$Nb\]\n\ \ \ \ \ \ \ \ set\ state\ \[shiftRows\ \$state\ \$Nb\]\n\ \ \ \ \ \ \ \ set\ state\ \[mixColumns\ \$state\ \$Nb\]\n\ \ \ \ \ \ \ \ set\ state\ \[addRoundKey\ \$state\ \$w\ \$round\ \$Nb\]\n\ \ \ \ \}\ \ \ \n\ \ \ \ set\ state\ \[subBytes\ \$state\ \$Nb\]\n\ \ \ \ set\ state\ \[shiftRows\ \$state\ \$Nb\]\n\ \ \ \ set\ state\ \[addRoundKey\ \$state\ \$w\ \$Nr\ \$Nb\]\n\ \ \ \ \n\ \ \ \ set\ output\ \[lrepeat\ \[*\ 4\ \$Nb\]\ 0\]\n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ \[*\ 4\ \$Nb\]\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ output\ \$i\ \[lindex\ \$state\ \[%\ \$i\ 4\]\ \[int\ \[floor\ \[/\ \$i\ 4.0\]\]\]\]\n\ \ \ \ \}\n\ \ \ \ return\ \$output\n\}\n\nproc\ keyExpansion\ \{key\}\ \{\n\ \ \ \ set\ Nb\ 4\n\ \ \ \ set\ Nk\ \[/\ \[llength\ \$key\]\ 4\]\ \;#\ 4,6,8\ for\ 128,192,256B\ key\n\ \ \ \ set\ Nr\ \[+\ \$Nk\ 6\]\ \ \n\ \ \ \ set\ w\ \[lrepeat\ \[*\ \$Nb\ \[+\ \$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\ \ \ \ \ lset\ s\ 2\ \$c\ \[^\ \[lindex\ \$a\ 0\]\ \[lindex\ \$a\ 1\]\ \[lindex\ \$b\ 2\]\ \[lindex\ \$a\ 3\]\ \[lindex\ \$b\ 3\]\ \]\n\ \ \ \ \ \ \ \ lset\ s\ 3\ \$c\ \[^\ \[lindex\ \$a\ 0\]\ \[lindex\ \$b\ 0\]\ \[lindex\ \$a\ 1\]\ \[lindex\ \$a\ 2\]\ \[lindex\ \$b\ 3\]\ \]\n\ \ \ \ \}\n\ \ \ \ return\ \$s\n\}\n\n##\ state\ is\ list\ of\ 4\ lists\ of\ 4\ elem:\ \{\{r0c0\ r0c1\ ...\}\ \{r1c0\ ...\}\ ...\}\nproc\ addRoundKey\ \{state\ w\ rnd\ Nb\}\ \{\n\ \ \ \ for\ \{set\ r\ 0\}\ \{\$r\ <\ 4\}\ \{incr\ r\}\ \{\n\ \ \ \ \ \ \ \ for\ \{set\ c\ 0\}\ \{\$c\ <\ \$Nb\}\ \{incr\ c\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ ##\ state\[r\]\[c\]\ ^=\ w\[rnd*4+c\]\[r\]\n\ \ \ \ \ \ \ \ \ \ \ \ lset\ state\ \$r\ \$c\ \[^\ \[lindex\ \$state\ \$r\ \$c\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[lindex\ \$w\ \[+\ \[*\ \$rnd\ 4\]\ \$c\]\ \$r\]\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ return\ \$state\n\}\n\n#\ Apply\ SBox\ to\ 4-byte\ word\ w4\nproc\ subWord\ \{w4\}\ \{\n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 4\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ w4\ \$i\ \[lindex\ \$::sBox\ \[lindex\ \$w4\ \$i\]\]\;\n\ \ \ \ \}\n\ \ \ \ return\ \$w4\n\}\n\nproc\ rotWord\ \{w4\}\ \{\n\ \ \ \ set\ tmp\ \[lindex\ \$w4\ 0\]\n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 3\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ w4\ \$i\ \[lindex\ \$w4\ \[+\ \$i\ 1\]\]\n\ \ \ \ \}\n\ \ \ \ lset\ w4\ 3\ \$tmp\n\ \ \ \ return\ \$w4\n\}\n\nproc\ str->bytes\ \{str\ \{keysz\ 0\}\}\ \{\n\ \ \ \ set\ keysz\ \[expr\ \{!\$keysz\ ?\ \[string\ length\ \$str\]\ :\ \$keysz\}\]\ \n\ \ \ \ concat\ \[lmap\ c\ \[lrange\ \[split\ \$str\ \"\"\]\ 0\ \$keysz-1\]\ \{\n\ \ \ \ \ \ \ \ scan\ \$c\ %c\n\ \ \ \ \}\]\ \[expr\ \{\$keysz\ >\ \[string\ length\ \$str\]\ ?\n\ \ \ \ \ \ \ \ \ \ \ \[lrepeat\ \[-\ \$keysz\ \[string\ length\ \$str\]\]\ 0\]\ :\ \{\}\ \}\]\n\}\n\nproc\ encrypt\ \{plaintxt\ passwd\ nBits\}\ \{\n\ \ \ \ set\ blockSize\ 16\n\ \ \ \ if\ \{\[ni\ \$nBits\ \{128\ 192\ 256\}\]\}\ \{\n\ \ \ \ \ \ \ \ return\ \"\"\n\ \ \ \ \}\n\ \ \ \ set\ plain\ \[encoding\ convertto\ utf-8\ \$plaintxt\]\n\ \ \ \ set\ pw\ \[encoding\ convertto\ utf-8\ \$passwd\]\ \ \ \ \n\ \ \ \ set\ nBytes\ \[/\ \$nBits\ 8\]\n\ \ \ \ set\ pwBytes\ \[str->bytes\ \$pw\ \$nBytes\]\n\ \ \ \ \n\ \ \ \ set\ key\ \[cipher\ \$pwBytes\ \[keyExpansion\ \$pwBytes\]\]\n\ \ \ \ lappend\ key\ \{*\}\[lrange\ \$key\ 0\ \[-\ \$nBytes\ 16\]\]\n\ \ \ \ \n\ \ \ \ set\ counterBlock\ \[lrepeat\ \$blockSize\ 0\]\ \ \ \n\ \ \ \ set\ nonce\ \[clock\ milliseconds\]\n\ \ \ \ set\ nonceMs\ \[%\ \$nonce\ 1000\]\n\ \ \ \ set\ nonceSec\ \[int\ \[/\ \$nonce\ 1000\]\]\n\ \ \ \ set\ nonceRnd\ \[int\ \[*\ \[rand\]\ 0xffff\]\]\n\ \ \ \ \n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 2\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ counterBlock\ \$i\ \[&\ \[>>\ \$nonceMs\ \[*\ \$i\ 8\]\]\ 0xff\]\n\ \ \ \ \}\n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 2\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ counterBlock\ \[+\ \$i\ 2\]\ \[&\ \[>>\ \$nonceRnd\ \[*\ \$i\ 8\]\]\ 0xff\]\n\ \ \ \ \}\n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 4\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ counterBlock\ \[+\ \$i\ 4\]\ \[&\ \[>>\ \$nonceSec\ \[*\ \$i\ 8\]\]\ 0xff\]\n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ ##\ save\ 1st\ 8\ bytes\ of\ counterBlock\ as\ text--used\ in\ output\n\ \ \ \ set\ ctrTxt\ \[join\ \[lmap\ x\ \[lrange\ \$counterBlock\ 0\ 7\]\ \{\n\ \ \ \ \ \ \ \ format\ %c\ \$x\n\ \ \ \ \}\]\ \"\"\]\ \ \n\ \ \ \ set\ keySchedule\ \[keyExpansion\ \$key\]\ \ \ \ \n\ \ \ \ set\ blockCount\ \[int\ \[ceil\ \[/\ \[double\ \[string\ length\ \$plain\]\]\ \$blockSize\]\]\]\n\ \ \ \ set\ ciphertxt\ \[lrepeat\ \$blockCount\ 0\]\n\ \ \ \ \n\ \ \ \ for\ \{set\ b\ 0\}\ \{\$b\ <\ \$blockCount\}\ \{incr\ b\}\ \{\n\ \ \ \ \ \ \ \ for\ \{set\ c\ 0\}\ \{\$c\ <\ 4\}\ \{incr\ c\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lset\ counterBlock\ \[-\ 15\ \$c\]\ \[&\ \[>>\ \$b\ \[*\ \$c\ 8\]\]\ 0xff\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ for\ \{set\ c\ 0\}\ \{\$c\ <\ 4\}\ \{incr\ c\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lset\ counterBlock\ \[-\ 15\ \$c\ 4\]\ \[>>\ \[/\ \$b\ 0x100000000\]\ \[*\ \$c\ 8\]\]\n\ \ \ \ \ \ \ \ \}\ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ cipherCntr\ \[cipher\ \$counterBlock\ \$keySchedule\]\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ blockLength\ \[expr\ \{\$b\ <\ (\$blockCount\ -\ 1)\ ?\ \$blockSize\ -\ 1\ :\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ((\[string\ length\ \$plain\]\ -\ 1)\ %\ \$blockSize)\}\]\ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ st\ \[*\ \$b\ \$blockSize\]\ \;#\ start\ of\ plaintext\ segment\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ ##\ xor\ chars\ from\ plaintext\ segment\ and\ cipherCntr\ \ \n\ \ \ \ \ \ \ \ set\ cipherChar\ \[\n\ \ \ \ \ \ \ \ \ \ lmap\ p\ \[split\ \[string\ range\ \$plain\ \$st\ \$st+\$blockLength\]\ \"\"\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ciph\ \[lrange\ \$cipherCntr\ 0\ \$blockLength\]\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ format\ %c\ \[^\ \$ciph\ \[scan\ \$p\ %c\]\]\n\ \ \ \ \ \ \ \ \}\]\ \ \ \n\ \ \ \ \ \ \ \ lset\ ciphertxt\ \$b\ \[join\ \$cipherChar\ \"\"\]\n\ \ \ \ \}\ \ \ \n\ \ \ \ ##\ prepend\ saved\ counterBlock\ text,\ needed\ for\ decryption\n\ \ \ \ binary\ encode\ base64\ \[string\ cat\ \$ctrTxt\ \[join\ \$ciphertxt\ \"\"\]\]\n\}\n\ \ \ \ \ \ \ \ \ \ \nproc\ decrypt\ \{ciphertext\ passwd\ nBits\}\ \{\n\ \ \ \ set\ blockSize\ 16\n\ \ \ \ if\ \{\[ni\ \$nBits\ \{128\ 192\ 256\}\]\}\ \{\n\ \ \ \ \ \ \ \ return\ \"\"\n\ \ \ \ \}\ \ \ \n\ \ \ \ set\ ciphertext\ \[binary\ decode\ base64\ \$ciphertext\]\n\ \ \ \ set\ pw\ \[encoding\ convertto\ utf-8\ \$passwd\]\ \ \ \ \n\ \ \ \ set\ nBytes\ \[/\ \$nBits\ 8\]\n\ \ \ \ set\ pwBytes\ \[str->bytes\ \$pw\ \$nBytes\]\n\ \ \ \ \n\ \ \ \ set\ key\ \[cipher\ \$pwBytes\ \[keyExpansion\ \$pwBytes\]\]\n\ \ \ \ lappend\ key\ \{*\}\[lrange\ \$key\ 0\ \[-\ \$nBytes\ 16\]\]\n\ \ \ \ \n\ \ \ \ set\ ctrTxt\ \[string\ range\ \$ciphertext\ 0\ 8\]\n\ \ \ \ set\ counterBlock\ \[lrepeat\ 16\ 0\]\n\ \ \ \ for\ \{set\ i\ 0\}\ \{\$i\ <\ 8\}\ \{incr\ i\}\ \{\n\ \ \ \ \ \ \ \ lset\ counterBlock\ \$i\ \[scan\ \[string\ index\ \$ctrTxt\ \$i\]\ %c\]\n\ \ \ \ \}\ \n\ \ \ \ set\ keySchedule\ \[keyExpansion\ \$key\]\n\ \ \ \ \n\ \ \ \ ##\ re:\ ceil:\ using\ 8.0\ to\ make\ sure\ result\ is\ double\n\ \ \ \ set\ nBlocks\ \[int\ \[ceil\ \[/\ \[-\ \[string\ length\ \$ciphertext\]\ 8.0\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$blockSize\]\]\]\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \n\ \ \ \ set\ ct\ \[lrepeat\ \$nBlocks\ 0\]\n\ \ \ \ for\ \{set\ b\ 0\}\ \{\$b\ <\ \$nBlocks\}\ \{incr\ b\}\ \{\n\ \ \ \ \ \ \ \ set\ pos\ \[+\ 8\ \[*\ \$b\ \$blockSize\]\]\n\ \ \ \ \ \ \ \ lset\ ct\ \$b\ \[string\ range\ \$ciphertext\ \$pos\ \[+\ \$pos\ \$blockSize\ -1\]\]\n\ \ \ \ \}\ \ \ \ \n\ \ \ \ set\ ciphertext\ \$ct\n\ \ \ \ set\ plaintxt\ \[lrepeat\ \[llength\ \$ciphertext\]\ 0\]\n\ \ \ \ \n\ \ \ \ for\ \{set\ b\ 0\}\ \{\$b\ <\ \$nBlocks\}\ \{incr\ b\}\ \{\n\ \ \ \ \ \ \ \ for\ \{set\ c\ 0\}\ \{\$c\ <\ 4\}\ \{incr\ c\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lset\ counterBlock\ \[-\ 15\ \$c\]\ \[&\ \[>>\ \$b\ \[*\ \$c\ 8\]\]\ 0xff\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ for\ \{set\ c\ 0\}\ \{\$c\ <\ 4\}\ \{incr\ c\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lset\ counterBlock\ \[-\ 15\ \$c\ 4\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \[&\ 0xff\ \[>>\ \[-\ \[int\ \[ceil\ \[/\ \[+\ \$b\ 1.0\]\ 0x100000000\]\]\]\ 1\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[*\ \$c\ 8\]\]\]\n\ \ \ \ \ \ \ \ \ \ \ \ #\ This\ \[expr\ ...\]\ is\ equiv\ to\ the\ above\ prefix\ format.\ \ \n\ \ \ \ \ \ \ \ \ \ \ \ #\ AFAICT\ performance\ is\ about\ the\ same.\ (Expected\ expr\ to\n\ \ \ \ \ \ \ \ \ \ \ \ #\ be\ faster--seems\ it\ isn't.)\n\ \ \ \ \ \ \ \ \ \ \ \ #\ \[expr\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ #\ \ \ \ \ ((int(ceil((\$b+1.0)/0x100000000))-1)\ >>\ \$c*8)\ &\ 0xff\n\ \ \ \ \ \ \ \ \ \ \ \ #\ \}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ set\ cipherCntr\ \[cipher\ \$counterBlock\ \$keySchedule\]\n\ \ \ \ \ \ \ \ set\ ctstr\ \[lindex\ \$ciphertext\ \$b\]\ \;#\ <=\ 16\ bytes\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ plaintxtByte\ \[lmap\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ciph\ \[lrange\ \$cipherCntr\ 0\ \[string\ length\ \$ctstr\]-1\]\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ t\ \[str->bytes\ \$ctstr\ \]\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ format\ %c\ \[^\ \$ciph\ \$t\]\n\ \ \ \ \ \ \ \ \}\]\n\ \ \ \ \ \ \ \ lset\ plaintxt\ \$b\ \[join\ \$plaintxtByte\ \"\"\]\n\ \ \ \ \}\n\ \ \ \ encoding\ convertfrom\ utf-8\ \[join\ \$plaintxt\ \"\"\]\ \ \ \ \n\}\n\ \ \ \ \n\n<<categories>>\ Cryptography\ |\ Aes} CALL {my revision {AES CTR}} CALL {::oo::Obj1070125 process revision/AES+CTR} CALL {::oo::Obj1070123 process}

-errorcode

NONE

-errorinfo

Unknow state transition: LINE -> END
    while executing
"error $msg"
    (class "::Wiki" method "render_wikit" line 6)
    invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
    (class "::Wiki" method "render" line 8)
    invoked from within
"my render $name $C"
    (class "::Wiki" method "revision" line 31)
    invoked from within
"my revision $page"
    (class "::Wiki" method "process" line 56)
    invoked from within
"$server process [string trim $uri /]"

-errorline

4