Hvordan kryptere og dekryptere jeg en fil? (filen indeholder kun ren teskt).
Hvis du vil kryptere en tekst så brug den her kode:
[pre9
var
A: TStrings;
B,C,D: String;
i,j,k: Integer;
begin
A := TStringList.Create;
A.LoadFromFile(extractfilepath(application.exename)+'Testing.Bac');
D := inputbox('Enter a Password','Secure this file with a password','default');
J := 1;
for i := 1 to length(A.Text)do
begin
k := ord(A.Text
)+ord(D[j]);
if K > 255 then
K := K - 255;
if J = Length(D) then
J := 1
else
J := J+1;
C := C + chr(K);
end;
A.Text := C;
deletefile(extractfilepath(application.exename)+'Testing.Bac');
A.SaveToFile(extractfilepath(application.exename)+'Testing.Bac');
memo1.Lines.LoadFromFile(extractfilepath(application.exename)+'Testing.Bac');
[/pre]
Du skal lave et memo felt, så laver scriptet en temp fil og kryptere den hvor efter den gemmer den som en rigtig fil.
Hvis du vil dekryptere den:
var
A: TStrings;
B,C,D: String;
i,j,k: Integer;
begin
A := TStringList.Create;
A.LoadFromFile(extractfilepath(application.exename)+'Testing.Bac');
D := inputbox('Enter Password','We need your password','Default');
J := 1;
for i := 1 to length(A.Text)do
begin
k := ord(A.Text[i])-ord(D[j]);
if K <1 then
K := K + 255;
if J = Length(D) then
J := 1
else
J := J+1;
C := C + chr(K);
end;
A.Text := C;
A.Delete(A.Count-1);
A.SaveToFile(extractfilepath(application.exename)+'Testing.Bac');
memo1.Lines.LoadFromFile(extractfilepath(application.exename)+'Testing.Bac');
Den gør næsten det samme bare modsat.
Med venlig hilsen
Frede_Manden