2,763
社区成员
发帖
与我相关
我的任务
分享
function passport_encrypt($txt, $key) {
srand((double)microtime() * 1000000);
$encrypt_key = md5(rand(0, 32000));
$ctr = 0;
$tmp = '';
for($i = 0;$i < strlen($txt); $i++) {
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
}
return base64_encode(passport_key($tmp, $key));
}
function passport_key($txt, $encrypt_key) {
$encrypt_key = md5($encrypt_key);
$ctr = 0;
$tmp = '';
for($i = 0; $i < strlen($txt); $i++) {
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
$tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
}
return $tmp;
}
def encrypt(txt,key)
encrypt_key=Digest::MD5.hexdigest(rand(32000).to_s)
ctr=0
tmp=''
for i in (0..txt.length)
ctr = (ctr == encrypt_key.length ? 0 : ctr)
tmp += (encrypt_key[ctr].to_s+( txt[i] ^ encrypt_key[ctr]).to_s)
ctr+=1
end
return Base64.encode64(passport_key(tmp,key))
end
def passport_key(txt,key)
encrypt_key=Digest::MD5.hexdigest(key)
ctr=0
tmp=''
for i in (0..txt.length)
ctr= (ctr==encrypt_key.length ? 0 : ctr)
tmp += (txt[i] ^ encrypt_key[ctr]).to_s
ctr+=1
end
return tmp
end