急! php写的加密函数如何用java解密

来源:百度知道 编辑:UC知道 时间:2024/07/06 20:56:07
<?php
$key = "This is supposed to be a secret key !!!";

function keyED($txt,$encrypt_key)
{
$encrypt_key = md5($encrypt_key);
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
$ctr++;
}
return $tmp;
}

function encrypt($txt,$key)
{
srand((double)microtime()*1000000);
$encrypt_key = md5(2000);
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($encrypt_key,$ctr,1) .
(substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
$ctr++;
}
return keyED($tmp,$key);
}

function decrypt($txt,$key)
{
$txt = keyED($txt,$key);
$tmp = "";
for ($i=0;$i<strlen($txt);$i++)
{
$md5

php,jsp,delphi多语言兼容的简单的加密解密算法,jsp目前暂时没有实现中文的加密解密兼容。希望哪路高手能帮忙补上。
1,php的需要对以上代码稍加修改,内容如下:
<?php

$key = "admin";

function keyED($txt,$encrypt_key) {
$encrypt_key = md5($encrypt_key);
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++){
if ($ctr==strlen($encrypt_key)) $ctr=0;
$tmp.= substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1);
$ctr++;
}
return $tmp;
}

function encrypt($txt,$key){
srand((double)microtime()*1000000);
$encrypt_key = md5(rand(0,32000));
$ctr=0;
$tmp = "";
for ($i=0;$i<strlen($txt);$i++){
if ($ctr==strlen($encrypt_key)) $ctr=0;
$bbb=substr($encrypt_key,$ctr,1) .
(substr($txt,$i,1) ^ substr($encrypt_key,$ctr,1));
$tmp.= $bbb;
$ctr++;
}
return base64_encode(keyED($tmp,$key));
}

function decrypt($txt,$key){