summaryrefslogtreecommitdiffstats
path: root/pintos-progos/tests/arc4.pm
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
committermanuel <manuel@mausz.at>2012-03-26 12:54:45 +0200
commitb5f0874cd96ee2a62aabc645b9626c2749cb6a01 (patch)
tree1262e4bbe0634de6650be130c36e0538240f4cbf /pintos-progos/tests/arc4.pm
downloadprogos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.gz
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.bz2
progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.zip
initial pintos checkin
Diffstat (limited to 'pintos-progos/tests/arc4.pm')
-rw-r--r--pintos-progos/tests/arc4.pm29
1 files changed, 29 insertions, 0 deletions
diff --git a/pintos-progos/tests/arc4.pm b/pintos-progos/tests/arc4.pm
new file mode 100644
index 0000000..df19216
--- /dev/null
+++ b/pintos-progos/tests/arc4.pm
@@ -0,0 +1,29 @@
1use strict;
2use warnings;
3
4sub arc4_init {
5 my ($key) = @_;
6 my (@s) = 0...255;
7 my ($j) = 0;
8 for my $i (0...255) {
9 $j = ($j + $s[$i] + ord (substr ($key, $i % length ($key), 1))) & 0xff;
10 @s[$i, $j] = @s[$j, $i];
11 }
12 return (0, 0, @s);
13}
14
15sub arc4_crypt {
16 my ($arc4, $buf) = @_;
17 my ($i, $j, @s) = @$arc4;
18 my ($out) = "";
19 for my $c (split (//, $buf)) {
20 $i = ($i + 1) & 0xff;
21 $j = ($j + $s[$i]) & 0xff;
22 @s[$i, $j] = @s[$j, $i];
23 $out .= chr (ord ($c) ^ $s[($s[$i] + $s[$j]) & 0xff]);
24 }
25 @$arc4 = ($i, $j, @s);
26 return $out;
27}
28
291;