quocvuongdn icon

#PHP: #RC4 + Base64

quocvuongdn | PRO | 12/26/14 02:51:31 AM UTC | 0 ⭐ | 523 👁️ | Never ⏰ | []
PHP |

720 B

|

None

|

0 👍

/

0 👎

function rc4($pt, $key) {
    $s = array();
    for ($i=0; $i<256; $i++) {
        $s[$i] = $i;
    }
    $j = 0;
    $x = null;
    for ($i=0; $i<256; $i++) {
        $j = ($j + $s[$i] + ord($key[$i % strlen($key)])) % 256;
        $x = $s[$i];
        $s[$i] = $s[$j];
        $s[$j] = $x;
    }
    $i = 0;
    $j = 0;
    $ct = '';
    $y = null;
    for ($y=0; $y<strlen($pt); $y++) {
        $i = ($i + 1) % 256;
        $j = ($j + $s[$i]) % 256;
        $x = $s[$i];
        $s[$i] = $s[$j];
        $s[$j] = $x;
        $ct .= $pt[$y] ^ chr($s[($s[$i] + $s[$j]) % 256]);
    }
    return $ct;
}
function encrypt_data($input, $key_seed) {
    $bin = rc4($input, $key_seed);
    return base64_encode($bin);
}
 
function decrypt_data($input, $key_seed) {
    $bin = base64_decode($input);
    return rc4($bin, $key_seed);
}

Comments