The principle of this encryption algorithm

Source: Internet
Author: User
Ask the php experts to see the principles of this encryption algorithm PHPcodefunctionsys_auth ($ str, $ actionencode, $ key) {$ keymd5 ($ key); $ str $ actionencode? $ Str: base64_decode ($ str); search for a php expert and check the principles of this encryption algorithm.
PHP code
  function sys_auth($str, $action = 'encode', $key = ''){    $key = md5($key);    $str = $action == 'encode' ? $str : base64_decode($str);            $strlen = strlen($str);        $keylen = strlen($key);        $code = '';    for($i = 0; $i < $strlen; $i++){        $k = $i % $keylen;        $code .= $str[$i] ^ $key[$k];    }    $code = $action == "decode" ? $code : base64_encode($code);    return $code;}


I echo the code in every sentence:

PHP code
  Function sys_auth ($ str, $ action = 'encoding', $ key = '') {$ key = md5 ($ key); echo'
$ Key: '. $ key; $ str = $ action = 'encoding '? $ Str: base64_decode ($ str); echo'
$ Str: '. $ str; $ strlen = strlen ($ str); echo' of the encryption method'
$ Str length '. $ strlen; $ keylen = strlen ($ key); echo'
$ Keylen length '. $ keylen; $ code = ''; for ($ I = 0; $ I <$ strlen; $ I ++) {$ k = $ I % $ keylen; echo"
No ". $ I. "The \ $ k value of the next loop is ". $ k; $ code. = $ str [$ I] ^ $ key [$ k]; echo"
The ". $ I. 'Round Robin $ k value is'. $ k; echo"
The ". $ I. 'loop $ str [$ I] value is'. $ str [$ I]; echo"
The value of the ". $ I. 'Round Robin $ key [$ k] is'. $ key [$ k]; echo"
The value of ". $ I." The \ $ code of the next loop is ". $ code ."




";}$ Code = $ action =" decode "? $ Code: base64_encode ($ code); echo"
". $ Code; return $ code;}: [code = PHP] $ key: c81e728d9d4c2f636f067f89cc14862c $ str: 123456 $ str length 6 $ keylen length 32 0th cycles $ k value is 0 0th cycles $ k is 0 0th cycles $ str [$ I] value is 1 0th times loop $ key [$ k] value is c 0th cycles $ code value is R 1st cycles $ k value is 1 1st cycles $ k is 1 1st cycles $ str [$ I] is set to 2 1st cycles. $ key [$ k] is set to 8 1st cycles. $ code is set to R 2nd Cycles. $ k is set 2 2nd Cycles $ k is 2 2nd Cycles $ str [$ I] value is 3 2nd Cycles $ key [$ k] value is the value of $ code for 1 2nd cycles the value of $ k for R 3rd cycles is 3 3rd cycles $ k is 3 3rd cycles $ str [$ I] the value of $ key [$ k] is 4 3rd cycles. the value is the value of $ code in e 3rd cycles. The value of $ k in r q 4th cycles is 4 4th cycles. The value of $ k is 4 4th cycles. $ str [$ I] the value is 5 4th cycles. $ key [$ k] and the value is 7 4th cycles. $ code is the value of r q 5th cycles. $ k is the value of 5 5th cycles. $ k value is 5 5th cycles $ str [$ I] value is 6 5th cycles $ key [$ k] value is 2 5th cycles $ code value is R QUgoCUQIE encrypted: ugoCUQIE

[/Code]

The problem is: the value of $ str [0] for 0th cycles is 1, and the value of $ key [0] is c.
I directly follow the above $ str [0] ^ $ key [0], (that is, 1 ^ 0), but an error is reported. what is the problem, in addition, $ str [0] ^ $ key [0] does not understand

------ Solution --------------------
Manual, operator

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.