Last active
December 18, 2015 13:48
-
-
Save t1anchen/5792168 to your computer and use it in GitHub Desktop.
Simply generate typoglycemia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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