Y
ynfly
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了二个加解密的函数(当然也是抄的),但发现结果不是很正常
比如收入'Hello,World'是加密后再解密回来变成了'Hello,Worl',
但是如果输入'hello,world'却又结果正常,真是百思不得其解,
现请教各位有没有什么好的加密界面控件介绍,另外我写的函数到底有什么问题?
unit encrypt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function Encrypt (const S: pchar; Key: Word): pchar;
function Decrypt (const S: pchar; Key: Word): pchar;
end;
const
C1 = 52845;
C2 = 22719;
var
Form1: TForm1;
implementation
{$R *.dfm}
function tform1.Encrypt (const S: pchar; Key: Word): pchar;
var
I: byte;
len:integer;
strResult:string;
destResultchar;
strS:string;
begin
strS:=strpas(s);
len:=length(strS);
setlength(strResult,len);
strResult[1]:=strS[1];
for I := 2 to len do begin
strResult := char(byte(strS) xor (Key shr 8));
Key := (byte(strResult) + Key) * C1 + C2;
end;
GetMem(destResult, 32767);
strpcopy(destResult,strResult);
Result:=destResult;
end;
function tform1.Decrypt (const S: pchar; Key: Word): pchar;
var
I: byte;
len:integer;
strResult:string;
destResultchar;
strS:string;
begin
strS:=strpas(S);
len:=length(strS);
setlength(strResult,len);
strResult[1]:=strS[1];
for I := 2 to Len do begin
strResult := char(byte(strS) xor (Key shr 8));
Key := (byte(strS) + Key) * C1 + C2;
end;
GetMem(destResult, 32767);
strpcopy(destResult,strResult);
Result:=destResult;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit2.Text:=encrypt(pchar(edit1.Text ),12345);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text :=decrypt(pchar(edit2.Text ),12345);
end;
end.
比如收入'Hello,World'是加密后再解密回来变成了'Hello,Worl',
但是如果输入'hello,world'却又结果正常,真是百思不得其解,
现请教各位有没有什么好的加密界面控件介绍,另外我写的函数到底有什么问题?
unit encrypt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function Encrypt (const S: pchar; Key: Word): pchar;
function Decrypt (const S: pchar; Key: Word): pchar;
end;
const
C1 = 52845;
C2 = 22719;
var
Form1: TForm1;
implementation
{$R *.dfm}
function tform1.Encrypt (const S: pchar; Key: Word): pchar;
var
I: byte;
len:integer;
strResult:string;
destResultchar;
strS:string;
begin
strS:=strpas(s);
len:=length(strS);
setlength(strResult,len);
strResult[1]:=strS[1];
for I := 2 to len do begin
strResult := char(byte(strS) xor (Key shr 8));
Key := (byte(strResult) + Key) * C1 + C2;
end;
GetMem(destResult, 32767);
strpcopy(destResult,strResult);
Result:=destResult;
end;
function tform1.Decrypt (const S: pchar; Key: Word): pchar;
var
I: byte;
len:integer;
strResult:string;
destResultchar;
strS:string;
begin
strS:=strpas(S);
len:=length(strS);
setlength(strResult,len);
strResult[1]:=strS[1];
for I := 2 to Len do begin
strResult := char(byte(strS) xor (Key shr 8));
Key := (byte(strS) + Key) * C1 + C2;
end;
GetMem(destResult, 32767);
strpcopy(destResult,strResult);
Result:=destResult;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit2.Text:=encrypt(pchar(edit1.Text ),12345);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text :=decrypt(pchar(edit2.Text ),12345);
end;
end.