Alright, so I'm just trying to get a working version of RC4 encryption for use on my website. I wanted to use Crypt::RC4, but my host is GoDaddy and it's not supported. So I've been ruthlessly scrawling the internet looking for ways, and I came across 3. One was a rip of the Crypt::RC4 module and the other 2 were some sort of homebrew scripts. Anyway, neither of them work. I have a Javascript port of the RC4 algorithm, and my input key and encrypted data are decrypted flawlessly every time. However in all of these Perl versions, the decrypted key is garbled gibberish. Here's the most recent code I found:
With my key and data, it returns:
What the heck am I supposed to do with that? I've been working on this for HOURS and I haven't found a viable solution. I am really frustrated, so any help you can offer would really make my day.
Code:
sub encrypt {
my ($pwd, $data) = @_;
@key;
@box;
$cipher = '';
$pwd_length = length($pwd);
$data_length = length($data);
for ($i = 0; $i < 256; $i++)
{
$key[$i] = ord($pwd[$i % $pwd_length]);
$box[$i] = $i;
}
for ($j = $i = 0; $i < 256; $i++)
{
$j = ($j + $box[$i] + $key[$i]) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
}
for ($a = $j = $i = 0; $i < $data_length; $i++)
{
$a = ($a + 1) % 256;
$j = ($j + $box[$a]) % 256;
$tmp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $tmp;
$k = $box[(($box[$a] + $box[$j]) % 256)];
$cipher .= chr(ord($data[$i]) ^ $k);
}
return $cipher;
}
sub decrypt {
my ($pwd, $data) = @_;
return encrypt($pwd, $data);
}
Code:
Þ‰A£7]:ŠgWn’mÇ£ðÌë—E+M2'–_ž¨ÌumŸ¹ÅAz¥Ë0ü"‹4˜-»bžÀKO‹ qP’ ÃXJHä£ 9{ŠÍžÈ}hò,ôœ£å“T¹E5¢z†BlÊ}^‚>ºDgW¸Ø`®L½LI»Å5ïáXÛ3•\ÛË›õ?