let shift_char c k = let n = Char.code c in if n >= 97 && n <= 122 then Char.chr (((n - 97 + k) mod 26 + 26) mod 26 + 97) else c let encode s k = String.init (String.length s) (fun i -> shift_char s.[i] k) ;; (* ROT13 round-trip: encode (encode "hello" 13) 13 = "hello". Sum the codes of two chars to give a deterministic integer check. *) let r = encode (encode "hello" 13) 13 in Char.code r.[0] + Char.code r.[4]