Thread adfgvx-Verschluesselung umsetzen (10 answers)
Opened by DrWhiteLetter at 2005-07-24 00:53

esskar
 2005-07-24 03:46
#56642 #56642
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
ist ein wenig länger
Code: (dl )
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-->

View full thread adfgvx-Verschluesselung umsetzen