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;

In reply to Decoding Base32 by Cynric

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.