Skip to content

Instantly share code, notes, and snippets.

@Blecki
Created May 5, 2013 01:23
Show Gist options
  • Select an option

  • Save Blecki/5519344 to your computer and use it in GitHub Desktop.

Select an option

Save Blecki/5519344 to your computer and use it in GitHub Desktop.
Some ciphered text for a piece of interactive fiction.. and the MISP code to create it.
(set @globals encoding-table
(record
(mape "abcdefghijklmno")
(base "─│┌┐└┘├┤┬┴┼▲►▼◄")
(a "aad")
(b "aaf")
(c "aah")
(d "aid")
(e "aif")
(f "aih")
(g "ajd")
(h "ajf")
(i "ajh")
(j "akd")
(k "akf")
(l "akh")
(m "iad")
(n "iaf")
(o "iah")
(p "iid")
(q "iif")
(r "iih")
(s "ijd")
(t "ijf")
(u "ijh")
(v "ikd")
(w "ikf")
(x "ikh")
(y "jad")
(z "jaf")
("." "aaa")
("!" "kkh")
("?" "kad")
)
)
(defun index-of ((arg str)(arg char))
(fori i 0 (strlen str)
(if (= (strind str i) char)
(break i)
-1
)
)
)
(defun get-enc ((arg char))
(strind @globals.encoding-table.base (index-of @globals.encoding-table.mape char))
)
(defun get-seq ((arg char))
(let (
(code @globals.encoding-table.(char))
(result "")
)
(lastarg
(fori i 0 (strlen code)
(var result (strcat result (get-enc (strind code i))))
)
result
)
)
)
(defun encode-string ((arg str))
(let (
(result "")
(prev-space true)
(next-space true)
)
(lastarg
(fori i 0 (strlen str)
(let ((cur-char (strind str i)))
(if (= cur-char ' ')
(nop
(var prev-space true)
(var result (strcat result " "))
)
(nop
(var next-space (|| (= i (- (strlen str) 1)) (= (strind str (+ i 1)) ' ')))
(if (&& prev-space next-space)
(var result (strcat result (get-enc 'a')))
(if prev-space
(var result (strcat result (get-enc 'c')))
(if next-space
(var result (strcat result (get-enc 'e')))
(var result (strcat result (get-enc 'g')))
)
)
)
(var result (strcat result (get-seq (strind str i))))
(var prev-space false)
)
)
)
)
result
)
)
)
(defun max ((arg-repeat values))
(let ((max- (first values)))
(lastarg
(for value values (if (> value max-) (var max- value)))
max-
)
)
)
(print @globals.encoding-table.mape "\n" @globals.encoding-table.base "\n")
(print "\n\n" (encode-string "hello world") "\n\n")
(defun encode-paragraph ((arg segments))
(let (
(pieces (map word segments (encode-string word)))
(counter 0)
(end (max $(map piece pieces (/ (strlen piece) 4))))
(result "")
)
(lastarg
(while (< counter end)
(nop
(for piece pieces
(if (< (* 4 counter) (strlen piece))
(var result (strcat result (substr piece (* 4 counter) 4) " "))
(var result (strcat result " "))
)
)
(var result (strcat result "\n"))
(var counter (+ 1 counter))
)
)
result
)
)
)
(defun write-to-file ((arg file-name)(arg text))
(let ((_file (file.open file-name "WRITE") (file.close _file)))
(file.write _file text)
)
"Create a file containing the text"
)
(write-to-file "cipher-text.txt" (unescape (encode-paragraph ^("this is some" "long text" "split into" "many segments."))))
┌┬┴┘ ┌─┼┤ ┌┬┴┐ ┌┬─┐
├─┴┘ ├┬─┤ ├┬┬┐ ├──┐
├─┴┤ ├┬─┘ ├─┼┤ ├┬─┘
└┬┴┐ └─┴┐ ├─┴┤ └┴─┐
└┬┴┘
┌─┴┤ ┌┬┴┘ ┌┬┴┐
└┬┴┐ ├─┬┘ ┌─┴┤ ├─┬┘
├┬┼┤ ├┬─┘ ├─┴┐
┌┬┴┐ └┬┴┘ ├┬┴┘ ├┬─┐
├┬─┤ └┬─┤ ├─┬┘
├┬─┐ ├┬─┘
└─┬┘ ├┬┴┘
├┬┴┐
└───
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment