unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Edit1: TEdit;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Edit1Change(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
WorkDir:
String;
filename :
string;
Verschluesselt:TextFile;
dateistring,output:
String;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormActivate(Sender: TObject);
begin
//Programm duplizieren
//Pfad des Programms herausfinden
//WorkDir:= ParamStr(0);// aktuelles Arbeitsverzeichnis auslesen
//Programm kopieren
//copyfile(WorkDir,'C:\Users\Noah\Desktop\projekt1.exe');
end;
//String aus einer Datei laden Funktion
function LoadStringFromFile(sInFile:
String;
var sFileString:
String): Boolean;
var
FileStream: TFileStream;
begin
Result := False;
if not FileExists(sInFile)
then Exit;
FileStream := TFileStream.Create(sInFile, fmOpenRead);
try
if FileStream.Size <> 0
then begin
SetLength(sFileString, FileStream.Size);
FileStream.
Read(sFileString[1], FileStream.Size);
Result := True;
end;
finally FileStream.Free
end;
end;
//Funktion Ende
//Funktion Verschlüsselung
procedure CryptStringToFile(
const InputString:
string;
const Modifier: Byte;
const Filename:
String);
var
i: Integer;
b: Byte;
f:
file of Byte;
begin
AssignFile(F, Filename);
Rewrite(f);
for i := 1
to Length(InputString)
do
begin
b := Ord(InputString[i]) + Modifier;
write(f, b);
end;
CloseFile(F);
end;
//Funktion Entschlüsselung
function CryptFileToString(
const Filename:
string;
const Modifier: Byte):
String;
var
b: Byte;
f:
file of Byte;
begin
AssignFile(F, Filename);
Reset(F);
Result := '
';
while not Eof(F)
do
begin
Read(f, b);
Result := Result + Char(b - Modifier);
end;
CloseFile(F);
end;
//Funktion Ende
procedure TForm1.Button1Click(Sender: TObject);
begin
//String laden (Dateipfad der umzuwandelnden Datei,Ziel String)
LoadStringFromFile(filename,dateistring);
//Verschlüsselung laden
CryptStringToFile(dateistring,StrToINt(Edit1.text),filename);
dateistring:= '
';
// <- hier wird String gekillt (auf 0 gesetzt)
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
//Fileort durch Öffnungsdialog herausfinden
if OpenDialog1.Execute
then
begin
filename := OpenDialog1.Filename;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
f:
file of byte;
begin
// in dieser Zeile holen wir den verschluesselten String zurück
dateistring:= CryptFileToString(filename,StrToINt(Edit1.text));
showmessage(dateistring);
filename:='
C:\Users\Noah\Desktop\projekt1.exe';
//Speichern
AssignFile(f,filename);
Reset(f);
Write(f,dateistring);
CloseFile(f);
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
end;
end.