请大家帮忙,将下面的一个加密和解密的delphi函数改为java函数,谢谢

sun_cathay 2006-02-07 01:49:00
function SeqEnc(Str:String;Key:Integer;Times:Integer):string;
var
i,c,n:Integer;
Key1,Key2,Key3,Key4:Byte;
begin
n:=Length(Str);
if n=0 then
exit;
Key4:=Byte(Key shr 24);
Key3:=Byte(Key shr 16);
Key2:=Byte(Key shr 8);
Key1:=Byte(Key);
for c:=Times-1 downto 0 do
begin
Str[1]:=Char(Byte(Str[1])+Key3);
for i:=2 to n do
Str[i]:=Char((Byte(Str[i-1])+Byte(Str[i])) xor Key1);
Str[n]:=Char(Byte(Str[n])+Key4);
for i:=n-1 downto 1 do
Str[i]:=Char((Byte(Str[i+1])+Byte(Str[i])) xor Key2);
end;
str:=strtohex(str);
result:=str;
end;

function SeqDec(Str:String;Key:Integer;Times:Integer):string;
var
i,c,n:Integer;
Key1,Key2,Key3,Key4:Byte;
begin
str:=hextostr(str);
n:=Length(Str);
if n=0 then
exit;
Key4:=Byte(Key shr 24);
Key3:=Byte(Key shr 16);
Key2:=Byte(Key shr 8);
Key1:=Byte(Key);
for c:=Times-1 downto 0 do
begin
for i:=1 to n-1 do
Str[i]:=Char(Byte(Str[i]) xor Key2-Byte(Str[i+1]));
Str[n]:=Char(Byte(Str[n])-Key4);
for i:=n downto 2 do
Str[i]:=Char(Byte(Str[i]) xor Key1-Byte(Str[i-1]));
Str[1]:=Char(Byte(Str[1])-Key3);
end;

result:=str;
end;
...全文
126 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sun_cathay 2006-02-07
  • 打赏
  • 举报
回复
不是懒,关键是对java不熟
725137 2006-02-07
  • 打赏
  • 举报
回复
懒人太多了.

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧