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 | |
by Cynric (Initiate) on Dec 23, 2009 at 21:03 UTC | |
|
Re: Decoding Base32
by ikegami (Patriarch) on Jan 07, 2010 at 17:04 UTC | |
|
Re: Decoding Base32
by Anonymous Monk on Apr 19, 2010 at 14:52 UTC | |
by Anonymous Monk on Apr 19, 2010 at 14:53 UTC | |
by Corion (Patriarch) on Apr 19, 2010 at 14:57 UTC | |
by Anonymous Monk on Apr 19, 2010 at 15:09 UTC | |
by ikegami (Patriarch) on Apr 19, 2010 at 16:15 UTC | |
|