procedure TForm1.EnDecryptFile(pathin, pathout: string; Chave: Word);
var
InMS, OutMS: TMemoryStream;
cnt: Integer;
C: byte;
begin
InMS := TMemoryStream.Create;
OutMS := TMemoryStream.Create;
try
InMS.LoadFromFile(pathin);
InMS.Position := 0;
for cnt := 0 to InMS.Size - 1 DO
begin
InMS.Read(C, 1);
C := (C xor not (ord(chave shr cnt)));
OutMS.Write(C, 1);
end;
OutMS.SaveToFile(pathout);
finally
InMS.Free;
OutMS.Free;
end;
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.Execute;
end;
procedure TForm1.BtnEnDeClick(Sender: TObject);
begin
IF MessageDlg('ATTENTION'+#13+
'Do not miss the password, or lose the file!',
mtConfirmation, [mbYes, mbNo], 0) = mrYes THEN
BEGIN
EnDecryptFile(OpenDialog1.FileName,
OpenDialog1.FileName,
StrToInt(Edit1.Text));
ShowMessage('Operation completed !');
END;
end;
Keine Kommentare:
Kommentar veröffentlichen