Skip to content

Instantly share code, notes, and snippets.

@t1anchen
Last active December 18, 2015 13:48
Show Gist options
  • Save t1anchen/5792168 to your computer and use it in GitHub Desktop.
Save t1anchen/5792168 to your computer and use it in GitHub Desktop.
Simply generate typoglycemia
(use 'clojure.string)
(defn gen-rnd-idx-seq [s]
(let [ordered-idx (range (count s))
randomed-idx (map #(rand-int %) ordered-idx)
arrayed-s (into-array s)]
(join (reduce #(let [foo-idx (first %2)
bar-idx (last %2)
foo (nth arrayed-s foo-idx)
bar (nth arrayed-s bar-idx)]
(do
(aset %1 foo-idx bar)
(aset %1 bar-idx foo)
%1))
arrayed-s
(map list ordered-idx randomed-idx)))))
(defn obfuscate-token [s]
(let [first-char (re-find #"^\w" s)
others (last (split (first (split s #"\w$")) #"^\w"))
last-char (re-find #"\w$" s)]
(str first-char (gen-rnd-idx-seq others) last-char)))
(defn gen-simple-typoglycemia [paragraph]
(let [words (split paragraph #"\W+")]
(join " " (into [] (map obfuscate-token words)))))
;; user> (gen-simple-typoglycemia "Hello, World! Welcome to computer world!")
;; "Hlelo Wlord Wcolmee to ctpuemor wlord"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment