<?php
/**
* 将字符串按小端序拆分为 32 位无符号整数数组
*
* @param string $str 输入字符串
* @return array<int> 32 位无符号整数数组
*/
function strToUint32Array(string $str): array
{
$bytes = strlen($str); // 字节数
$words = (int) ceil($bytes / 4); // 所需的 32 位整数个数
$result = array_fill(0, $words, 0);
for ($i = 0; $i < $bytes; $i++) {
$byte = ord($str[$i]) & 0xFF; // 取低 8 位
$wordIndex = (int) ($i / 4); // 第几个 32 位整数
$shift = ($i % 4) * 8; // 小端序位移
$result[$wordIndex] |= $byte << $shift;
}
return $result;
}
/* === 演示 === */
$arr = strToUint32Array('sssssbbbbb1753874610182');
print_r($arr); // 输出:Array ( [0] => 6513249 )
exit;
$key = 'jo8j9wGw%6HbxfFn';
$iv = '0123456789ABCDEF';
$data = '{page: 1, _ts: 1753795557201}';
$cipher = "AES-128-CBC";
$options = 1;
class AES {
protected $method;
protected $secret_key;
protected $iv;
protected $options;
public function __construct($key, $method = 'AES-128-CBC', $iv = '', $options = 0) {
$this->secret_key = isset($key) ? $key : exit('key为必须项');
$this->method = $method;
$this->iv = $iv;
$this->options = $options;
}
public function encrypt($data) {
return openssl_encrypt($data, $this->method, $this->secret_key, $this->options, $this->iv);
}
public function decrypt($data) {
return openssl_decrypt($data, $this->method, $this->secret_key, $this->options, $this->iv);
}
}
$aes = new AES($key, 'AES-128-CBC', $iv);
$encrypted = $aes->encrypt($data);
echo "加密后的数据: " . hexdec($encrypted) . PHP_EOL;
$decrypted = $aes->decrypt($encrypted);
echo "解密后的数据: " . $decrypted . PHP_EOL;
//$encrypted = openssl_encrypt(base64_encode($data), $cipher, $key, $options, substr($iv, 0, 16));
//$encrypted = openssl_encrypt($data, $cipher, $key, $options, substr($iv, 0, 16));
$encrypted = openssl_encrypt($data, $cipher, $key, 1, $iv);
echo OPENSSL_RAW_DATA;
echo $encrypted;exit;
$headers[] = 'Cookie:Hm_lvt_0d2227abf9548feda3b9cb6fddee26c0=1753794156; HMACCOUNT=8CFCE68853DBDF9C; sessionid=acnti2em752v7l48qa9av21r69td509r; Hm_lpvt_0d2227abf9548feda3b9cb6fddee26c0=1753794360';
$headers[] = 'User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0';
$headers[] ='Referer:https://mashangpa.com/problem-detail/4/';
$sums = 0;
for ($i=1;$i<=20;$i++){
$page = $i;
$time = get_total_millisecond();
$sign = md5("tuling{$time}{$page}");
$url = "https://mashangpa.com/api/problem-detail/4/data/?page={$page}&sign={$sign}&_ts={$time}";
//echo $url;echo PHP_EOL;
$code = get_curl_contents($url,$headers);
$json = json_decode($code,true);
//var_dump($json);
$sum = 0;
foreach($json['current_array'] as $v){
$sum +=$v;
}
$sums += $sum;
}
echo $sums;
function get_curl_contents($bstrURL, $headers = null, $post = null) {
$ch = curl_init($bstrURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
if ($headers) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$data = curl_exec($ch);
// 关闭CURL会话
curl_close($ch);
return $data;
}
function get_total_millisecond() {
$time = explode(" ", microtime());
$time = ($time[1] + $time[0]) * 1000;
$time = round($time) . '';
return $time;
}
function padPkcs7($data, $blocksize = 16){
$pad = $blocksize - (strlen($data) % $blocksize);
return $data . str_repeat(chr($pad), $pad);
}