To pack a 40 byte SHA in 20 bytes, we are doing this:
(defn pack-sha-1 [sha-1]
(->> sha-1
(partition 2)
(map (partial apply str)) ;; To convert back to list of strings
(map (fn [hex] (-> hex
(Integer/parseInt 16)
char)))
(apply str))) ;; To convert back to string
First we partition by 2 and then convert that into a single character.
This is essentially the packing step where 2 hex characters are converted into a single character.
When we try to convert the packed string back to its 40 bytes SHA (using https://www.rapidtables.com/convert/number/ascii-to-hex.html), it does not give the same SHA back in all the cases.
It works for: "5e4fb7a0afe4f2ec9768a9ddd2c476dab7fd449b"
But it does not work for: "00c35422185bf1dca594f699084525e8d0b8569f"
Whenever there is a pair of hex in the range ("08" - "0d"), it does not work.
What is going wrong here?
This is done as part of implementing James Coglan's book "Building Git" in Clojure.
Thanks for your help!