summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-11-09 04:19:12 +0100
committerAki <please@ignore.pl>2024-11-09 04:19:12 +0100
commit419e19cbc2750512a13ddfff5698f9df39f408da (patch)
tree3556e672ec82f129c6ec7835b009fe4c0f580b75
parent55e970f074cfe1e31e738fe2ce9e7216ef0e2420 (diff)
downloadnoita-eyes-419e19cbc2750512a13ddfff5698f9df39f408da.zip
noita-eyes-419e19cbc2750512a13ddfff5698f9df39f408da.tar.gz
noita-eyes-419e19cbc2750512a13ddfff5698f9df39f408da.tar.bz2
Sketch encoding method for graph automaton
-rwxr-xr-xgraph.lua40
1 files changed, 39 insertions, 1 deletions
diff --git a/graph.lua b/graph.lua
index 2b756d4..5db968d 100755
--- a/graph.lua
+++ b/graph.lua
@@ -2,6 +2,7 @@
local automaton = require "automaton"
local generate = require "generate"
local reading = require "reading"
+local format = require "format"
local init = automaton(generate.trange(1, 25))
@@ -95,9 +96,46 @@ generate_paths_from(graph[19], 3)
for _, node in ipairs(graph) do
for target, paths in pairs(node.paths) do
for _, path in ipairs(paths) do
- print(string.format("%d,%d,%d,%s,%s,%s", node.id, target, trigram(path), path[1], path[2], path[3]))
+ -- print(string.format("%d,%d,%d,%s,%s,%s", node.id, target, trigram(path), path[1], path[2], path[3]))
end
end
error_no_path_between(node, graph[3])
error_no_path_between(node, graph[19])
end
+
+
+local function stupid_invert (obj)
+ local lookup = {}
+ for k, v in pairs(obj) do
+ lookup[v] = k
+ end
+ return lookup
+end
+
+
+local function encode (graph, state, message)
+ state = automaton(state)
+ local lookup = stupid_invert(state)
+ local values = {}
+ for i=1, #message do
+ local node = graph[lookup[message:sub(i, i)]]
+ if not node then
+ error(message:sub(i, i))
+ end
+ local output = 3
+ if (i - 1) % 3 == 1 then
+ output = 19
+ end
+ local path = node.paths[output][math.random(1, #node.paths[output])]
+ table.insert(values, trigram(path))
+ state = state:apply(map[path[1]]):apply(map[path[2]]):apply(map[path[3]])
+ lookup = stupid_invert(state)
+ end
+ return values
+end
+
+
+for i=1, 5 do
+ print(format.csv(encode(graph, "abcdefghiwklm opqrstuvxyz", "we cam try this method to see what kimd of potemial ciphertext we will get out of it")))
+ print(format.csv(encode(graph, "abcdefghiwklm opqrstuvxyz", "amd them try it with amother plaimtext iust to make sure this actually works as expected with lomger texts too")))
+end