能否将我如下代码改写成JAVA代码? (50分)

  • 主题发起人 主题发起人 wxf_wxf
  • 开始时间 开始时间
W

wxf_wxf

Unregistered / Unconfirmed
GUEST, unregistred user!
function EncryptString(InString: string): string;
const
Template = 'aaaa';
CharTable = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var
I, CharVal: Byte;
StartKey, MultKey, AddKey: Word;
begin
Result := '';
InString := InString + Chr(1);
StartKey := Byte(InString[1]);
MultKey := StartKey * 100;
AddKey := StartKey * 512;
for I := 1 to Length(Template)do
begin
CharVal := Byte(InString[(I mod Length(InString)) + 1]) xor (StartKey shr 8) xor Byte(Template) + Length(InString);
CharVal := (CharVal mod Length(CharTable)) + 1;
Result := Result + CharTable[CharVal];
StartKey := (Byte(Result) + StartKey) * MultKey + AddKey;
end;
end;
 
try this JavaScript code:
function EncryptString(InStr) {
var Template = new String("aaaa");
var CharTable = new String("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
var Result = "";
var InString = new String(InString + String.fromCharCode(1));
var StartKey = InString.charAt(0);
var MultKey = StartKey * 100;
var AddKey = StartKey * 512;
var CharVal;
for(I=0;
I<Template.length-1;
I++) {
CharVal = InString.charCodeAt(Math.floor((I+1)/InString.length)) ^ Math.floor(StartKey/256) ^ Template.charCodeAt(I) + InString.length;
CharVal = Math.floor(CharVal/CharTable.length);
Result = Result + CharTable.charAt(CharVal);
StartKey = (Result.charCodeAt(I) + StartKey) * MultKey + AddKey;
}
return Result;
}
 
是base64吗???
public String getBASE64(String s) { //将 字符串 s 进行BASE64编码
if (s == null) {
return null;
}
return (new sun.misc.BASE64Encoder()).encode(s.getBytes());
}
// 将 BASE64 编码的字符串 s 进行解码
public String getFromBASE64(String s) {
if (s == null) {
return null;
}
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
return new String(b);
}
catch (Exception e) {
return null;
}
}
记着import

import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
import java.security.MessageDigest;

 
接受答案了.
 

Similar threads

I
回复
0
查看
577
import
I
I
回复
0
查看
671
import
I
I
回复
0
查看
818
import
I
后退
顶部