1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85:
| unit caesar;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TDatei = File of char; TForm1 = class(TForm) Button1: TButton; Edit2: TEdit; Memo1: TMemo; Button2: TButton; Memo2: TMemo; procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private public end;
var klartext:string; Form1: TForm1; quelle:TDatei; ziel:TDatei;
implementation
{$R *.dfm}
function ccrypt(input:string; cinput:char):string; var i, stellen:integer; output:string; begin stellen:=ord(cinput)-65; output:='';
for i:=1 to length(input) do begin if ((ord(input[i])>64) and (ord(input[i])<91)) then output[i]:=char(((ord(output[i])-65+stellen)mod 26)+65);
if ((ord(input[i])>96) and (ord(input[i])<123)) then output[i]:=char(((ord(output[i])-97+stellen)mod 26)+97);
end; result:=output; end;
procedure TForm1.Button1Click(Sender: TObject); var dummy:string; var cinput:char; begin cinput:=Edit2.Text[1]; dummy:=ccrypt(klartext,cinput); Memo2.Lines.Add(dummy); end;
procedure TForm1.FormCreate(Sender: TObject); begin assignfile(quelle, 'msg.txt'); assignfile(ziel, 'cryptedmsg.txt'); rewrite(ziel); end;
procedure TForm1.Button2Click(Sender: TObject); var ch:char; begin reset(quelle); klartext:=''; while not(EOF(quelle)) do begin read(quelle, ch); klartext:=klartext+ch; end; closefile(quelle); Memo1.Lines.Add(klartext); end;
end. |