unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls, Buttons; type TForm1 = class(TForm) Edit1: TEdit; RadioGroup1: TRadioGroup; GroupBox1: TGroupBox; UpDown1: TUpDown; Edit2: TEdit; Button1: TButton; BitBtn1: TBitBtn; Label1: TLabel; Label2: TLabel; Edit3: TEdit; Label3: TLabel; Edit4: TEdit; Label4: TLabel; BitBtn2: TBitBtn; Button2: TButton; Button3: TButton; procedure Edit1KeyPress(Sender: TObject; var Key: Char); procedure FormCreate(Sender: TObject); procedure RadioGroup1Click(Sender: TObject); procedure UpDown1Click(Sender: TObject; Button: TUDBtnType); procedure Button1Click(Sender: TObject); procedure BitBtn2Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; laenge:integer; eingabetext:array[0..255]of char; ausgabetext:array[0..255]of char; anzahl:array[65..90]of integer;{registriert die Anzahl der einzelnen Zeichen des Alphabets} copy:array[65..90]of integer;{registriert die Anzahl der einzelnen Zeichen des Alphabets in einer Kopie} platz:array[1..9]of integer;{Feld zur Auswertung der Häufigkeitsverteilung} implementation uses Unit2, Unit3; {$R *.dfm} procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if Key in ['a'..'z'] then begin{begin of then} Key:=upcase(Key); end;{end of then} if not (Key in [#8,'0'..'9','A'..'Z']) then begin{begin of then} Key:=#0; end;{end of then} if not (Key in[#8,#0]) then begin{begin of then2} eingabetext[laenge]:=Key; inc(laenge); Edit4.Text:=IntToStr(laenge); end;{end of then2} if (Key=chr(8))and(laenge>0) then begin{begin of then} dec(laenge); Edit4.Text:=IntToStr(laenge); end;{end of then} end; procedure TForm1.FormCreate(Sender: TObject); begin Edit2.Text:=IntToStr(UpDown1.Position); laenge:=0; Edit4.Text:=IntToStr(laenge); end; procedure TForm1.RadioGroup1Click(Sender: TObject); begin if RadioGroup1.ItemIndex=0 then begin{begin of then} Button1.Caption:='Verschlüsseln'; Label2.Caption:='Klartext'; Label3.Caption:='Chiffretext'; end{end of then} else begin{begin of else} Button1.Caption:='Entschlüsseln'; Label2.Caption:='Chiffretext'; Label3.Caption:='Klartext'; end;{end of else} end; procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType); begin Edit2.Text:=IntToStr(UpDown1.Position); end; procedure TForm1.Button1Click(Sender: TObject); var faktor:byte;{eingegebener Verschiebefaktor} ascii:byte;{umgewandelter ASCII-Code der Eingabe} verschiebung:byte;{berechneeter Verschiebefaktor} i:byte; begin Edit3.Text:=''; faktor:=StrToInt(Edit2.Text); if RadioGroup1.ItemIndex=0 then begin{begin of then} for i:=0 to laenge-1 do begin{begin of for} ascii:=ord(eingabetext[i]); verschiebung:=ascii+faktor; if verschiebung>90 {das ist der Code vom Z} then begin{begin of then} verschiebung:=verschiebung-26; end;{end of then} ausgabetext[i]:=chr(verschiebung); end;{end of for} for i:=0 to laenge-1 do begin{begin of for} Edit3.Text:=Edit3.Text+ausgabetext[i]; end;{end of for} end{end of then} else begin{begin of else} for i:=0 to laenge-1 do begin{begin of for} ascii:=ord(eingabetext[i]); verschiebung:=ascii-faktor; if verschiebung<65 {das ist der Code vom A} then begin{begin of then} verschiebung:=verschiebung+26; end;{end of then} ausgabetext[i]:=chr(verschiebung); end;{end of for} for i:=0 to laenge-1 do begin{begin of for} Edit3.Text:=Edit3.Text+ausgabetext[i]; end;{end of for} end;{end of else} end; procedure TForm1.BitBtn2Click(Sender: TObject); var i:byte; begin laenge:=0; Edit1.Text:=''; Edit3.Text:=''; Edit4.Text:=IntToStr(laenge); for i:=65 to 90 do {alle Häufigkeiten werden Null gesetzt} begin{begin of for} anzahl[i]:=0; end;{end of for} end; procedure TForm1.Button2Click(Sender: TObject); var i:integer; begin for i:=65 to 90 do {alle Häufigkeiten werden Null gesetzt} begin{begin of for} anzahl[i]:=0; end;{end of for} Form2.Visible:=true; Form1.Visible:=false; for i:=0 to laenge do begin{begin of for} case ausgabetext[i] of 'A': begin{begin of branch 'A'} inc(anzahl[65]); end;{end of branch 'A'} 'B': begin{begin of branch 'B'} inc(anzahl[66]); end;{end of branch 'B'} 'C': begin{begin of branch 'C'} inc(anzahl[67]); end;{end of branch 'C'} 'D': begin{begin of branch 'D'} inc(anzahl[68]); end;{end of branch 'D'} 'E': begin{begin of branch 'E'} inc(anzahl[69]); end;{end of branch 'E'} 'F': begin{begin of branch 'F'} inc(anzahl[70]); end;{end of branch 'F'} 'G': begin{begin of branch 'G'} inc(anzahl[71]); end;{end of branch 'G'} 'H': begin{begin of branch 'H'} inc(anzahl[72]); end;{end of branch 'H'} 'I': begin{begin of branch 'I'} inc(anzahl[73]); end;{end of branch 'I'} 'J': begin{begin of branch 'J'} inc(anzahl[74]); end;{end of branch 'J'} 'K': begin{begin of branch 'K'} inc(anzahl[75]); end;{end of branch 'K'} 'L': begin{begin of branch 'L'} inc(anzahl[76]); end;{end of branch 'L'} 'M': begin{begin of branch 'M'} inc(anzahl[77]); end;{end of branch 'M'} 'N': begin{begin of branch 'N'} inc(anzahl[78]); end;{end of branch 'K'} 'O': begin{begin of branch 'O'} inc(anzahl[79]); end;{end of branch 'O'} 'P': begin{begin of branch 'P'} inc(anzahl[80]); end;{end of branch 'P'} 'Q': begin{begin of branch 'Q'} inc(anzahl[81]); end;{end of branch 'Q'} 'R': begin{begin of branch 'R'} inc(anzahl[82]); end;{end of branch 'R'} 'S': begin{begin of branch 'S'} inc(anzahl[83]); end;{end of branch 'S'} 'T': begin{begin of branch 'T'} inc(anzahl[84]); end;{end of branch 'T'} 'U': begin{begin of branch 'U'} inc(anzahl[85]); end;{end of branch 'U'} 'V': begin{begin of branch 'V'} inc(anzahl[86]); end;{end of branch 'V'} 'W': begin{begin of branch 'W'} inc(anzahl[87]); end;{end of branch 'W'} 'X': begin{begin of branch 'X'} inc(anzahl[88]); end;{end of branch 'X'} 'Y': begin{begin of branch 'Y'} inc(anzahl[89]); end;{end of branch 'Y'} 'Z': begin{begin of branch 'Z'} inc(anzahl[90]); end;{end of branch 'Z'} end;{end of case} end;{end of for} Form2.Edit1.Text:=IntToStr(anzahl[65]); Form2.Edit2.Text:=IntToStr(anzahl[66]); Form2.Edit3.Text:=IntToStr(anzahl[67]); Form2.Edit4.Text:=IntToStr(anzahl[68]); Form2.Edit5.Text:=IntToStr(anzahl[69]); Form2.Edit6.Text:=IntToStr(anzahl[70]); Form2.Edit7.Text:=IntToStr(anzahl[71]); Form2.Edit8.Text:=IntToStr(anzahl[72]); Form2.Edit9.Text:=IntToStr(anzahl[73]); Form2.Edit10.Text:=IntToStr(anzahl[74]); Form2.Edit11.Text:=IntToStr(anzahl[75]); Form2.Edit12.Text:=IntToStr(anzahl[76]); Form2.Edit13.Text:=IntToStr(anzahl[77]); Form2.Edit14.Text:=IntToStr(anzahl[78]); Form2.Edit15.Text:=IntToStr(anzahl[79]); Form2.Edit16.Text:=IntToStr(anzahl[80]); Form2.Edit17.Text:=IntToStr(anzahl[81]); Form2.Edit18.Text:=IntToStr(anzahl[82]); Form2.Edit19.Text:=IntToStr(anzahl[83]); Form2.Edit20.Text:=IntToStr(anzahl[84]); Form2.Edit21.Text:=IntToStr(anzahl[85]); Form2.Edit22.Text:=IntToStr(anzahl[86]); Form2.Edit23.Text:=IntToStr(anzahl[87]); Form2.Edit24.Text:=IntToStr(anzahl[88]); Form2.Edit25.Text:=IntToStr(anzahl[89]); Form2.Edit26.Text:=IntToStr(anzahl[90]); end; procedure TForm1.Button3Click(Sender: TObject); {hier wird nur nach den ersten neun Häufigkeiten gesucht, der Rest macht eh keinen Sinn mehr} var i:byte; j:byte; max:integer; begin Form3.Visible:=true; for i:=65 to 90 do {Erstellen der Kopie des Feldes, um es anschließend partiell zerstören zu können - ich such die ersten 9} begin{begin of for} copy[i]:=anzahl[i]; end;{end of for} for i:=1 to 9 do begin{begin of for1} max:=65; for j:=66 to 90 do begin{begin of for2} if copy[j]>copy[max] then begin{begin of then} max:=j; end;{end of then} end;{end of for2} platz[i]:=max; copy[max]:=0;{aktuelles Maximum aus der Liste streichen} end;{end of for1} Form3.Edit1.Text:=Chr(platz[1]); Form3.Edit2.Text:=Chr(platz[2]); Form3.Edit3.Text:=Chr(platz[3]); Form3.Edit4.Text:=Chr(platz[4]); Form3.Edit5.Text:=Chr(platz[5]); Form3.Edit6.Text:=Chr(platz[6]); Form3.Edit7.Text:=Chr(platz[7]); Form3.Edit8.Text:=Chr(platz[8]); Form3.Edit9.Text:=Chr(platz[9]); end; end.