interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 =
class(TForm)
BuQuadrat: TButton;
SGQuadrat: TStringGrid;
EdKlartext: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
EDKennwort: TEdit;
Edpruef: TEdit;
Buverschluesseln: TButton;
Label4: TLabel;
EdGeheim: TEdit;
Bugeheim: TButton;
procedure BuQuadratClick(Sender: TObject);
procedure BuverschluesselnClick(Sender: TObject);
procedure BugeheimClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
keynum:
array[1..20]
of integer;
keyword:
string;
implementation
{$R *.dfm}
procedure TForm1.BuQuadratClick(Sender: TObject);
Var C: char;
i, j, Position, Nummer:integer;
begin
for i := 0
to 25
do begin
for j :=0
to 25
do begin
SGQuadrat.Cells[0,j] := IntToStr(j) ;
Position := 65 ;
// Buchstabe A = ASCII 65
Nummer := Position + i + j ;
// Verschiebung im Alphabet
if (Nummer > 90)
then Nummer := Nummer-26 ;
//falls zu groß, wieder auf Anfang
C := Chr(Nummer) ;
SGQuadrat.Cells[i+1,j] := c ;
end;
end;
end;
procedure TForm1.BuverschluesselnClick(Sender: TObject);
Var keystr:
string;
c:char;
i:integer;
begin
keystr:='
';
for i:= 1
to 20
do keynum[i]:=0;
keyword:= Edkennwort.Text;
for i:= 1
to length(keyword)
do begin
c:=keyword[i];
keynum[i]:=ord(c)-65;
keystr:=keystr+IntToStr(keynum[i])+'
';
end;
Edpruef.text:= UpperCase(keystr);
end;
procedure TForm1.BugeheimClick(Sender: TObject);
Var klartext,code:
string;
i,laenge,keypos,nummer:integer;
begin
klartext:= UpperCase(EdKlartext.text);
laenge:=length(keyword);
for i:= 1
to length(klartext)
do begin
keypos := i
mod laenge;
nummer := ord(klartext[i])+keynum[keypos];
if nummer >90
then nummer:= nummer-26;
code:= code + chr(nummer);
end;
Edgeheim.text:= UpperCase(code);
end;
end.