#!/usr/bin/perl # (C) SYN-ACK.org - 2005 # # Perl URL encoder/decoder put together by rastakid. # Converts hex URLs to dec, and vice versa. # # Almost all the credit should go to Glenn Fleishman (http://glennf.com/writing/hexadecimal.url.encoding.html), # all I did was putting his code examples together and adding a user interface. $|=1; print "Enter URL: "; $url = ; chomp($url); while ($encdec ne "E" and $encdec ne "e" and $encdec ne "D" and $encdec ne "d") { print "Do you want to [E]ncode or [D]ecode: "; $encdec = ; chomp($encdec); } if ($encdec eq "E" or $encdec eq "e") { print URLEncode($url) . "\n"; } elsif ($encdec eq "D" or $encdec eq "d") { print URLDecode($url) . "\n"; } sub URLDecode { my $theURL = $_[0]; $theURL =~ tr/+/ /; $theURL =~ s/%([a-fA-F0-9]{2,2})/chr(hex($1))/eg; $theURL =~ s///g; return $theURL; } sub URLEncode { my $theURL = $_[0]; $theURL =~ s/([\W])/"%" . uc(sprintf("%2.2x",ord($1)))/eg; return $theURL; }