Decode Caesar ciphers by petchema

open Char open String;;
let t=ref "" in try while true do t:=!t^read_line()^"\n"done with _->();
let m=ref 0in let b=ref 0in for i=97to 122do let s=ref 0in iter(fun c->if c=chr i then incr s)!t;if !s> !m then(m:=!s;b:=i)done;
iter(fun c->let z m=chr(m+(code c-m+127- !b)mod 26)in print_char(match c with|'a'..'z'->z 97|'A'..'Z'->z 65|c->c))!t

Note that non-ascii characters in the above source code will be escaped (such as \x9f).


return to the top page