Commits

Philipp Gesang committed 22e0876

fix external string encoding

  • Participants
  • Parent commits 312ea6a

Comments (0)

Files changed (2)

doc/context/third/enigma/enigma_manual.tex

 \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,

tex/context/third/enigma/enigma.lua

 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
 
 
 --[[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()
 \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