(* q0.ml - Don Yang (uguu.org) Q is for quine. Of course this is not quite a quine yet. 08/04/03 *) let template = "P.bK .bEaE.";; let data = "kfool#tlqog";; let key = 3;; let rec string_to_list str = if String.length str > 0 then (String.get str 0) :: (string_to_list (String.sub str 1 ((String.length str) - 1))) else [];; let rec list_to_string lst = match lst with a::b -> (String.make 1 a) ^ list_to_string b | [] -> "";; let char_list_to_int_list c = List.map (fun x -> Char.code x) c;; let int_list_to_char_list c k = List.map (fun x -> Char.chr (x lxor k)) c;; let string_to_int_list s = char_list_to_int_list (string_to_list s);; let int_list_to_string l k = list_to_string (int_list_to_char_list l k);; let xor_string s k = int_list_to_string (string_to_int_list s) k;; let rec remove_space str = if String.length str <= 0 then "" else ( (let x = String.sub str 0 1 in if x = " " then "" else x) ^ (remove_space (String.sub str 1 ((String.length str) - 1))) );; let rec format_text template text = match template with x::y -> if x >= 65 && x <= 90 then ( let x = x - 64 in ( print_string (String.sub text 0 x); format_text y (String.sub text x ((String.length text) - x)) ) ) else ( if x >= 97 && x <= 122 then print_string (String.make (x - 96) ' ') else print_newline (); format_text y text ); | [] -> ();; format_text (string_to_int_list (remove_space template)) (remove_space ("header" ^ template ^ data ^ (xor_string data key)));;