在(3)中我们会一块块的读取
那么,如果说我们在每块内加点东西,那么程序就不能运行,再减去你加的那些,程序又能以运行
由此你可以想到对自己的程序(加密),这里不是真正加密
我做的程序是在向文件写入时写入两次,这种方法你的程序会加大一倍,如果你有时间,那就用char类型加密,(别有数组4096)加密部分代码,其它不变就可以
代码如下
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Edit1: TEdit;
Edit2: TEdit;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
Var SouFile,DescFile:TFileStream;
Buf:Array [1..4096] of Char;
iLen:integer;
begin
if (edit1.Text='') or (edit2.Text='') then
begin
application.messagebox('请填写正确路径','提示',mb_ok);
exit;
end;
SouFile:=TfileStream.Create(edit1.Text,fmOpenRead or fmShareDenyWrite);
DescFile:=TFileStream.Create(edit2.Text,fmCreate);
SouFile.Position:=0;
While SouFile.Position <=SouFile.Size do
begin
If (SouFile.Size-SouFile.Position)>4096 Then
Begin
SouFile.ReadBuffer(Buf,sizeof(buf));
DescFile.WriteBuffer(Buf,sizeof(buf));
DescFile.WriteBuffer(Buf,sizeof(buf));
end
else
begin
iLen:=SouFile.Size-SouFile.Position;
SouFile.ReadBuffer(Buf,iLen);
DescFile.WriteBuffer(Buf,iLen);
Break;
End;
end;
SouFile.Free();
DescFile.Free();
application.messagebox('加密成功','good',mb_ok);
end;
procedure TForm1.Button2Click(Sender: TObject);
Var SouFile,DescFile:TFileStream;
buf1, Buf:Array [1..4096] of Char;
iLen:integer;
begin
if (edit1.Text='') or (edit2.Text='') then
begin
application.messagebox('请填写正确路径','提示',mb_ok);
exit;
end;
SouFile:=TfileStream.Create(edit1.Text,fmOpenRead or fmShareDenyWrite);
SouFile.Position:=0;
SouFile.ReadBuffer(Buf,sizeof(buf));
SouFile.ReadBuffer(Buf1,sizeof(buf));
if buf<>buf1 then
begin
application.messagebox('些程序未加密','提示',mb_ok);
SouFile.Free();
exit;
end;
DescFile:=TFileStream.Create(edit2.Text,fmCreate);
SouFile.Position:=0;
While SouFile.Position <=SouFile.Size do
begin
If (SouFile.Size-SouFile.Position)>4096 Then
Begin
SouFile.ReadBuffer(Buf,sizeof(buf));
DescFile.WriteBuffer(Buf,sizeof(buf));
SouFile.Position:=SouFile.Position+4096;
end
else
begin
iLen:=SouFile.Size-SouFile.Position;
SouFile.ReadBuffer(Buf,iLen);
DescFile.WriteBuffer(Buf,iLen);
Break;
End;
end;
SouFile.Free();
DescFile.Free();
application.messagebox('复原成功','good',mb_ok);
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if opendialog1.Execute then
edit1.Text:=opendialog1.FileName;
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
if savedialog1.Execute then
edit2.Text:=savedialog1.FileName;
end;
end.
如果自己做不好可以下载我的源码试着学
下载地址
http://www.cnitblog.com/Files/shuyezi122/加解.rar
posted on 2009-01-23 22:57
小叶子 阅读(2027)
评论(0) 编辑 收藏 引用 所属分类:
delphi流的应用