再加300分求这个问题的答案!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!(300分)

  • 主题发起人 主题发起人 9903
  • 开始时间 开始时间
9

9903

Unregistered / Unconfirmed
GUEST, unregistred user!
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2622802
 
//解密
function DeCode(InStr:Pchar;var OutStr:Pchar):Integer;
var lcnt,I,icode,_edi:Integer;
S:String[2];
begin
Result:=0;
if not Assigned(InStr) then
Exit;
lcnt:=strlen(InStr);
lcnt:=lcnt shr 1;
if lcnt=0 then
Exit;
if InStr[0]=#0 then
Exit;
icode:=0;
_edi:=$f667;
for i:=0 to lcnt-1do
begin
S[1]:=InStr[I*2];
S[2]:=InStr[I*2+1];
icode:=StrToInt('$'+S);
OutStr:=Chr(icode xor (_edi shr 8));
_edi:=(((_edi+icode)*$ce6d) and $ffff)+$58bf;
end;
OutStr[lcnt]:=#0;
Result:=1;
end;

//加密
function EnCode(InStr:Pchar;var OutStr:Pchar):Integer;
var lcnt,I,icode,tcode,_edi:Integer;
S:String;
begin
lcnt:=strlen(InStr);
icode:=0;
tcode:=0;
_edi:=$f667;
for i:=0 to lcnt-1do
begin
icode:=Ord(InStr);
icode:=(iCode xor (_edi shr 8))and $FF;
S:=IntToHex(icode,2);
outStr[i*2]:=S[1];
outStr[i*2+1]:=S[2];
_edi:=(((_edi+icode)*$ce6d)and $ffff)+$58bf;
end;
outStr[i*2]:=#0;
Result:=1
end;

procedure TForm1.Button1Click(Sender: TObject);
var P:Pchar;
S:String;
begin
GetMem(P,100);
S:='Button1Click';
EnCode(Pchar(S),P);
S:=P;
ShowMessage(S);
DeCode(Pchar(S),P);
S:=P;
ShowMessage(S);
FreeMem(P);
end;
 
//一律转成大写字母
function ucase(c:char):char;
begin
if(c>='a') AND (c<='z') then
c:=char(byte(c)-$20);
ucase:=c;
end;
==========
//16进制字符转成对应数值
function hex2int(c:char):byte;
begin
if (c>='A')and(c<='F')
then
hex2int:=byte(c)-byte('A')+10
else
if (c>='a')AND (c<='f')
then
hex2int:=byte(c)-byte('a')+10
else
if(c>='0')AND(c<='9')
then
hex2int:=byte(c)-byte('0')
else
hex2int:=0;
end;
=========
function int2hex(v:byte):char;
const
hextable : array [0..15] of char=('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
begin
v:=v AND $f;
//只保留最低字节
int2hex:=hextable[v];
end;
=========
 
//加密
procedure EnCode(instr:string;outstr:string);
//函数返回值无意义,去处
var
lcnt,i,icode,tcode,hbyte,lbyte,_edi:integer;
begin
lcnt:=length(instr);
setlength(outstr,lcnt*2);
i := 0;
icode:= 0;
tcode:= 0;
hbyte:= 0;
lbyte:= 0;
_edi := $f667;
for i:=1 to lcntdo
begin
icode := integer(instr) AND $ff;
tcode := icode;
tcode := tcode Xor ((_edi AND $ffff) shr 8);
hbyte := (tcode And $f0) shr 4;
//高4位
lbyte := (tcode And $f);
//低4位
outstr[i*2-1] := int2hex(hbyte);
outstr[i*2] := int2hex(lbyte);
_edi := (((_edi + tcode) * $ce6d) And $ffff) + $58bf;
//改变密钥
end;
end;
 
//解密
function DeCode(instr:string;outstr:string):Boolean;//是否成功
var
lcnt,i,icode,_edi:integer;
begin
if (instr='') then
begin
DeCode:=false;
exit;
end;
lcnt:=length(instr) shr 1;//除以2
setlength(outstr,lcnt);
i := 0;
icode:= 0;
_edi := $f667;
for i:=1 to lcntdo
begin
outstr:= char((hex2int(ucase(instr[i*2-1]))And $f) shl 4);
outstr:= char(byte(outstr)+hex2int(ucase(instr[i*2])) And $f);
icode := integer(outstr)And $ff;
outstr:= char(integer(outstr) Xor ((_edi And $ffff) shl 8));
_edi := (((_edi + icode) * $ce6d) And $ffff) + $58bf;
end;
Decode:=true;
end;
 
麻子兄, TYZhang 也是你的账号吗???
 
不是,我只有两个。 :)
 
多人接受答案了。
 
后退
顶部