The problem of exclusive or operation on bytes after phpmd5 is encrypted

Source: Internet
Author: User
The problem of exclusive or operation on bytes after phpmd5 is encrypted $ string = "! & 22E2 &! '& 5aSJ ^ # $ & 6 <&! & () PR49} I & dh111111 ";
$ Md5 = md5 ("0e2c83d839c026a5e05303167feb90". md5 ($ string, true), true );
Performs an exclusive or operation on the 16-bit binary bytes returned after md5 encryption.
$ Data = array ();
$ Data [0] = "0 ";
For ($ I = 0; $ I <strlen ($ md5); $ I ++ ){
$ Data [$ I % 4 + 1] ^ = $ md5 [$ I];
}
Then an integer is obtained.
$ Val = 0;
$ Val = $ bytes [$ data + 1] & 0xff;
$ Val <= 8;
$ Val | = $ bytes [$ data + 2] & 0xff;
$ Val <= 8;
$ Val | = $ bytes [$ data + 3] & 0xff;
$ Val <= 8;
$ Val | = $ bytes [$ data + 4] & 0xff;
Echo $ val;
Why is the returned value incorrect? Is there an error? Please advise


Reply to discussion (solution)

You should be clear about what you want to do, that is, what is your correct logic. And your code itself has syntax error. I didn't see what you were trying to do.

Thanks for answering, my goal is to make an exception or get a long integer for every eight bits after md5 encryption.

If you say the result is incorrect, what is the correct value?
You only gave the code snippet and cannot test it.

Thanks for answering, my goal is to make an exception or get a long integer for every eight bits after md5 encryption.



1. md5 is not called encryption http://zh.wikipedia.org/wiki/MD5
2. your description does not provide more information than the comments in your code. Please describe it like a programmer. For example, if you say that every eight bits do an exclusive or exclusive operator or a binary operator, then it is different from who.
3. as described above, if you think there is a problem with the implementation, please provide a normal output for the input.
4. check my first reply. check your code and write it as a runable version. only the part related to the problem is retained. no syntax error is allowed even if there is a logical error.

If you say the result is incorrect, what is the correct value?
You only gave the code snippet and cannot test it.


This often explains why there are more and more programmers in China, and these once-established Chinese technology communities have all fallen.
If you do not need to ask questions again, you should block the number, and then find a document similar to "ask for wisdom", so that the banned person can read the recordings and send them to unseal them manually. A verification code sent to this person should be read in the recording to avoid cheating.
In the future, if you don't want to ask a question or mail this person's number, you can link his own recitation to the back of the question.

PS: How idle I am today.


Thanks for answering, my goal is to make an exception or get a long integer for every eight bits after md5 encryption.



1. md5 is not called encryption http://zh.wikipedia.org/wiki/MD5
2. your description does not provide more information than the comments in your code. Please describe it like a programmer. For example, if you say that every eight bits do an exclusive or exclusive operator or a binary operator, then it is different from who.
3. as described above, if you think there is a problem with the implementation, please provide a normal output for the input.
4. check my first reply. check your code and write it as a runable version. only the part related to the problem is retained. no syntax error is allowed even if there is a logical error.

Okay. thank you for your patience. I ran a piece of code in java and then ran a piece of code in php. but the results are indeed different. maybe my description is too vague. let's take a look at the code first.
Java code:

String data = "! & 22E2 &! '& 5aSJ ^ # $ & 6 <&! & () PR49} I & dh111111 ";
String apSecert = "0e2c83d839c026a5e0530da-7feb90 ";
ByteArrayOutputStream stream = new ByteArrayOutputStream ();
Stream. write (apSecert. getBytes ());
MessageDigest md5 = MessageDigest. getInstance ("MD5 ");
Md5.update (data. getBytes ());
Stream. write (md5.digest ());
Md5.update (stream. toByteArray ());
Byte [] md = md5.digest ();
Byte [] ret = new byte [5]; // The first byte is retained to 0 to prevent conversion to negative numbers. only the last four digits are used.
For (int I = 0; I <md. length; I ++)
{
Ret [I % 4 + 1] ^ = md [I];
}
System. out. println ("---------------" + new BigInteger (ret); ----- get an integer
}
Php code:
$ String = "! & 22E2 &! '& 5aSJ ^ # $ & 6 <&! & () PR49} I & dh111111 ";
$ Md5 = md5 ("0e2c83d839c026a5e05303167feb90". md5 ($ string, true), true );
$ Data = array ();
$ Data [0] = "0 ";
For ($ I = 0; $ I <strlen ($ md5); $ I ++ ){
$ Data [$ I % 4 + 1] ^ = $ md5 [$ I];
}
$ Val = 0;
$ Val = $ data [1] & 0xff;
$ Val <= 8;
$ Val | = $ data [2] & 0xff;
$ Val <= 8;
$ Val | = $ data [3] & 0xff;
$ Val <= 8;
$ Val | = $ data [4] & 0xff;
Echo $ val;

The final result is different: is it accurate? Or is there a problem with my code?
-Java: = 2676031167
Php := 16327680

Php code: the code I posted for the first time is indeed faulty. I will write it again.
$ String = "! & 22E2 &! '& 5aSJ ^ # $ & 6 <&! & () PR49} I & dh111111 ";
$ Md5 = md5 ("0e2c83d839c026a5e05303167feb90". md5 ($ string, true), true );
$ Data = array ();
$ Data [0] = "0 ";
For ($ I = 0; $ I <strlen ($ md5); $ I ++ ){
$ Data [$ I % 4 + 1] ^ = $ md5 [$ I];
}
$ Val = 0;
$ Val = $ data [1] & 0xff;
$ Val <= 8;
$ Val | = $ data [2] & 0xff;
$ Val <= 8;
$ Val | = $ data [3] & 0xff;
$ Val <= 8;
$ Val | = $ data [4] & 0xff;
Echo $ val;

Yes? Can you tell me where I am wrong? 100 RMB reward

The php running result is 16327680.
But the code you posted is 327680.

Yes, I wrote it wrong. it is 327680. I am not familiar with PHP, and the JAVA value is correct. I will also consider whether the PHP bitwise operation is different from the JAVA operation, is JAVA unicode encoded, causing a php bit operation error?

Write in this way

$string = "!&22E2&!'&5aSJ^#$&6<&!&()pR49}I&dh111111";$md5 = md5("0E2C83D839C026A5E0530100007FEB90".md5($string,true),true);$data =  array(0,0,0,0);for($i = 0; $i < strlen($md5); $i++){  $data[$i % 4 ] ^= ord($md5[$i]);}$val = 0; foreach($data as $v) $val = $val * 256 + $v;printf('%u', $val); //2676031167

Write in this way

$string = "!&22E2&!'&5aSJ^#$&6<&!&()pR49}I&dh111111";$md5 = md5("0E2C83D839C026A5E0530100007FEB90".md5($string,true),true);$data =  array(0,0,0,0);for($i = 0; $i < strlen($md5); $i++){  $data[$i % 4 ] ^= ord($md5[$i]);}$val = 0; foreach($data as $v) $val = $val * 256 + $v;printf('%u', $val); //2676031167


Thanks to the moderator, you are a master. I closed the post. how can I pay you?

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.