L
lwaif
Unregistered / Unconfirmed
GUEST, unregistred user!
我这里给个最简单的方法,不知道还有没有更高明的,欢迎大家共享自己的珍藏,
并讨论下这样的加密有什么优缺点,怎样能防止别人的破解?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function Encrypt(const S: String;
Key: Word): String;
var
I: Integer;
begin
Result := S;
for I := 1 to Length(S)do
begin
Result := char(byte(S) xor (Key shr 8));
Key := (byte(Result) + Key) * 123 + 345345;
end;
end;
function Decrypt(const S: String;
Key: Word): String;
var
I: Integer;
begin
Result := S;
for I := 1 to Length(S)do
begin
Result := char(byte(S) xor (Key shr 8));
Key := (byte(S) + Key) * 123 + 345345;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(Encrypt('asdfasdf',12));
showmessage(Decrypt(Encrypt('asdfasdf',12),12));
end;
end.
并讨论下这样的加密有什么优缺点,怎样能防止别人的破解?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function Encrypt(const S: String;
Key: Word): String;
var
I: Integer;
begin
Result := S;
for I := 1 to Length(S)do
begin
Result := char(byte(S) xor (Key shr 8));
Key := (byte(Result) + Key) * 123 + 345345;
end;
end;
function Decrypt(const S: String;
Key: Word): String;
var
I: Integer;
begin
Result := S;
for I := 1 to Length(S)do
begin
Result := char(byte(S) xor (Key shr 8));
Key := (byte(S) + Key) * 123 + 345345;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(Encrypt('asdfasdf',12));
showmessage(Decrypt(Encrypt('asdfasdf',12),12));
end;
end.