萬分緊急,有人能幫忙么? PHP5和Java的语法很接近,你这个程序也不复杂,自己改一下啦。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 解除一下 >>> << & 是啥意思!其实php很好写.//enkeystore函数不知道是完成啥功能,只能写个空函数了.// >>> << & 不知道是啥意思function dekeystore($data){ return $data;}function enkeystore($data){ return $data;}public class Encrypt { private static final $enkeystore = array( 0x08, 0x02, 0x0b, 0x0c, 0x01, 0x0a, 0x00, 0x0d, 0x07, 0x03, 0x0e, 0x05, 0x0f, 0x06, 0x04, 0x09 ); public static encode($data) { $result = array(); for ($i = 0; $i < sizeof($data); $i++) { $result[$i] .= (enkeystore[($data[$i] >>> 4) & 0x0F] << 4); $result[i] .= (enkeystore[$data[$i] & 0x0F]); } return $result; }}public class Decrypt{private static final $dekeystore = array( 0x06, 0x04, 0x01, 0x09, 0x0e, 0x0b, 0x0d, 0x08, 0x00, 0x0f, 0x05, 0x02, 0x03, 0x07, 0x0a, 0x0c ); public static decode($data) { $result = array(); for ($i = 0; $i < sizoef(data); $i++) { $result[$i] .= (dekeystore[(data[i] >>> 4) & 0x0F] << 4); $result[$i] .= (dekeystore[data[i] & 0x0F]); } return $result; }} 你看這樣可行嗎?<?function encode($data){$enkeystore = array(0x08, 0x02, 0x0b, 0x0c, 0x01, 0x0a, 0x00, 0x0d, 0x07, 0x03, 0x0e, 0x05, 0x0f, 0x06, 0x04, 0x09);$result = array();for ($i = 0; $i < count($data); $i++){$result[$i] = $enkeystore[($data[$i] >> 4) & 0x0f] << 4;$result[$i] += $enkeystore[$data[$i] & 0x0f];$result[$i] -= 256;}return $result;}function decode($data){ $dekeystore = array(0x06, 0x04, 0x01, 0x09, 0x0e, 0x0b, 0x0d, 0x08, 0x00, 0x0f, 0x05, 0x02, 0x03, 0x07, 0x0a, 0x0c); $result = array(); for ($i = 0; $i < count($data); $i++) { $result[$i] = $dekeystore[($data[$i] >> 4) & 0x0f] << 4; $result[$i] += $dekeystore[$data[$i] & 0x0f]; } return $result;}?> http://jp.php.net/manual/en/language.operators.bitwise.php 如果哪几个操作符一样的话,基本上就是这样子了的了,呵呵.在php中<< 位操作符,左移>> 右移& 位操作符 AND当时被你三个<<<给弄迷糊了,三个的还真没有见过. function encode($data){ $enkeystore = array(0x08, 0x02, 0x0b, 0x0c, 0x01, 0x0a, 0x00, 0x0d, 0x07, 0x03, 0x0e, 0x05, 0x0f, 0x06, 0x04, 0x09); for ($i = 0; $i < strlen($data); $i++) { $result[$i] = $enkeystore[(ord($data[$i]) >> 4) & 0x0f] << 4; $result[$i] += $enkeystore[ord($data[$i]) & 0x0f]; $result[$i] -= 256; $result[$i] = chr($result[$i]); } $strResult = implode('', $result); return $strResult;}function decode($data){ $dekeystore = array(0x06, 0x04, 0x01, 0x09, 0x0e, 0x0b, 0x0d, 0x08, 0x00, 0x0f, 0x05, 0x02, 0x03, 0x07, 0x0a, 0x0c); $result = array(); for ($i = 0; $i < strlen($data); $i++) { $result[$i] = $dekeystore[(ord($data[$i]) >> 4) & 0x0f] << 4; $result[$i] += $dekeystore[ord($data[$i]) & 0x0f]; $result[$i] = chr($result[$i]); } $strResult = implode("", $result); return $strResult;}测试成功,字符串要先转成ASCII码才成,然后再转回来. >>>N 表示右移N位,左边补0,php中没这个操作符 那有什麽辦法解決呢?有人能幫我把那個java類轉成php的嗎? 7b78097f6fda19831c4a5afbf6be8f64 这个字符串加密后应该是下面的:[-51, 11, -51, -57, -56, -61, -51, 0, -64, 0, 1, 2, -62, -61, -57, -52, -62, 12, -63, 2, -54, 2, 0, 11, 0, -64, 11, 10, -57, 0, -64, -63]上面是java得出的結果。但我用php拆分之後測試就是亂碼 <?phpclass Crypter { private static $enkeystore = array(0x08, 0x02, 0x0b, 0x0c, 0x01, 0x0a, 0x00, 0x0d, 0x07, 0x03, 0x0e, 0x05, 0x0f, 0x06, 0x04, 0x09); private static $dekeystore = array(0x06, 0x04, 0x01, 0x09, 0x0e, 0x0b, 0x0d, 0x08, 0x00, 0x0f, 0x05, 0x02, 0x03, 0x07, 0x0a, 0x0c); /** * * @param <String> $data * @return <String> */ private function recode($data,$keystore) { $data = $this->getByte($data); $result = array(); for ($i = 0; $i < count($data); $i++) { $result[$i] += ($keystore[($data[$i] >> 4) & 0x0F] << 4); $result[$i] += ($keystore[$data[$i] & 0x0F]); } return $this->getString($result); } /** * * @param <String> $str * @return <byte[]> */ private function getByte($str){ $bytes = array(); for($i=0;$i<strlen($str);$i++){ $bytes[] = ord($str[$i]); } return $bytes; } /** * * @param <byte[]> $data * @return <type> */ private function getString(&$data){ settype($data,'array'); $str = ""; foreach($data as $d){ $str .= chr($d); } return $str; } /** * 加密 * @param <String> $data * @return <String> */ public function encode($data) { return $this->recode($data,self::$enkeystore); } /** * 解密 * @param <String> $data * @return <String> */ public function decode($data) { return $this->recode($data,self::$dekeystore); }}$crypter = new Crypter();$str = $crypter->encode("中文测试");echo $str;echo "<br />";echo $crypter->decode($str);?>密文是乱码,你可以base64一下。 乱码是因为我将其数字转换成ascii码了.用php执行的结果是-51-245-51-57-56-61-51-256-64-256-255-254-62-61-57-52-62-244-63-254-54-254-256-245-256-64-245-246-57-256-64-63去掉$result[$i] = chr($result[$i]);这部就OK,不过,结果还是有点出入,可能还需要修正一下. 我将你给的数据串,转成ascii码以后,用base64加密.然后base64加密我encode后的串,结果是一样的.虽然结果不同,但是用base64加密以后得到的串是一样的.所以可以说等价. 测试表明,值-245和值11对应的ascii码是一样的,所以说,没有问题,呵呵.今天又学习了. 请帮忙给出处理一个数据文件的代码 mysql的多台数据库服务器。程序上该如何来访问? PHP文件读取问题 求PHP发送Email代码(SMTP)可以带附件的! 有没有可以接收别人网站返回的信息的方法? 50分请教一个新开窗口的问题,多谢各位 如何在程序里 模拟 get 方法提交数据,并得到返回结果。 关于生成图片缩略图的神秘问题-_-!! 用header()函数实现页面的用户认证,如何实现。 php 关于session的警告 php中字符串的问题。。。大家帮忙看哈。。谢谢了哈。 php多数据库问题
其实php很好写.
//enkeystore函数不知道是完成啥功能,只能写个空函数了.
// >>> << & 不知道是啥意思
function dekeystore($data)
{
return $data;
}function enkeystore($data)
{
return $data;
}public class Encrypt
{
private static final $enkeystore = array( 0x08, 0x02, 0x0b, 0x0c, 0x01, 0x0a, 0x00, 0x0d, 0x07, 0x03, 0x0e, 0x05, 0x0f, 0x06, 0x04, 0x09 );
public static encode($data)
{
$result = array();
for ($i = 0; $i < sizeof($data); $i++)
{
$result[$i] .= (enkeystore[($data[$i] >>> 4) & 0x0F] << 4);
$result[i] .= (enkeystore[$data[$i] & 0x0F]);
}
return $result;
}
}public class Decrypt
{
private static final $dekeystore = array( 0x06, 0x04, 0x01, 0x09, 0x0e, 0x0b, 0x0d, 0x08, 0x00, 0x0f, 0x05, 0x02, 0x03, 0x07, 0x0a, 0x0c );
public static decode($data)
{
$result = array();
for ($i = 0; $i < sizoef(data); $i++)
{
$result[$i] .= (dekeystore[(data[i] >>> 4) & 0x0F] << 4);
$result[$i] .= (dekeystore[data[i] & 0x0F]);
}
return $result;
}
}
<?
function encode($data)
{
$enkeystore = array(0x08, 0x02, 0x0b, 0x0c, 0x01, 0x0a, 0x00, 0x0d, 0x07, 0x03, 0x0e, 0x05, 0x0f, 0x06, 0x04, 0x09);
$result = array();
for ($i = 0; $i < count($data); $i++)
{
$result[$i] = $enkeystore[($data[$i] >> 4) & 0x0f] << 4;
$result[$i] += $enkeystore[$data[$i] & 0x0f];
$result[$i] -= 256;
}
return $result;
}function decode($data)
{
$dekeystore = array(0x06, 0x04, 0x01, 0x09, 0x0e, 0x0b, 0x0d, 0x08, 0x00, 0x0f, 0x05, 0x02, 0x03, 0x07, 0x0a, 0x0c);
$result = array();
for ($i = 0; $i < count($data); $i++)
{
$result[$i] = $dekeystore[($data[$i] >> 4) & 0x0f] << 4;
$result[$i] += $dekeystore[$data[$i] & 0x0f];
}
return $result;
}
?>
http://jp.php.net/manual/en/language.operators.bitwise.php
在php中
<< 位操作符,左移
>> 右移
& 位操作符 AND当时被你三个<<<给弄迷糊了,三个的还真没有见过.
function encode($data)
{
$enkeystore = array(0x08, 0x02, 0x0b, 0x0c, 0x01, 0x0a, 0x00, 0x0d, 0x07, 0x03, 0x0e, 0x05, 0x0f, 0x06, 0x04, 0x09);
for ($i = 0; $i < strlen($data); $i++)
{
$result[$i] = $enkeystore[(ord($data[$i]) >> 4) & 0x0f] << 4;
$result[$i] += $enkeystore[ord($data[$i]) & 0x0f];
$result[$i] -= 256;
$result[$i] = chr($result[$i]);
}
$strResult = implode('', $result);
return $strResult;
}function decode($data)
{
$dekeystore = array(0x06, 0x04, 0x01, 0x09, 0x0e, 0x0b, 0x0d, 0x08, 0x00, 0x0f, 0x05, 0x02, 0x03, 0x07, 0x0a, 0x0c);
$result = array();
for ($i = 0; $i < strlen($data); $i++)
{
$result[$i] = $dekeystore[(ord($data[$i]) >> 4) & 0x0f] << 4;
$result[$i] += $dekeystore[ord($data[$i]) & 0x0f];
$result[$i] = chr($result[$i]);
}
$strResult = implode("", $result);
return $strResult;
}测试成功,字符串要先转成ASCII码才成,然后再转回来.
有人能幫我把那個java類轉成php的嗎?
这个字符串加密后应该是下面的:
[-51, 11, -51, -57, -56, -61, -51, 0, -64, 0, 1, 2, -62, -61, -57, -52, -62, 12, -63, 2, -54, 2, 0, 11, 0, -64, 11, 10, -57, 0, -64, -63]
上面是java得出的結果。
但我用php拆分之後測試就是亂碼
private static $enkeystore = array(0x08, 0x02, 0x0b, 0x0c, 0x01, 0x0a, 0x00, 0x0d, 0x07, 0x03, 0x0e, 0x05, 0x0f, 0x06, 0x04, 0x09);
private static $dekeystore = array(0x06, 0x04, 0x01, 0x09, 0x0e, 0x0b, 0x0d, 0x08, 0x00, 0x0f, 0x05, 0x02, 0x03, 0x07, 0x0a, 0x0c);
/**
*
* @param <String> $data
* @return <String>
*/
private function recode($data,$keystore) {
$data = $this->getByte($data);
$result = array();
for ($i = 0; $i < count($data); $i++) {
$result[$i] += ($keystore[($data[$i] >> 4) & 0x0F] << 4);
$result[$i] += ($keystore[$data[$i] & 0x0F]);
}
return $this->getString($result);
}
/**
*
* @param <String> $str
* @return <byte[]>
*/
private function getByte($str){
$bytes = array();
for($i=0;$i<strlen($str);$i++){
$bytes[] = ord($str[$i]);
}
return $bytes;
}
/**
*
* @param <byte[]> $data
* @return <type>
*/
private function getString(&$data){
settype($data,'array');
$str = "";
foreach($data as $d){
$str .= chr($d);
}
return $str;
}
/**
* 加密
* @param <String> $data
* @return <String>
*/
public function encode($data) {
return $this->recode($data,self::$enkeystore);
}
/**
* 解密
* @param <String> $data
* @return <String>
*/
public function decode($data) {
return $this->recode($data,self::$dekeystore);
}
}
$crypter = new Crypter();
$str = $crypter->encode("中文测试");
echo $str;
echo "<br />";
echo $crypter->decode($str);
?>
密文是乱码,你可以base64一下。
用php执行的结果是
-51-245-51-57-56-61-51-256-64-256-255-254-62-61-57-52-62-244-63-254-54-254-256-245-256-64-245-246-57-256-64-63去掉$result[$i] = chr($result[$i]);这部就OK,不过,结果还是有点出入,可能还需要修正一下.
然后base64加密我encode后的串,
结果是一样的.虽然结果不同,但是用base64加密以后得到的串是一样的.
所以可以说等价.