_StringEncrypt转为php,移动电话卡100元支付
本帖最后由 zhouein 于 2014-12-31 16:18 编辑Func _StringEncrypt($i_Encrypt, $s_EncryptText, $s_EncryptPassword, $i_EncryptLevel = 1, $i_Flag = 1)
If $i_Encrypt <> 0 And $i_Encrypt <> 1 Then
SetError(1)
Return ''
ElseIf $s_EncryptText = '' Or $s_EncryptPassword = '' Then
SetError(1)
Return ''
Else
If Number($i_EncryptLevel) <= 0 Or Int($i_EncryptLevel) <> $i_EncryptLevel Then $i_EncryptLevel = 1
Local $b_EncryptText
Local $b_EncryptPassword
Local $v_EncryptModified
Local $i_EncryptCountH
Local $i_EncryptCountG
Local $v_EncryptSwap
Local $av_EncryptBox
Local $i_EncryptCountA
Local $i_EncryptCountB
Local $i_EncryptCountC
Local $i_EncryptCountD
Local $i_EncryptCountE
Local $v_EncryptCipher
Local $v_EncryptCipherBy
$b_EncryptText = StringToBinary($s_EncryptText, $i_Flag)
$b_EncryptPassword = StringToBinary($s_EncryptPassword, $i_Flag)
If $i_Encrypt = 1 Then
For $i_EncryptCountF = 0 To $i_EncryptLevel Step 1
$i_EncryptCountG = ''
$i_EncryptCountH = ''
$v_EncryptModified = Binary('')
For $i_EncryptCountG = 1 To BinaryLen($b_EncryptText)
If $i_EncryptCountH = BinaryLen($b_EncryptPassword) Then
$i_EncryptCountH = 1
Else
$i_EncryptCountH += 1
EndIf
$v_EncryptModified = Binary($v_EncryptModified) & Binary('0x' & Hex(BitXOR(BinaryMid($b_EncryptText, $i_EncryptCountG, 1), BinaryMid($b_EncryptPassword, $i_EncryptCountH, 1), 255),2))
Next
$b_EncryptText = $v_EncryptModified
$i_EncryptCountA = ''
$i_EncryptCountB = 0
$i_EncryptCountC = ''
$i_EncryptCountD = ''
$i_EncryptCountE = ''
$v_EncryptCipherBy = ''
$v_EncryptCipher = ''
$v_EncryptSwap = ''
$av_EncryptBox = ''
Local $av_EncryptBox
For $i_EncryptCountA = 0 To 255
$av_EncryptBox[$i_EncryptCountA] = Dec(StringTrimLeft(BinaryMid($b_EncryptPassword, Mod($i_EncryptCountA, BinaryLen($b_EncryptPassword)) + 1, 1),2))
$av_EncryptBox[$i_EncryptCountA] = $i_EncryptCountA
Next
For $i_EncryptCountA = 0 To 255
$i_EncryptCountB = Mod(($i_EncryptCountB + $av_EncryptBox[$i_EncryptCountA] + $av_EncryptBox[$i_EncryptCountA]), 256)
$v_EncryptSwap = $av_EncryptBox[$i_EncryptCountA]
$av_EncryptBox[$i_EncryptCountA] = $av_EncryptBox[$i_EncryptCountB]
$av_EncryptBox[$i_EncryptCountB] = $v_EncryptSwap
Next
For $i_EncryptCountA = 1 To BinaryLen($b_EncryptText)
$i_EncryptCountC = Mod(($i_EncryptCountC + 1), 256)
$i_EncryptCountD = Mod(($i_EncryptCountD + $av_EncryptBox[$i_EncryptCountC]), 256)
$i_EncryptCountE = $av_EncryptBox + $av_EncryptBox[$i_EncryptCountD]), 256) ]
$v_EncryptCipherBy = BitXOR(BinaryMid($b_EncryptText, $i_EncryptCountA, 1), $i_EncryptCountE)
$v_EncryptCipher = Binary($v_EncryptCipher) & Binary('0x' & Hex($v_EncryptCipherBy, 2))
Next
$b_EncryptText = StringTrimLeft($v_EncryptCipher,2)
Next
Else
$b_EncryptText = $s_EncryptText
For $i_EncryptCountF = 0 To $i_EncryptLevel Step 1
$b_EncryptText = Binary('0x' & $b_EncryptText)
$i_EncryptCountB = 0
$i_EncryptCountC = ''
$i_EncryptCountD = ''
$i_EncryptCountE = ''
$v_EncryptCipherBy = ''
$v_EncryptCipher = ''
$v_EncryptSwap = ''
$av_EncryptBox = ''
Local $av_EncryptBox
For $i_EncryptCountA = 0 To 255
$av_EncryptBox[$i_EncryptCountA] = Dec(StringTrimLeft(BinaryMid($b_EncryptPassword, Mod($i_EncryptCountA, BinaryLen($b_EncryptPassword)) + 1, 1),2))
$av_EncryptBox[$i_EncryptCountA] = $i_EncryptCountA
Next
For $i_EncryptCountA = 0 To 255
$i_EncryptCountB = Mod(($i_EncryptCountB + $av_EncryptBox[$i_EncryptCountA] + $av_EncryptBox[$i_EncryptCountA]), 256)
$v_EncryptSwap = $av_EncryptBox[$i_EncryptCountA]
$av_EncryptBox[$i_EncryptCountA] = $av_EncryptBox[$i_EncryptCountB]
$av_EncryptBox[$i_EncryptCountB] = $v_EncryptSwap
Next
For $i_EncryptCountA = 1 To BinaryLen($b_EncryptText)
$i_EncryptCountC = Mod(($i_EncryptCountC + 1), 256)
$i_EncryptCountD = Mod(($i_EncryptCountD + $av_EncryptBox[$i_EncryptCountC]), 256)
$i_EncryptCountE = $av_EncryptBox + $av_EncryptBox[$i_EncryptCountD]), 256) ]
$v_EncryptCipherBy = BitXOR(BinaryMid($b_EncryptText, $i_EncryptCountA, 1), $i_EncryptCountE)
$v_EncryptCipher = Binary($v_EncryptCipher) & Binary('0x' & Hex($v_EncryptCipherBy,2))
Next
$b_EncryptText = $v_EncryptCipher
$i_EncryptCountG = ''
$i_EncryptCountH = ''
$v_EncryptModified = ''
For $i_EncryptCountG = 1 To BinaryLen($b_EncryptText)
If $i_EncryptCountH = BinaryLen($b_EncryptPassword) Then
$i_EncryptCountH = 1
Else
$i_EncryptCountH += 1
EndIf
$v_EncryptModified = Binary($v_EncryptModified) & Binary('0x' & Hex(BitXOR(BinaryMid($b_EncryptText, $i_EncryptCountG, 1), BinaryMid($b_EncryptPassword, $i_EncryptCountH, 1), 255),2))
Next
$b_EncryptText = BinaryToString($v_EncryptModified, $i_Flag)
Next
EndIf
Return $b_EncryptText
EndIf
EndFunc ;==>_StringEncrypt
$passwordsmi = _StringEncrypt(1,"admin","123") ;1是加密
Msgbox(0,"对admin进行加密" , $passwordsmi)
$passwordsmi = _StringEncrypt(0,"DB7E467519FD6C09DD9B","123") ;0是解密
Msgbox(0,"对DB7E467519FD6C09DD9B解密码" , $passwordsmi)以上代码怎么转为php? <?php
function encrypt($string,$operation,$key=''){
$key=md5($key);
$key_length=strlen($key);
$string=$operation=='D'?base64_decode($string):substr(md5($string.$key),0,8).$string;
$string_length=strlen($string);
$rndkey=$box=array();
$result='';
for($i=0;$i<=255;$i++){
$rndkey[$i]=ord($key[$i%$key_length]);
$box[$i]=$i;
}
for($j=$i=0;$i<256;$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=='D'){
if(substr($result,0,8)==substr(md5(substr($result,8).$key),0,8)){
return substr($result,8);
}else{
return'';
}
}else{
return str_replace('=','',base64_encode($result));
}
}
$str = 'abc';
$key = '1234';
$token = encrypt($str, 'E', $key);
echo '加密:'.encrypt($str, 'E', $key);
echo '解密:'.encrypt($str, 'D', $key);
?>或将这个php转为au3 2个用了同样的方法,对字符串进行编码,解码处理。 学习一下。。。 TCPListenTCPListenTCPListen 还是写不出来 还是写不出来 1.原始鑰匙 key
2.md5(md5+常量) 加密原始key => mkey
3.mkey 作為AC4的密匙 ac_mkey
4.ac_mkey 對加密數據 進行 AC4 加密 得到AC4密碼
5.AC4密碼 在進行一次 AC4加密可還原 加密數據
簡單來說,一句話,用md5 做AC4的密匙
以下是代碼<?php
/*
* rc4加密算法
* $pwd 密钥
* $data 要加密的数据
*/
function rc4 ($pwd, $data)//$pwd密钥 $data需加密字符串
{
$key[] ="";
$box[] ="";
$pwd_length = strlen($pwd);
$data_length = strlen($data);
for ($i = 0; $i < 256; $i++)
{
$key[$i] = ord($pwd[$i % $pwd_length]);
$box[$i] = $i;
}
for ($j = $i = 0; $i < 256; $i++)
{
$j = ($j + $box[$i] + $key[$i]) % 256;
$tmp = $box[$i];
$box[$i] = $box[$j];
$box[$j] = $tmp;
}
for ($a = $j = $i = 0; $i < $data_length; $i++)
{
$a = ($a + 1) % 256;
$j = ($j + $box[$a]) % 256;
$tmp = $box[$a];
$box[$a] = $box[$j];
$box[$j] = $tmp;
$k = $box[(($box[$a] + $box[$j]) % 256)];
$cipher .= chr(ord($data[$i]) ^ $k);
}
return $cipher;
}
$key = '5201314'; //原始KEY
$pwd = md5(md5($key).'我是常量'); //md5+常量
$data = '我愛北京天安門'; //要加密的數據
$cipher = rc4($pwd, $data); //AC4 加密算法
$c = rc4($pwd, $cipher); //AC4 加密算法還原 (還原只需要重新加密一次)
echo '<pre>';
var_dump($key);
var_dump($pwd);
var_dump($data);
var_dump($cipher);
var_dump($c);
?>
页:
[1]