PHP implementation RC4 encryption Algorithm _php tutorial

Source: Internet
Author: User
Tags ord
PHP implements RC4 encryption algorithm, the decryption method of this algorithm is re-encryption once, can be restored

Copy to ClipboardWhat to refer to: [www.bkjia.com]/*
* RC4 encryption algorithm
* $pwd Key
* $data the data to be encrypted
*/
function RC4 ($pwd, $data)//$pwd key $data need to encrypt string
{
$key [] = "";
$box [] = "";

$pwd _length = strlen ($PWD);
$data _length = strlen ($data);

for ($i = 0; $i < $i + +)
{
$key [$i] = Ord ($pwd [$i% $pwd _length]);
$box [$i] = $i;
}

for ($j = $i = 0; $i <; $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;
}

http://www.bkjia.com/PHPjc/363949.html www.bkjia.com true http://www.bkjia.com/PHPjc/363949.html techarticle PHP implements the RC4 encryption algorithm, the decryption method of this algorithm is re-encryption once, you can restore the contents of the Copy to Clipboard reference: [www.veryhuo.com]/* * RC4 encryption Algorithm * $PWD key * ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.