Un codificador con las sig opciones
- Hex
- SHA1
- MD5
- Base64
- ASCII
- URL
Imagen
(http://doddyhackman.webcindario.com/images/code.jpg)
#!usr/bin/perl
#Codificator (C) Doddy Hackman 2011
use Tk;
use Digest::MD5;
use Digest::SHA1;
use MIME::Base64;
use URI::Escape;
if ($^O eq 'MSWin32') {
use Win32::Console;
Win32::Console::Free();
}
$header= "This tool encode text in :
Hex
SHA1
MD5
Base64
ASCII
URL
";
$window = MainWindow->new(-background=>"black",-foreground=>"white");
$window->geometry("500x500+80+80");
$window->title("Codificator (C) Doddy Hackman 2011");
$window->resizable(0,0);
$window->Label(-background=>"black",-foreground=>"white",-font=>"Impact",-text=>"Codificator")->pack();
$window->Label(-background=>"black",-foreground=>"white")->pack();
$window->Label(-background=>"black",-foreground=>"white")->pack();
$window->Label(-background=>"black",-foreground=>"white",-text=>"Code")->place(-x =>180, -y => 70);
$window->Optionmenu(-background=>"black",-foreground=>"white",-activebackground=>'white',
-options => [[HEX=>HEX], [ASCII=>ASCII], [BASE64=>BASE64], [MD5=>MD5],[SHA1=>SHA1],[URL=>URL]],
-variable => \$var,
-textvariable => \$codificacion
)->place(-x =>220, -y => 70);
my $rot = $window->Text(-background=>"black",-foreground=>"white",-width=> 45,-height=> 15)->place(-x =>90, -y => 150);
$window->Button(-text=>"Encode",-background=>"black",-foreground=>"white",-activebackground=>"white",-command=>\&encode,-width=>"10")->place(-x =>12, -y => 170);
$window->Button(-text=>"Decode",-background=>"black",-foreground=>"white",-activebackground=>"white",-command=>\&decode,-width=>"10")->place(-x =>12, -y => 200);
$window->Button(-text=>"Clear",-background=>"black",-foreground=>"white",-activebackground=>"white",-command=>\&clear,-width=>"10")->place(-x =>420, -y => 170);
$window->Button(-text=>"About",-background=>"black",-foreground=>"white",-activebackground=>"white",-command=>\&about,-width=>"10")->place(-x =>420, -y => 200);
$window->Button(-text=>"Exit",-background=>"black",-foreground=>"white",-activebackground=>"white",-command=>[$window=>'destroy'],-width=>"10")->place(-x =>420, -y => 230);
$window->Label(-background=>"black",-foreground=>"white",-text=>"Copyright 2011 Doddy Hackman",-font=>"Impact")->place(-x =>150, -y => 430);
$rot->insert('end',$header);
MainLoop;
sub about {
my $venta = MainWindow->new(-background=>"black");
$venta->geometry("300x180+20+20");
$venta->title("About");
$venta->resizable(0,0);
$venta->Label(-font=>"Impact",-text=>"\nCodificator",-background=>"black",-foreground=>"white")->pack();
$venta->Label(-text=>"\nProgrammer : Doddy Hackman\n\nContact : lepuke[at]hotmail[com]\n\n",-background=>"black",-foreground=>"white")->pack();
$venta->Button(-text=>"Exit",-foreground=>"white",-background=>"black",-command => [$venta => 'destroy'],-activebackground=>'white',-width=>"20")->pack()
}
sub clear {
$rot->delete('0.1','end');
}
sub encode {
$text = $rot->get("1.0", "end");
chomp $text;
&clear;
if ($codificacion eq "HEX") {
$result = hexar($text);
$rot->insert('end',$result);
print $result;
}
elsif ($codificacion eq "SHA1") {
$sha1 = Digest::SHA1->new->add($text);
my $digest = $sha1->digest;
$rot->insert('end',$digest);
}
elsif ($codificacion eq "BASE64") {
$result = encode_base64($text);
$rot->insert('end',$result);
}
elsif ($codificacion eq "URL") {
my $codec = Badger::Codec::URL->new();
my $ya = $codec->encode($text);
$rot->insert('end',$ya);
}
elsif ($codificacion eq "ASCII") {
$result = ascii($text);
$rot->insert('end',$result);
}
elsif ($codificacion eq "MD5") {
$digest = Digest::MD5->md5_hex($text);
$rot->insert('end',$digest);
}
else {
$window->messageBox(-message=>"What?!\n");
}}
sub decode {
$text = $rot->get("1.0", "end");
chomp $text;
&clear;
if ($codificacion eq "HEX") {
$result = decodera($text);
$rot->insert('end',$result);
}
elsif ($codificacion eq "SHA1") {
$window->messageBox(-message=>"What?! , it's not possible with a function decoded\n");
}
elsif ($codificacion eq "BASE64") {
$result = decode_base64($text);
$rot->insert('end',$result);
}
elsif ($codificacion eq "URL") {
my $codec = Badger::Codec::URL->new();
my $ya = $codec->decode($text);
$rot->insert('end',$ya);
}
elsif ($codificacion eq "ASCII") {
$result = ascii_de($text);
$rot->insert('end',$result);
}
elsif ($codificacion eq "MD5") {
$window->messageBox(-message=>"What?! , it's not possible with a function decoded\n");
}
else {
$window->messageBox(-message=>"What?!\n");
}}
sub hexar {
my $string = $_[0];
$hex = '0x';
for (split //,$string) {
$hex .= sprintf "%x", ord;
}return $hex;}
sub ascii {
return join ',',unpack "U*",$_[0];
}
sub decodera {
$_[0] =~ s/^0x//;
$encode = join q[], map { chr hex } $_[0] =~ /../g;
return $encode;
}
sub ascii_de {
$_[0] = join q[], map { chr } split q[,],$_[0];
return $_[0];
}
# ¿ The End ?