1,183
社区成员
发帖
与我相关
我的任务
分享
procedure CodeBuf(var Buf: array of byte; BufSize: integer; Password: string);
begin
...
在此处理Buf的内容
...
end;
procedure CodeBuf(var Buf: array of byte; BufSize: integer; Password: string);
var
I: Integer;
begin
if Password = '' then Exit;
for I := 0 to BufSize - 1 do
Buf[I] := Buf[I] xor Ord(Password[I mod Length(Password) + 1]);
end;
procedure UnCodeBuf(var Buf: array of byte; BufSize: integer; Password: string);
var
I: Integer;
begin
if Password = '' then Exit;
for I := 0 to BufSize - 1 do
Buf[I] := Buf[I] xor Ord(Password[I mod Length(Password) + 1]);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
A: array of Byte;
S: string;
begin
// 写入
S := Memo1.Text;
if S = '' then Exit;
SetLength(A, Length(S));
Move(S[1], A[0], Length(S));
CodeBuf(A, Length(A), 'zswang 路过');
with TMemoryStream.Create do try
Write(A[0], Length(A));
SaveToFile('c:\temp\temp.dat');
finally
Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
A: array of Byte;
S: string;
begin
// 读取
if not FileExists('c:\temp\temp.dat') then Exit;
with TMemoryStream.Create do try
LoadFromFile('c:\temp\temp.dat');
SetLength(A, Size);
Read(A[0], Size);
UnCodeBuf(A, Length(A), 'zswang 路过');
SetLength(S, Size);
Move(A[0], S[1], Size);
Memo2.Text := S;
finally
Free;
end;
end;