On Dec 17, 2007 11:22 PM, Casey <[EMAIL PROTECTED]> wrote:
>
> On Dec 17, 2007 7:06 PM, Grace Shibley <[EMAIL PROTECTED]> wrote:
> > Hi Everyone,
> >
> > We have an encryption function that was written in another language that we
> > needed translated to PHP.
> >
> > Here's the function:
> >
> > function rc4 pText, pKey
> > -- initialize
> > repeat with i = 0 to 255
> > put i into S1[i]
> > end repeat
> >
> > put 0 into i
> > repeat with n = 0 to 255
> > add 1 to i
> > if i > length(pkey) then put 1 into i
> > put chartonum(char i of pKey) into S2[n]
> > end repeat
> >
> > put 0 into j
> > repeat with i = 0 to 255
> > put (j + S1[i] + S2[i]) mod 256 into j
> > put S1[i] into temp
> > put S1[j] into S1[i]
> > put temp into S1[j]
> > end repeat
> >
> > -- encrypt/decrypt
> > put 0 into i ; put 0 into j
> > repeat for each char c in pText
> > put chartonum(c) into tChar
> >
> > put (i + 1) mod 256 into i
> > put (j + S1[i]) mod 256 into j
> > put S1[i] into temp
> > put S1[j] into S1[i]
> > put temp into S1[j]
> > put (S1[i] + S1[j]) mod 256 into t
> > put S1[t] into K
> >
> > put numtochar(tChar bitXor K) after tOutput
> > end repeat
> >
> > return tOutput
> > end rc4
> >
> > Can anyone help us with this? We don't mind paying via PayPal :)
> >
> > Thanks!
> > grace
> >
>
> function rc4($pText, $pKey) {
> // initialize
> $S1 = range(0, 255);
> $S2 = array();
>
> $i = 0;
> for ($n=0; $n<=255; $n++) {
> $i++;
> if ($i > strlen($pkey))
> $i = 1;
> $S2[] = ord($pKey[$i]);
> }
>
> $j = 0;
> for ($i=0; $i<=255; $i++) {
> $j = ($j + $S1[$i] + $S2[$i]) % 256;
> $temp = $S1[$i];
> $S1[$i] = $S1[$j];
> $S1[$j] = $temp;
> }
>
> // encrypt/decrypt
> $i = $j = 0;
> $tOutput = '';
>
> foreach (str_split($pText) as $c) {
> $tChar = ord($c);
>
> $i = ($i+1) % 256;
> $j = ($j+$S1[$i]) % 256;
> $temp = $S1[$i];
> $S1[$i] = $S1[$j];
> $S1[$j] = $temp;
> $t = ($S1[$i] + $S1[$j]) % 256;
> $K = $S1[$t];
>
> $tOutput .= chr($tChar ^ $K);
> }
>
> return $tOutput;
> }
>
> I don't know what language this is. I'm curious -- what is it? It
> might not work; it's untested except for syntax errors.
That's written in Revolution. I just glanced at your translation,
Case, but it looks good with a (literally) two-second once-over.
--
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]
If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php