WebQQ web page hash Encryption Algorithm PHP version

Source: Internet
Author: User
Tags hash ord strlen

Due to the recent severe mass mailing of QQ junk information, the official team chose to detail the implementation of some WebQQ functions. The POST value obtained from friends has an additional hash parameter.

This hash is encrypted in js.

Below is the js source code

The code is as follows: Copy code

<Script type = "text/javascript">
Function getHash (B, I ){
For (var a = I + "password error ",
S = "",
J = [];) if (s. length <= a. length ){
If (s + = B, s. length = a. length) break
} Else {
S = s. slice (0, a. length );
Break
    }  
For (var d = 0; d <s. length; d ++) j [d] = s. charCodeAt (d) ^ a. charCodeAt (d );
A = ["0", "1", "2", "3", "4", "5", "6", "7", "8 ", "9", "A", "B", "C", "D", "E", "F"];
S = "";
For (d = 0; d <j. length; d ++) s + = a [j [d]> 4 & 15],
S + = a [j [d] & 15];
Return s;
}
</Script>

Convert to PHP version for processing. The source code is as follows:

The code is as follows: Copy code
<? Php
/**
* The POST parameter Hash algorithm when obtaining friends
 *
* Public
* @ Param string $ qq number
* @ Param string $ ptwebqq in cookies
* @ Return string
*/
Function get_hash ($ qq, $ ptwebqq)
{
For ($ a = $ ptwebqq. "password error", $ s = "", $ j = array ();;)
 {
If (strlen ($ s) <= strlen ($ ))
  {
$ S. = $ qq;
If ($ s = strlen ($ a) break;
  }
Else
  {
$ S = substr ($ s, 0, strlen ($ ));
Break;
  }
 }
 
For ($ d = 0; $ d <strlen ($ s); $ d ++)
 {
$ J [$ d] = uniord (substr ($ s, $ d) ^ uniord (substr ($ a, $ d ));
 }
 
$ A = array ("0", "1", "2", "3", "4", "5", "6", "7 ", "8", "9", "A", "B", "C", "D", "E", "F ");
$ S = "";
For ($ d = 0; $ d <count ($ j); $ d ++)
 {
$ S. = $ a [$ j [$ d]> 4 & 15];
$ S. = $ a [$ j [$ d] & 15];
 }
 
Return $ s;
}
 
/**
* Simulate the JavaScript charCodeAt function
 *
* Protected
* @ Param string $ str
* @ Return int
*/
Function uniord ($ str)
{
List (, $ ord) = unpack ('N', mb_convert_encoding ($ str, 'ucs-4be ', 'utf-8 '));
 
Return

$ Ord;
}
 
/* End of file commons. php */

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.