永发信息网

delphi 代码转java

答案:4  悬赏:70  手机版
解决时间 2021-01-27 07:53
Function EncrypKey (Src:String; Key:String):string;
var
KeyLen :Integer;
KeyPos :Integer;
offset :Integer;
dest :string;
SrcPos :Integer;
SrcAsc :Integer;
Range :Integer;

begin
KeyLen:=Length(Key);
if KeyLen = 0 then key:= 'Think Space ';

KeyPos:=0;
Range:=256;

Randomize;
offset:=Random(Range);
dest:=format( '%1.2x',[offset]);
for SrcPos := 1 to Length(Src) do
begin
SrcAsc:=(Ord(Src[SrcPos]) + offset) MOD 255;
if KeyPos < KeyLen then KeyPos:= KeyPos + 1 else KeyPos:=1;
SrcAsc:= SrcAsc xor Ord(Key[KeyPos]);
dest:=dest + format( '%1.2x',[SrcAsc]);
offset:=SrcAsc;
end;
Result:=Dest;
end;

delphi的加密代码,现需要将其转为java的代码
哪位帮解决下
知道排版不好排,不好意思了
解决了再追加50分!谢谢了
最佳答案
int KeyLen, KeyPos ,offset ,SrcPos ,SrcAsc, Range ;
string dest;
KeyLen =Length(Key);
if ( KeyLen = 0 ) key= 'Think Space ';

KeyPos=0;
Range=256;

Randomize;
offset=Random(Range);
dest=format( "%1.2x",[offset]);
for ( SrcPos = 1 ; SrcPos< Length(Src); SrcPos++)
{
SrcAsc=(Ord(Src[SrcPos]) + offset) % 255;
if ( KeyPos < KeyLen )
KeyPos= KeyPos + 1
全部回答
pubilc EncrypKey (string Src, Key):string; { int KeyLen, KeyPos ,offset ,SrcPos ,SrcAsc, Range ; string dest; KeyLen =Length(Key); if ( KeyLen = 0 ) key= 'Think Space '; KeyPos=0; Range=256; Randomize; offset=Random(Range); dest=format( "%1.2x",[offset]); for ( SrcPos = 1 ; SrcPos< Length(Src); SrcPos++) { SrcAsc=(Ord(Src[SrcPos]) + offset) % 255; if ( KeyPos < KeyLen ) KeyPos= KeyPos + 1 else KeyPos=1; SrcAsc= SrcAsc xor Ord(Key[KeyPos]); dest =dest + format( “%1.2x",[SrcAsc]); offset=SrcAsc; } rueten Dest; }
//字符串加密用 static final byte[] xorkey={(byte)0xb2, (byte)0x09, (byte)0xaa, (byte)0x55, (byte)0x93, (byte)0x6d, (byte)0x84, (byte)0x47}; static string dec(string str){//字符解密函数 string result=""; for(int i=1, j=0; i<=str.length() / 2; i++ ){ string s=str.substring(i*2-2, i*2); system.out.println(i+" "+s); int v=integer.parseint(s, 16); result=result+(char)(byte)(v ^ xorkey[j]); j=(j+1) % 8; } return result; } 请参考,时间紧, 没时间全转。
public string EncrypKey(string Src,string Key){ int KeyLen, KeyPos ,offset ,SrcPos ,SrcAsc, Range ; string dest; KeyLen = Key.length(); if(KeyLen==0) Key = "Think Space"; KeyPos=0; Range=256; offset = Math.random()*Range; dest = Integer.parseInt(offset, 16); for(SrcPos=1;SrcPos
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯