Cynric has asked for the wisdom of the Perl Monks concerning the following question:

I'm using ActivePerl and pulled in Convert::Base32 using their PPM graphical tool. The entire issue derives from being able to decode/encode the URN:SHA1 strings used in Limewire.

Taking a SHA1 and encoding it to Base32 works just fine. However, I can't seem to take a Base32 encoding of a SHA1 and decode it. Any help would be greatly appreciated.

The encode part is based off of "Magnet URI Redirect Service" (1). Adding a comparable unpack to the decode function does not work either. Thanks again.

(1) http://magnet.pixelcort.com/
#!/usr/bin/env perl use strict; use warnings; use Switch; use Convert::Base32; # Prompt user on which action they wish to take print "[D]ecode or [E]ncode URN (default = D): "; chomp (my $urn_format = <>); # Execute appropriate function switch (uc($urn_format)) { case "" { &urnDecode } case "D" { &urnDecode } case "E" { &urnEncode } else {print "Invalid option. Enter \"D\" to decode or \"E\" to enc +ode."} } # Convert URN:SHA1 (base32) values to standard SHA1 (base16) sub urnDecode { print "\nEnter URN to decode: "; chomp (my $urn_decode = <>); print "SHA1: " . decode_base32($urn_decode) . "\n"; } # Convert SHA1 (base16) values to URN:SHA1 (base32) sub urnEncode { print "\nEnter SHA1 to encode: "; chomp (my $urn_encode = <>); print "urn:sha1:" . uc(encode_base32(pack('H40', $urn_encode))) . +"\n"; } exit 0;

Replies are listed 'Best First'.
Re: Decoding Base32
by ikegami (Patriarch) on Dec 23, 2009 at 20:22 UTC
      Ahah. Ok, that would explain it. I'll check it out. Thanks for the information.
Re: Decoding Base32
by ikegami (Patriarch) on Jan 07, 2010 at 17:04 UTC
    Fixed in 0.03
Re: Decoding Base32
by Anonymous Monk on Apr 19, 2010 at 14:52 UTC
    I am attempting to use this to batch convert base32 SHA-1 hashes without much luck. The posted urnDecode gives the standard "Data contains non-base32 characters." Any ideas on what would need to be done to fix it? According to the module, decode_base32 performs a lc(). I've tried tossing in a lc() and an unpack(H32,) without any luck.
      I should clarify, my lc() and unpack were placed inside decode_base32() in different variations to get the data to line up.

        Maybe you want to show some code, and some sample data in addition to the error message? From a first guess, I would say that your data contains non-base32 characters.