Guest User

Untitled

a guest
Dec 12th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #!/usr/bin/env lua
  2. -- splitmergedata.lua
  3. -- Read concatenated partial models as generated with splitmakedata.lua and
  4. -- merge them producing a model string that can be used with klg.passwordEntropy.
  5. -- Output is a nicely formatted Javascript source.
  6.  
  7. local e = require "encode"
  8.  
  9. local cx = {}
  10.  
  11. for ln in io.lines() do
  12. local p1, p2, n = ln:match("^%s*(..)(..)%s(%d+)")
  13. if n then
  14. local p2f = e.fldecode(p2)
  15. n = tonumber(n)
  16. if cx[n] == nil then
  17. cx[n] = { p1, p2, p2f }
  18. else
  19. if cx[n][1] == "--" then
  20. cx[n][1] = p1
  21. elseif p1 ~= "--" and p1 ~= cx[n][1] then
  22. error "Inconsistent model"
  23. end
  24. if cx[n][3] < p2f then
  25. cx[n][2] = p2
  26. cx[n][3] = p2f
  27. end
  28. end
  29. end
  30. end
  31.  
  32. local sx = {}
  33.  
  34. for i, dat in pairs(cx) do
  35. if dat[1] == "--" then
  36. io.stderr:write(string.format(
  37. "Warning: Model incomplete. Unknown probability for tuple %d.\n", i))
  38. else
  39. table.insert(sx, i)
  40. end
  41. end
  42. table.sort(sx)
  43.  
  44. local last = -1
  45. local str = ""
  46.  
  47. io.write("// Generated "..os.date().."\n")
  48. io.write("(window.klg || (window.klg = {})).passwordModel =\n")
  49.  
  50. for _, k in ipairs(sx) do
  51. if k - last > 1 then
  52. str = str .. e.rlencode(k-last-1)
  53. end
  54. str = str .. cx[k][1]
  55. str = str .. cx[k][2]
  56. last = k
  57. if #str > 77 then
  58. io.write('"', str:sub(1, 77), '"+\n')
  59. str = str:sub(78)
  60. end
  61. end
  62.  
  63. io.write('"', str, '";\n')
Add Comment
Please, Sign In to add comment