diff options
| author | mryouse | 2022-06-06 00:55:15 +0000 |
|---|---|---|
| committer | mryouse | 2022-06-06 00:55:15 +0000 |
| commit | 90a359ef5930b4dd764c49edef7c951caeec037d (patch) | |
| tree | fa52fba6b76ad978b84021a023e1ea500d0e1ef5 /cipher/viewer.neb | |
| parent | 0cbfbba377cfc0e88a87361b774c3f46ddfe12e5 (diff) | |
initial commit of cipher
Diffstat (limited to 'cipher/viewer.neb')
| -rw-r--r-- | cipher/viewer.neb | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/cipher/viewer.neb b/cipher/viewer.neb new file mode 100644 index 0000000..ae99f29 --- /dev/null +++ b/cipher/viewer.neb @@ -0,0 +1,76 @@ +;(func ascii-grey (inp) +; (print (concat "\033[31;1;4m" inp "\033[0m")) +; (concat "\033[90m" inp "\033[0m")) + +(func keys (assoc) + (map first assoc)) + +(func get (assoc key) + (def ret "_") + (for-each assoc + (if (eq? (first _item_) key) + (redef ret (first (rest _item_))))) + ret) + +(func de-cipher (cipher codex) + (def out "") + (for-each (split cipher) + (redef out + (concat out + (if (in? _item_ (keys codex)) + (get codex _item_) + (ascii-gray _item_))))) + out) + +(func print-codex (codex) + (for-each codex + (print (concat (first _item_) " => " (first (rest _item_)))))) + +(func save-and-exit (cipher codex) + (print "in save-and-exit") + (with-write "progress.txt" + (write (concat cipher (newline)) _file_) + (for-each codex + (write (concat (first _item_) " " (first (rest _item_)) (newline)) _file_))) + (exit)) + +(func loop (cipher codex) + (def cur codex) + (while #true + (clear) + (print (de-cipher cipher cur)) + (print "") + (print-codex cur) + (print "") + (def inp (split (strip (input "? ")) " ")) + (branch + ((eq? "quit" (first inp)) (exit)) + ((eq? "save" (first inp)) (save-and-exit cipher cur)) + ((> (list-length inp) 2) (exit)) + ((and (empty? (rest inp)) (in? (first inp) (keys cur))) + (redef cur (remove cur (first inp)))) + ((in? (first inp) (keys codex)) + (redef cur (append (remove cur (first inp)) inp))) + ((empty? (rest inp)) + #true) + (#true + (redef cur (append cur inp)))))) + +(func split-space (str) + (split str " ")) + +(func main (args) + (if (empty? args) + (block + (print "expecting a cypher!") + (exit))) + (def lines + (map strip + (read-lines (first args)))) + + (def codex + (map split-space (rest lines))) + + (loop (first lines) codex)) + +(main (rest (argv))) |
