for function you can add this :
Function EncryptString(const sBuffer : Widestring) : Widestring;
var
i : Integer;
begin
Result := sBuffer;
for i:=1 to Length(sBuffer) do
Result[i] := Chr(23 XOr Ord(sBuffer[i]));
end;
Function DecryptString(const sBuffer : Widestring) : Widestring;
var
i :Integer;
begin
Result := sBuffer;
for i:=1 to Length(sBuffer) do
Result[i] := Chr(23 XOr Ord(sBuffer[i]));
end;
And next add this to button or whatever you want add.
//To Encrypt the file.
var
oSL : TStringlist;
begin
oSL := TStringlist.Create;
oSL.LoadFromFile('C:\Debug.txt');
oSL.Text := EncryptString(oSL.Text);
oSL.SaveToFile('C:\Debug.txt');
oSL.Free;
//To decrypt the file in RAM and read it.
var
i : Integer;
oSL : TStringlist;
begin
oSL := TStringlist.Create;
oSL.LoadFromFile('C:\Debug.txt');
oSL.Text := DecryptString(oSL.Text);
//Read the decrypted data from oSL.
for i:=0 to oSL.Count-1 do begin
Showmessage(oSL[i]);
end;
oSL.Free;

0 Response to "Simple Encrypting and Decrypting a Text File"
Post a Comment