diff options
| author | Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> | 2012-02-23 19:05:12 +0100 | 
|---|---|---|
| committer | Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> | 2012-02-23 19:05:12 +0100 | 
| commit | 93e1c741d591be11d4782ec359d33a3f1b54bf8c (patch) | |
| tree | cfb0cf2bf706e6a6613e5a305fa8b5881b652282 | |
| parent | b17163c6ef0c5d84456874f67d198e844e4d774f (diff) | |
| download | enigma-93e1c741d591be11d4782ec359d33a3f1b54bf8c.tar.gz | |
mtx-script
| -rw-r--r-- | documentation.ichd | 9 | ||||
| -rw-r--r-- | scripts/context/lua/third/enigma/mtx-t-enigma.lua | 62 | ||||
| -rw-r--r-- | tex/context/third/enigma/enigma.lua | 47 | ||||
| -rw-r--r-- | tex/context/third/enigma/t-enigma.mkvi | 7 | 
4 files changed, 99 insertions, 26 deletions
| diff --git a/documentation.ichd b/documentation.ichd new file mode 100644 index 0000000..7d49d0e --- /dev/null +++ b/documentation.ichd @@ -0,0 +1,9 @@ + Documentation Specification for the Enigma Module. +[Manual] + to be written +[Implementation] +\PLAIN\_macros      tex     enigma.tex +\CONTEXT\_macros    context t-enigma.mkvi +\LATEX\_wrapper     latex   enigma.sty +Functionality       lua     enigma.lua  +Scripting           lua     mtx-t-enigma.lua diff --git a/scripts/context/lua/third/enigma/mtx-t-enigma.lua b/scripts/context/lua/third/enigma/mtx-t-enigma.lua new file mode 100644 index 0000000..8c84385 --- /dev/null +++ b/scripts/context/lua/third/enigma/mtx-t-enigma.lua @@ -0,0 +1,62 @@ +-- +-------------------------------------------------------------------------------- +--         FILE:  mtx-transliterate.lua +--        USAGE:  mtxrun --script transliterate [--mode=mode] --s="string" +--  DESCRIPTION:  context script interface for the Transliterator module +-- REQUIREMENTS:  latest ConTeXt MkIV +--       AUTHOR:  Philipp Gesang (Phg), <gesang@stud.uni-heidelberg.de> +--      CREATED:  2011-06-11T16:14:16+0200 +-------------------------------------------------------------------------------- +-- + +environment.loadluafile("enigma") + +local helpinfo = [[ +=============================================================== +    The Enigma module, command line interface. +    © 2012 Philipp Gesang. License: 2-clause BSD. +    Home: <https://bitbucket.org/phg/enigma/> +=============================================================== + +USAGE: + +    mtxrun --script enigma --setup="settings" --text="text" +           --verbose=int + +    where the settings are to be specified as a comma-delimited +    conjunction of “key=value” statements, and “text” refers to +    the text to be encoded. Note that due to the involutory +    design of the enigma cipher, the text can be both plaintext +    and ciphertext. + +=============================================================== +]] + +local application = logs.application { +    name     = "mtx-t-enigma", +    banner   = "The Enigma for ConTeXt, hg-rev 9+", +    helpinfo = helpinfo, +} + +local ea = environment.argument + +local setup, text = ea"setup" or ea"s",  ea"text" or ea"t" +local verbose     = ea"verbose" or ea"v" + +local out = function (str) +  io.write(str) +end + +if setup and text then +  local machine = enigma.new_machine(enigma.parse_args(setup)) +  machine.name  = "external" +  local result  = machine:encode_string(text) +  if result then +    out(result) +  else +    application.help() +  end +else +    application.help() +end + diff --git a/tex/context/third/enigma/enigma.lua b/tex/context/third/enigma/enigma.lua index ad23c2b..b7ab57c 100644 --- a/tex/context/third/enigma/enigma.lua +++ b/tex/context/third/enigma/enigma.lua @@ -71,12 +71,12 @@ local iowrite                      = io.write  local mathfloor                    = math.floor  local mathrandom                   = math.random  local next                         = next -local nodecopy                     = node.copy -local nodeid                       = node.id -local nodeinsert_before            = node.insert_before -local nodenew                      = node.new -local noderemove                   = node.remove -local nodetraverse                 = node.traverse +local nodecopy                     = node and node.copy +local nodeid                       = node and node.id +local nodeinsert_before            = node and node.insert_before +local nodenew                      = node and node.new +local noderemove                   = node and node.remove +local nodetraverse                 = node and node.traverse  local nodesinstallattributehandler = format_is_context_p and nodes.installattributehandler  local nodestasksappendaction       = format_is_context_p and nodes.tasks.appendaction  local stringfind                   = string.find @@ -109,8 +109,8 @@ else    end  end -local glyph_node                   = nodeid"glyph" -local glue_node                    = nodeid"glue" +local glyph_node                   = node and nodeid"glyph" +local glue_node                    = node and nodeid"glue"  --[[ichd--  \startparagraph @@ -742,19 +742,22 @@ extraction of successive characters from the sequence.  \TODO{Make \luafunction{encode_string} preprocess characters.}  \stopparagraph  --ichd]]-- -  --local encode_string = function (machine, str) --, pattern) -  --  local init_state = pattern_to_state(pattern or get_random_pattern()) -  --  emit(1, pprint_init, init_state) -  --  machine:set_state(init_state) -  --  local result = { } -  --  str = stringlower(str) -  --  local n = 1 -- OPTIONAL could lookup machine.step instead -  --  for char in utfcharacters(str) do -  --    result[n] = machine:encode_char(char) -  --    n = n + 1 -  --  end -  --  return tableconcat(result) -  --end +  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] +        end +      else +        result[#result+1] = tmp +      end +    end +    machine:processed_chars() +    return tableconcat(result) +  end  --[[ichd--  \stopdocsection  --ichd]]-- @@ -1273,9 +1276,9 @@ enigma.save_raw_args     = save_raw_args  enigma.retrieve_raw_args = retrieve_raw_args  local new_machine = function (args, name) +  verbose_level = args.verbose    local machine = new(args.day_key, args.rotor_setting)    machine.name  = name -  verbose_level = args.verbose    return machine  end diff --git a/tex/context/third/enigma/t-enigma.mkvi b/tex/context/third/enigma/t-enigma.mkvi index 173bb07..552e483 100644 --- a/tex/context/third/enigma/t-enigma.mkvi +++ b/tex/context/third/enigma/t-enigma.mkvi @@ -78,11 +78,10 @@ thirddata = thirddata or { }  \def\inherit_enigma#to#from{%    \ctxlua{% -    local enigma = thirddata.enigma +    local enigma       = thirddata.enigma      local current_args = enigma.retrieve_raw_args(\!!bs#from\!!es) -    enigma.new_callback( -      enigma.new_machine(current_args, \!!bs#to\!!es), \!!bs#to\!!es -    ) +    enigma.new_callback(enigma.new_machine(current_args, \!!bs#to\!!es), +                        \!!bs#to\!!es)    }%    \do_do_define_enigma{#to}%  } | 
