请大侠帮我看看这段php代码

来源:百度知道 编辑:UC知道 时间:2024/06/01 17:54:47
$lvemoney=lmemoney((int)$results['level'],(int)$results['metempsychosis']);
$countemoney=(int)$results['emoney']+(int)$lvemoney;
$enc=encoder((int)$accid,(int)$countemoney);
$sql1 = "Update cq_user SET emoney = $countemoney,chk_sum = $enc where account_id=$accid";
$rs=mysql_query($sql1);

想请教大家这段代码是什么意思,$sql1= update cq_user set emoney 中的emoney的算发,还有chk_sum的算法

各位大侠帮我看看emoney和chk_sum的算法呀! 必有重谢!
function encoder($account_id,$emoney) {
$chk_sum = 0;
$dwKeyTable = array(29565076,3118018,9581781);
$chk_sum = $emoney^($account_id+$dwKeyTable[$emoney % 3]);
return $chk_sum;
}

解释一下$chk_sum = 什么,是怎么运算的,这里看不明白,谢谢啦。。。。弄好了分送给你,留下你的QQ号码,我要报答你,你太好了!!!

代码不全啊,Imemoney() 是个自定义函数,你看看这个函数是啥意思啊
还有 encoder();

大概意思就是

把emoney列 由原来的 emoney 更新为 原来的emoney+$Ivemoney,这个$Ivemoney 就是 Imemoney()函数返回的结果;

把chk_sum 列 更新为 $enc,这个$enc 是encoder()函数返回的结果,
encoder()函数也没有代码;

function encoder($account_id,$emoney) {
$chk_sum = 0;
$dwKeyTable = array(29565076,3118018,9581781);
$chk_sum = $emoney^($account_id+$dwKeyTable[$emoney % 3]);
return $chk_sum;
}

1,初始化 变量$chk_sum=0;
2,初始化 $dwKeyTable 为 键值分别为0,1,2,的 数字索引数组
3,计算 $account_id 与 数组$dwKeyTable 中 键值为 $emoney%3 的值 的和;
4,计算 $emoney 与 上边得出来的和 经过按位异或计算 得出来的值;
5,返回其值;
注:"^" 为位运算符中的按位异或运算符,具体计算方法为:
对整型数中指定的位进行置位。如果左右参数都是字符串,则位运算符将操作字符的 ASCII 值。$a ^ $b Xor(按位异或) 将把 $a 和 $b 中不同的位设为 1。
说白了就是:把运算符左右的整数先转换为2进制,然后按位比较,一样为0 反之为1,得出结果后转换为10进制数 返回;
例如:12^9:
12(1100) ^ 9(1001) = 5(101);

我知道的就这么多了 ,希望能够帮到你