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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |