ist ein wenig länger
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl
use strict;
use warnings;
my @Chars = ('a'..'z', 0..9);
my %IndexToADFGVX = (0, 'A', 1, 'D', 2, 'F', 3, 'G', 4, 'V', 5, 'X');
sub gen_keymix {
my @mixed = @Chars;
for(my $i = scalar @mixed; $i > 1;) {
my $r = int(rand($i--));
($mixed[$i], $mixed[$r]) = ($mixed[$r], $mixed[$i]);
}
return @mixed;
}
sub gen_keytable {
my (@mixed) = @_;
my %table = ();
for my $row (0 .. 5) {
for my $col (0 .. 5) {
$table{shift @mixed} = $IndexToADFGVX{$row}.$IndexToADFGVX{$col};
}
}
return %table;
}
sub adfgvx_crypt {
my ($table, $data) = @_;
my $result = join "", map {
$table->{$_},
} split //, $data;
return $result;
}
my @key = &gen_keymix;
my %tab = &gen_keytable(@key);
print adfgvx_crypt(\%tab, 'aperlhacker');
\n\n
<!--EDIT|esskar|1122162391-->