Files
2026-11-22 18:19:16 +01:00

19 lines
521 B
OCaml

let decode s =
let value = function
| 'a' .. 'z' as c -> Char.code c - Char.code 'a'
| 'A' .. 'Z' as c -> Char.code c - Char.code 'A'
| c -> Char.code c - Char.code '2' + 26
in
let buf = Buffer.create 32 in
let acc = ref 0 and bits = ref 0 in
String.iter
(fun c ->
acc := (!acc lsl 5) lor value c;
bits := !bits + 5;
if !bits >= 8 then begin
bits := !bits - 8;
Buffer.add_char buf (Char.chr ((!acc lsr !bits) land 0xff))
end)
s;
Buffer.contents buf