Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env lua
- -- splitmergedata.lua
- -- Read concatenated partial models as generated with splitmakedata.lua and
- -- merge them producing a model string that can be used with klg.passwordEntropy.
- -- Output is a nicely formatted Javascript source.
- local e = require "encode"
- local cx = {}
- for ln in io.lines() do
- local p1, p2, n = ln:match("^%s*(..)(..)%s(%d+)")
- if n then
- local p2f = e.fldecode(p2)
- n = tonumber(n)
- if cx[n] == nil then
- cx[n] = { p1, p2, p2f }
- else
- if cx[n][1] == "--" then
- cx[n][1] = p1
- elseif p1 ~= "--" and p1 ~= cx[n][1] then
- error "Inconsistent model"
- end
- if cx[n][3] < p2f then
- cx[n][2] = p2
- cx[n][3] = p2f
- end
- end
- end
- end
- local sx = {}
- for i, dat in pairs(cx) do
- if dat[1] == "--" then
- io.stderr:write(string.format(
- "Warning: Model incomplete. Unknown probability for tuple %d.\n", i))
- else
- table.insert(sx, i)
- end
- end
- table.sort(sx)
- local last = -1
- local str = ""
- io.write("// Generated "..os.date().."\n")
- io.write("(window.klg || (window.klg = {})).passwordModel =\n")
- for _, k in ipairs(sx) do
- if k - last > 1 then
- str = str .. e.rlencode(k-last-1)
- end
- str = str .. cx[k][1]
- str = str .. cx[k][2]
- last = k
- if #str > 77 then
- io.write('"', str:sub(1, 77), '"+\n')
- str = str:sub(78)
- end
- end
- io.write('"', str, '";\n')
Add Comment
Please, Sign In to add comment