(* your code goes here *)(* hex to raw bytes *)
let rec hex_to_raw hexstring =
let rec hexraw hexstr rawstr =
let tophex
= String.sub hexstr
0 2 in let newrawstr
= rawstr
^ (String.make
1 (Char.chr topint
)) in let remlen
= (String.length hexstr
) - 2 in if remlen = 0 then newrawstr
else hexraw
(String.sub hexstr
2 remlen
) newrawstr
in hexraw hexstring "" ;;
let b64_to_raw b64string =
b64string ;;
let raw_to_hex rawstring =
rawstring ;;
let raw_to_b64 rawstring =
rawstring ;;
Printf.printf
"%s" (raw_to_b64
(hex_to_raw
"badf00d"))
KCogeW91ciBjb2RlIGdvZXMgaGVyZSAqKSgqIGhleCB0byByYXcgYnl0ZXMgKikKbGV0IHJlYyBoZXhfdG9fcmF3IGhleHN0cmluZyA9IAogIGxldCByZWMgaGV4cmF3IGhleHN0ciByYXdzdHIgPSAKICAgIGxldCB0b3BoZXggPSBTdHJpbmcuc3ViIGhleHN0ciAwIDIgaW4KICAgIGxldCB0b3BpbnQgPSBpbnRfb2Zfc3RyaW5nICgiMHgiIF4gdG9waGV4KSBpbgogICAgbGV0IG5ld3Jhd3N0ciA9IHJhd3N0ciBeIChTdHJpbmcubWFrZSAxIChDaGFyLmNociB0b3BpbnQpKSBpbgogICAgbGV0IHJlbWxlbiA9IChTdHJpbmcubGVuZ3RoIGhleHN0cikgLSAyICBpbgogICAgaWYgcmVtbGVuID0gMCB0aGVuIG5ld3Jhd3N0cgogICAgZWxzZSBoZXhyYXcgKFN0cmluZy5zdWIgaGV4c3RyIDIgcmVtbGVuKSBuZXdyYXdzdHIgaW4KICBoZXhyYXcgaGV4c3RyaW5nICIiIDs7CgpsZXQgYjY0X3RvX3JhdyBiNjRzdHJpbmcgPQogIGI2NHN0cmluZyA7OwoKbGV0IHJhd190b19oZXggcmF3c3RyaW5nID0KICByYXdzdHJpbmcgOzsKCmxldCByYXdfdG9fYjY0IHJhd3N0cmluZyA9CiAgcmF3c3RyaW5nIDs7CgpQcmludGYucHJpbnRmICIlcyIgKHJhd190b19iNjQgKGhleF90b19yYXcgImJhZGYwMGQiKSk=