quocvuongdn

#PHP: #RC4 + Base64

Dec 25th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. function rc4($pt, $key) {
  2.     $s = array();
  3.     for ($i=0; $i<256; $i++) {
  4.         $s[$i] = $i;
  5.     }
  6.     $j = 0;
  7.     $x = null;
  8.     for ($i=0; $i<256; $i++) {
  9.         $j = ($j + $s[$i] + ord($key[$i % strlen($key)])) % 256;
  10.         $x = $s[$i];
  11.         $s[$i] = $s[$j];
  12.         $s[$j] = $x;
  13.     }
  14.     $i = 0;
  15.     $j = 0;
  16.     $ct = '';
  17.     $y = null;
  18.     for ($y=0; $y<strlen($pt); $y++) {
  19.         $i = ($i + 1) % 256;
  20.         $j = ($j + $s[$i]) % 256;
  21.         $x = $s[$i];
  22.         $s[$i] = $s[$j];
  23.         $s[$j] = $x;
  24.         $ct .= $pt[$y] ^ chr($s[($s[$i] + $s[$j]) % 256]);
  25.     }
  26.     return $ct;
  27. }
  28. function encrypt_data($input, $key_seed) {
  29.     $bin = rc4($input, $key_seed);
  30.     return base64_encode($bin);
  31. }
  32.  
  33. function decrypt_data($input, $key_seed) {
  34.     $bin = base64_decode($input);
  35.     return rc4($bin, $key_seed);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment