diff options
Diffstat (limited to 'cipher')
| -rw-r--r-- | cipher/cipher.txt | 2 | ||||
| -rw-r--r-- | cipher/viewer.neb | 76 |
2 files changed, 78 insertions, 0 deletions
diff --git a/cipher/cipher.txt b/cipher/cipher.txt new file mode 100644 index 0000000..1cac2a7 --- /dev/null +++ b/cipher/cipher.txt @@ -0,0 +1,2 @@ +xocli ci c sat yanncl nzwpl jw un ayy ahwuj a kllp abw ahwuj klarcgb nugbyannln jw ayy aujwzncln swdcgb iwrkarm jw nowk rlnzlxj iwr jol mlam c ncszyt iwrbwj agm bun rliunlm hlxaunl ol oan gw dayul iwr ousag ycil +n s 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))) |
