in reply to Re^3: Decoding Base32
in thread Decoding Base32

That would be an intelligent first guess ...

The code used is the code posted above. The only modifications I've done are attempting to add (and remove) lc and unpack functions within the decode_base32 to condition the data properly. I am not completely confident in my understanding of unpack, but one such attempt looked like:

print "SHA1: " . udecode_base32(unpack('H32', $urn_decode)) . "\n";

As for example data, I simply grabbed a SHA-1 of a zip file using md5deep. That was converted to base32 using both this script and BitCollider 1 provided by bitzi.com.

SHA-1: 58d18761f662f8cb4cf26de2f82f1b5c6e9a9857
SHA-1 Base32: LDIYOYPWML4MWTHSNXRPQLY3LRXJVGCX

1 http://bitzi.com/bitcollider

Replies are listed 'Best First'.
Re^5: Decoding Base32
by ikegami (Patriarch) on Apr 19, 2010 at 16:15 UTC

    Assuming udecode_base32 should be decode_base32, why are you passing a hex string to it?

    Update: Ah, you want to convert the SHA to hex, but that's now what you're doing. Fix:

    print "SHA1: " . unpack('H*', decode_base32($urn_decode)) . "\n";

      You are correct, I had meant decode_base32. And, yes, I'm trying to get back to hex as I need to be able to verify the hashes of downloads.

      I knew this must be fairly trivial as I appear to be the only one needing help. I should have caught my encapsulation was incorrect. Apparently decode_base32 still expects all lowercase characters; at least my version does.

      All that said, I'm in good working order now. I really appreciate your time and help ikegami.

        Acceptance of uc was added to 0.03. To have older versions accept uc:
        print "SHA1: " . unpack('H*', decode_base32(lc($urn_decode))) . "\n";