#!/usr/local/bin/perl
#
# @(#) $Id: bin2hex.pl,v 1.9 1999/03/02 13:17:53 jaalto Exp $
# @(#) Perl -- FILE, Convert binary file to hex dump
#
# File id
#
# .Copyright (C) 1998-1999 Jari Aalto
# .Created: 1998-05
#.Contactid:<jari.aalto@poboxes.com>
#.Keywords:Perl file conversion bin hex
#.Url:http://www.netforward.com/poboxes/?jari.aalto
I think it's here. [planet-source-code.com]
Onya
Woz
#!/usr/local/bin/perlprint "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<title>Convert Text to HEX</title>\n";
print "</head>\n";
print "<body>\n";
print "<font color=\"#000030\" face=\"Arial\" size=\n";
print "\"3\"><b>Convert Text to HEX</b>\n";
print "<p><br></p>\n";
if ($ENV{'CONTENT_LENGTH'}) {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
$input = $FORM{'message'};
@tmp_array = unpack("C*",$input);
print "<font color=\"#000030\" face=\"Arial\" size=\"2\"><b>Answer: </b>";
foreach $i (@tmp_array) {
$key = sprintf("%lx",$i);
$output = "\%$key";
print $output;
}
$input =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
}
else {
$input = "Enter text here.";
}
print "</font>\n\n";
print "<form method=\"post\" action=\"/cgi-bin/hex.pl\">\n";
print "<textarea cols=\"65\" rows=\"5\" name=\"message\">$input</textarea><br>\n";
print "<input type=\"submit\" value=\"Convert to HEX\" style=\n";
print "\"background: #000033; color: #FFFFFF; font-family: 'Arial', sans-serif; font-weight:bold; font-size: 8pt\">\n";
print "</form>\n";
print "</body>\n";
print "</html>\n";
exit;
There is bintohex.pl and hextobin.pl (they do just the opposite). I can not find bintohex.pl on that site I mentioned above.
(sidebar: that side [planet-source-code] is a disgrace and embarassment to all programmers. I was just on a page that had 4700 html errors)