#!/usr/bin/perl -s
# coded by Oromis92
# <nicolabbi@libero.it>
$key = shift or die "usage: perl $0 [-d] <key> [infile [>> outfile]]\n
+";
while (<>) {
$plain .= $_;
}
chomp($plain);
@key = split //,$key;
@plain = split //,$plain;
@key = map(ord, @key);
@S = 0..255;
foreach $i (0..255) {
$K[$i]=$key[$i%($#key+1)];
}
sub KSA {
$j=0;
for ($i=0;$i<255;$i++){
$j = ($j + $S[$i] + $K[$i])%256;
$temp = $S[$i];
$S[$i] = $S[$j];
$S[$j] = $temp;
}
}
sub PRGA {
$i = 0;
$j = 0;
for ($count=0;$count<length($plain);$count++) {
$i = ($i + 1)%256;
$j = ($j + $S[$i])%256;
$temp = $S[$i];
$S[$i] = $S[$j];
$S[$j] = $temp;
$t = ($S[$i] + $S[$j])%256;
if (!$d) {
$output = sprintf('%X', ($S[$t] ^ ord($plain[$count])));
if (length($output) % 2 == 0) {
$result .= $output;
} else {
$output .= "0" ;
$result .= $output;
$output = "";
}
} else {
if ($count*2 < length($plain)) {
$output = chr($S[$t] ^ (hex(substr($plain,($count*2),2
+))));
$result .= $output;
$output = "";
}
}
}
print "$result\n";
}
KSA;
PRGA;
In reply to ARC4
by Oromis92
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|