以下 perl 代码将基于上述内容进行加密/解密。不是最优雅或最紧凑的代码,但它有效。
use Readonly;
Readonly my @nxseq => ( 3, 22, 4, 5, 18, 0, 21, 5, 18, 3, 10, 5, 16, 22, 4, 16, 24, 17, 12, 5, 21, 18, 5, 22, 19, 7 );
sub encrypt_nxos7 {
my $ep = shift;
my $dp = '';
for ( my $i = 0; $i < length($ep); $i += 1 ) {
my $char_p = substr( $ep, $i, 1 );
if ( $char_p =~ /[a-z]/ ) {
my $ord = ord($char_p);
$ord -= 97;
$ord += $nxseq[$i];
$ord = $ord % 26;
$ord += 97;
$dp .= chr($ord);
}
elsif ( $char_p =~ /[A-Z]/ ) {
my $ord = ord($char_p);
$ord -= 65;
$ord += $nxseq[$i];
$ord = $ord % 26;
$ord += 65;
$dp .= chr($ord);
}
else {
$dp .= $char_p;
}
}
return $dp;
}
sub decrypt_nxos7 {
my $ep = shift;
my $dp = '';
for ( my $i = 0; $i < length($ep); $i += 1 ) {
my $char_p = substr( $ep, $i, 1 );
if ( $char_p =~ /[a-z]/ ) {
my $ord = ord($char_p);
$ord -= 97;
$ord -= $nxseq[$i];
$ord += 26 if ( $ord < 0 );
$ord += 97;
$dp .= chr($ord);
}
elsif ( $char_p =~ /[A-Z]/ ) {
my $ord = ord($char_p);
$ord -= 65;
$ord -= $nxseq[$i];
$ord += 26 if ( $ord < 0 );
$ord += 65;
$dp .= chr($ord);
}
else {
$dp .= $char_p;
}
}
return $dp;
}