PHP Source Code Analysis DZX1.5 Cryptographic decryption function Authcode Usage _php tutorial

Source: Internet
Author: User

PHP source code Analysis of DZX1.5 cryptographic decryption function Authcode usage


This article describes the PHP source code Analysis of the DZX1.5 cryptographic decryption function Authcode usage. Share to everyone for your reference. The specific analysis is as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

$authkey = ";

/**

* @param string $string: Input plaintext (or ciphertext) that needs to be encrypted (or decrypted)

* @param string $operation: ' DECODE ' or other, where the default is to decrypt, input other means to encrypt

* @param string $key: Add decryption key

* @param int $expiry: expiry date

*/

function Authcode ($string, $operation = ' DECODE ', $key = ", $expiry = 0) {

Global $authkey;

$ckey _length = 4;

$key = MD5 ($key! = "? $key: $authkey);

$keya = MD5 (substr ($key, 0, 16));

$KEYB = MD5 (substr ($key, 16, 16));

$KEYC = $ckey _length? ($operation = = ' DECODE '? substr ($string, 0, $ckey _length): substr (MD5 (Microtime ()),-$ckey _length)): ";

$cryptkey = $keya. MD5 ($keya. $KEYC);

$key _length = strlen ($cryptkey);

$string = $operation = = = ' DECODE '? Base64_decode (substr ($string, $ckey _length)): sprintf ('%010d ', $expiry? $expiry + Time (): 0). substr (MD5 ($string. $keyb ), 0, (+). $string;

$string _length = strlen ($string);

$result = ";

$box = Range (0, 255);

$rndkey = Array ();

for ($i = 0; $i <= 255; $i + +) {

$rndkey [$i] = Ord ($cryptkey [$i% $key _length]);

}

for ($j = $i = 0; $i < $i + +) {

$j = ($j + $box [$i] + $rndkey [$i])% 256;

$tmp = $box [$i];

$box [$i] = $box [$j];

$box [$j] = $tmp;

}

for ($a = $j = $i = 0; $i < $string _length; $i + +) {

$a = ($a + 1)% 256;

$j = ($j + $box [$a])% 256;

$tmp = $box [$a];

$box [$a] = $box [$j];

$box [$j] = $tmp;

$result. = Chr (ord ($string [$i]) ^ ($box [($box [$a] + $box [$j])% 256]));

}

if ($operation = = ' DECODE ') {

if (substr ($result, 0, ten) = = 0 | | substr ($result, 0,)-time () > 0) && substr ($result, ten, +) = = SUBSTR (MD 5 (substr ($result, +). $keyb), 0, 16)) {

Return substr ($result, 26);

} else {

Return ';

}

} else {

Return $KEYC. Str_replace (' = ', ' ', Base64_encode ($result));

}

}

$STR = ' 1234 ';

$key = ' 1234 ';

echo "Clear text:". $str;

echo "
";

echo "key:". $key;

$encode = Authcode ($str, ' one ', $key);

echo "
";

echo "Ciphertext after encryption:" $ENCODE;

echo "
";

$decode = Authcode ($encode, ' decode ', $key);

echo "decrypted plaintext:". $decode;

/*end of php*/

The results of the operation are as follows:

PlainText: 1234

Key: 1234

Ciphertext after encryption: A52F67EXZGVY0HTQBO4VOREHQ3WXNL6E2ZLX75JGFOJW

Decrypted plaintext: 1234

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1018379.html www.bkjia.com true http://www.bkjia.com/PHPjc/1018379.html techarticle PHP Source Code Analysis of the DZX1.5 cryptographic decryption function Authcode Usage This article describes the PHP source code analysis of DZX1.5 cryptographic decryption function Authcode usage. Share to everyone for your reference. Specific analysis ...

  • 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.