Code em Perl que demostra como Encriptar e Desencriptar.
sub ASCII_to_Custom
{
my $length = length( $_[0] );
my @chars = split( //, $_[0] );
my $encoded;
foreach ( @chars )
{
$length++;
my $t_c = ord( $_ ) + $length;
while( $t_c > 126 )
{
$t_c -= 94;
}
$encoded .= chr( $t_c );
}
return $encoded;
}
sub Custom_to_ASCII
{
my $text = $_[0];
my $length = length( $text );
my @chars = split( //, $text );
my $decoded;
foreach ( @chars )
{
$length++;
my $t_c = ord( $_ ) - $length;
while( $t_c > 126 )
{
$t_c += 92;
}
$decoded .= chr( $t_c );
}
return $decoded;
}
{
my $length = length( $_[0] );
my @chars = split( //, $_[0] );
my $encoded;
foreach ( @chars )
{
$length++;
my $t_c = ord( $_ ) + $length;
while( $t_c > 126 )
{
$t_c -= 94;
}
$encoded .= chr( $t_c );
}
return $encoded;
}
sub Custom_to_ASCII
{
my $text = $_[0];
my $length = length( $text );
my @chars = split( //, $text );
my $decoded;
foreach ( @chars )
{
$length++;
my $t_c = ord( $_ ) - $length;
while( $t_c > 126 )
{
$t_c += 92;
}
$decoded .= chr( $t_c );
}
return $decoded;
}
Comment