O
ouyongke
Unregistered / Unconfirmed
GUEST, unregistred user!
我看了一下,这里怎么全是字符串加密呢?我想给一个文本文件倒是找到一个例子,您看罗:
procedure TForm1.Button2Click(Sender: TObject)
var b:byte
I:integer
filestream:tfilestream
begin
FileStream:=TFileStream.Create('c:/a.dat',fmOpenReadWrite)
^^^^^^^^^^^^^^^^^^^^^^^用读写模式打开
for I:=0 to FileStream.size-1 do
begin
filestream.position:=i
filestream.readbuffer(b,1)
b:=b xor $F
filestream.position:=i
filestream.writebuffer(b,1)
end
filestream.Free
end;
一次才处理一个字节,太慢了吧,我改进的请看:
procedure TForm1.btnDecodeClick(Sender: TObject);
var
b:Array[0..72] of Byte;
I,j:Integer;
filestream:TFileStream;
str:string;//密匙
StartTime:TDateTime;
begin
StartTime:=now;
Screen.Cursor:=crHourGlass;
j:=-1;
str:='PHKFZQLZHLJCLJJLDHGCHLOKPHKFZQLZHLJCLJJLDHGCHLOKPHKFZQLZHLJCLJJLDHGCHLOK';
FileStream:=TFileStream.Create('c:/temp/aaaa2.txt',fmOpenReadWrite);
filestream.readbuffer(b,72);
for I:=0 to FileStream.size-1 do
begin
if j<=72 then
begin
j:=j+1;
b[j]:=b[j] xor Byte(str[j]);
end
else
begin
j:=0;
filestream.position:=i;
filestream.writebuffer(b,72);
filestream.position:=i;
if FileStream.size-1-i<72 then
filestream.readbuffer(b,FileStream.size-1-i)
else
filestream.readbuffer(b,72);
end;
//b:=b xor $F;
Gauge1.Progress:= Round(i / FileStream.size*100);
Application.ProcessMessages;
end;
filestream.Free;
Screen.Cursor:=crDefault;
ShowMessage(FormatDateTime('hh:nn:ss zzz', Now - StartTime));
end;
不好意思得很,快是快了,就是上面我的代码是错的!
所以,想请您帮个忙,帮我组合一个速度有点保证的加密文件过程吧
procedure TForm1.Button2Click(Sender: TObject)
var b:byte
I:integer
filestream:tfilestream
begin
FileStream:=TFileStream.Create('c:/a.dat',fmOpenReadWrite)
^^^^^^^^^^^^^^^^^^^^^^^用读写模式打开
for I:=0 to FileStream.size-1 do
begin
filestream.position:=i
filestream.readbuffer(b,1)
b:=b xor $F
filestream.position:=i
filestream.writebuffer(b,1)
end
filestream.Free
end;
一次才处理一个字节,太慢了吧,我改进的请看:
procedure TForm1.btnDecodeClick(Sender: TObject);
var
b:Array[0..72] of Byte;
I,j:Integer;
filestream:TFileStream;
str:string;//密匙
StartTime:TDateTime;
begin
StartTime:=now;
Screen.Cursor:=crHourGlass;
j:=-1;
str:='PHKFZQLZHLJCLJJLDHGCHLOKPHKFZQLZHLJCLJJLDHGCHLOKPHKFZQLZHLJCLJJLDHGCHLOK';
FileStream:=TFileStream.Create('c:/temp/aaaa2.txt',fmOpenReadWrite);
filestream.readbuffer(b,72);
for I:=0 to FileStream.size-1 do
begin
if j<=72 then
begin
j:=j+1;
b[j]:=b[j] xor Byte(str[j]);
end
else
begin
j:=0;
filestream.position:=i;
filestream.writebuffer(b,72);
filestream.position:=i;
if FileStream.size-1-i<72 then
filestream.readbuffer(b,FileStream.size-1-i)
else
filestream.readbuffer(b,72);
end;
//b:=b xor $F;
Gauge1.Progress:= Round(i / FileStream.size*100);
Application.ProcessMessages;
end;
filestream.Free;
Screen.Cursor:=crDefault;
ShowMessage(FormatDateTime('hh:nn:ss zzz', Now - StartTime));
end;
不好意思得很,快是快了,就是上面我的代码是错的!
所以,想请您帮个忙,帮我组合一个速度有点保证的加密文件过程吧