diff options
-rw-r--r-- | doc/context/third/enigma/enigma_manual.tex | 1 | ||||
-rw-r--r-- | tex/context/third/enigma/enigma.lua | 27 |
2 files changed, 16 insertions, 12 deletions
diff --git a/doc/context/third/enigma/enigma_manual.tex b/doc/context/third/enigma/enigma_manual.tex index b511b94..efef2fd 100644 --- a/doc/context/third/enigma/enigma_manual.tex +++ b/doc/context/third/enigma/enigma_manual.tex @@ -183,6 +183,7 @@ the following parameters. \stopitemize %% day key +\noindentation To state the obvious, the value of \identifier{day_key} serves as the \emph{day key} for encryption. An Enigma day key ordinarily consists of (1) a list of the the rotor configuration, diff --git a/tex/context/third/enigma/enigma.lua b/tex/context/third/enigma/enigma.lua index 9d37b76..4aacf53 100644 --- a/tex/context/third/enigma/enigma.lua +++ b/tex/context/third/enigma/enigma.lua @@ -103,6 +103,7 @@ local type = type local utf8byte = unicode.utf8.byte local utf8char = unicode.utf8.char local utf8len = unicode.utf8.len +local utf8lower = unicode.utf8.lower local utf8sub = unicode.utf8.sub local utfcharacters = string.utfcharacters @@ -808,24 +809,26 @@ local variable, \identifier{pb_char}. --[[ichd-- \startparagraph -As the actual encoding proceeds character-wise, the processing of -entire strings needs to be managed externally. This is where -\luafunction{encode_string} comes into play: It handles iteration and -extraction of successive characters from the sequence. -\TODO{Make \luafunction{encode_string} preprocess characters.} +When \modulename{Enigma} is called from \TEX, the encoding +proceeds character by character as we iterate one node at a time. +\luafunction{encode_string} is a wrapper for use with strings, e.~g. in +the mtx-script (\at{page}[sec:fun]). +It handles iteration and extraction of successive characters from the +sequence. \stopparagraph --ichd]]-- local encode_string = function (machine, str) --, pattern) local result = { } - str = stringlower(str) for char in utfcharacters(str) do local tmp = machine:encode(char) - if type(tmp) == "table" then - for i=1, #tmp do - result[#result+1] = tmp[i] + if tmp ~= false then + if type(tmp) == "table" then + for i=1, #tmp do + result[#result+1] = tmp[i] + end + else + result[#result+1] = tmp end - else - result[#result+1] = tmp end end machine:processed_chars() @@ -1070,7 +1073,7 @@ character, each one will be encoded successively, yielding a list. \stopparagraph --ichd]]-- local encode_general = function (machine, chr) - local chr = stringlower(chr) + local chr = utf8lower(chr) local replacement = pp_substitutions[chr] or letter_to_value[chr] and chr if not replacement then |