将以下js代码转 java代码function $c(ascii){ return String.fromCharCode(ascii); } function dhc_cacheEncrypt(x){ var constval=37,out=""; x = x.replace(/(\s*$)/g,""); var len ; var ch,num; for(var i=1; i<= x.length; i++){ ch = x.charAt(i-1) if(ch=="D") ch = $c(2); if(ch=="p") ch = $c(3); if(ch=="d") ch = $c(4); if(ch=="t") ch = $c(5); num = ch.charCodeAt(); num = (num-i+constval)%255; if (num>127) num = (num+128)%255; if (num<32) num = (num+40)%255; if ($c(num)=="^") num++; out += ""+$c(num%255); } len = out.length; for(var i=len; i<12; i++){ ch = out.charAt(i-len); num = ch.charCodeAt(); num = (num*2.345*constval*(constval-7))%255; if (num>127) num = (num+128)%255; if (num<32) num = (num+40)%255; if ($c(num)=="^") num++; out += ""+$c(num%255); } return out; }
时间: 2024-03-29 22:36:39 浏览: 42
JS中把字符转成ASCII值的函数示例代码
以下是将js代码转换为java代码后的样子:
public String $c(int ascii) {
return Character.toString((char)ascii);
}
public String dhc_cacheEncrypt(String x) {
int constval = 37;
String out = "";
x = x.replaceAll("(\\s*$)", "");
int len;
char ch;
int num;
for(int i=1; i<=x.length(); i++) {
ch = x.charAt(i-1);
if(ch=='D') ch = $c(2).charAt(0);
if(ch=='p') ch = $c(3).charAt(0);
if(ch=='d') ch = $c(4).charAt(0);
if(ch=='t') ch = $c(5).charAt(0);
num = (int)ch;
num = (num-i+constval)%255;
if(num>127) num = (num+128)%255;
if(num<32) num = (num+40)%255;
if($c(num).equals("^")) num++;
out += "" + $c(num%255);
}
len = out.length();
for(int i=len; i<12; i++) {
ch = out.charAt(i-len);
num = (int)ch;
num = (int)((num*2.345*constval*(constval-7))%255);
if(num>127) num = (num+128)%255;
if(num<32) num = (num+40)%255;
if($c(num).equals("^")) num++;
out += "" + $c(num%255);
}
return out;
}
阅读全文