AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Object-Pascal / Delphi-Language Delphi Eingabezahlen aus Editfeld in Bytearray einlesen
Thema durchsuchen
Ansicht
Themen-Optionen

Eingabezahlen aus Editfeld in Bytearray einlesen

Ein Thema von Amina · begonnen am 5. Jun 2009 · letzter Beitrag vom 6. Jun 2009
Antwort Antwort
Amina

Registriert seit: 5. Jun 2009
3 Beiträge
 
#1

Re: Eingabezahlen aus Editfeld in Bytearray einlesen

  Alt 5. Jun 2009, 20:38
Nochmals vielen Dank. Ich denke ich habe es jetzt so implementiert und damit ein Problem gelöst.


Jedoch kommt immernoch diesselbe Fehlermeldung.
Mein aktueller Quellcode ist der folgende (das Programm liegt nochmals im Anhang bei):
Der Fehler tritt bei der Prozedur TForm1.Button2Click unter case of :3 auf.

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, math;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    RadioGroup: TRadioGroup;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Button1: TButton;
    Benutzeranweisung: TLabel;
    Eingabeanweisung: TLabel;
    Information1: TLabel;
    Information2: TLabel;
    Ausgabeinformation: TLabel;
    B1: TLabel;
    B2: TLabel;
    Eingabe: TEdit;
    Ausgabe: TLabel;
    Button2: TButton;
    Zusatzlabel: TLabel;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function ggt(a,b:integer):integer;
begin
 while b<>0 do
 if a > b then a:=a - b else b:=b - a;
ggt:=a;
end;

Function isPrimzahl(Value: integer): Boolean;
Var
  i, t: Integer;
Begin
  t := round(sqrt(Value));
  For i := 2 To t Do
    If Value Mod i = 0 Then Begin
      result := false;
      exit;
    End;
  result := true;
End;

function PosEx(const Substr: string; const S: string; Offset: Integer): Integer;
begin
  if Offset <= 0 then Result := 0
  else
    Result := Pos(Substr, Copy(S, Offset, Length(S)));

  if Result <> 0 then
    Result := Result + Offset - 1;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
case radiogroup.ItemIndex of
0: begin
        Label5.Caption := 'P';
        Label6.Caption := 'Q';
        Label3.Caption := 'Primzahlen';
        Eingabe.Visible := false;
        Zusatzlabel.Visible := true;
        Benutzeranweisung.Caption := 'Bitte geben Sie die Primzahlen P und Q ein.';
        Eingabeanweisung.Caption := 'Berechnung von N:';
        Information1.Caption := 'Berechnung von M:';
        Information2.Caption := 'Berechnung von E:';
        Ausgabeinformation.Caption := 'Berechnung von D:';
        B1.Caption := '';
        B2.Caption :='';
        Ausgabe.Caption := '';

end;
1: begin
        Label5.Caption := 'N';
        Label6.Caption := 'E';
        Label3.Caption := 'öffentlich';
        Zusatzlabel.Visible := false;
        Eingabe.Visible := true;
        Benutzeranweisung.Caption := 'Bitte geben Sie die öffentlichen Schlüssel E und N ein.';
        Eingabeanweisung.Caption := 'Bitte geben Sie den zu verschlüsselnden Text ein:';
        Information1.Caption := 'Umwandlung der Buchstaben in Zahlen:';
        Information2.Caption := 'Anwendung des Verschlüsselungsalgorithmus (C=K^E mod N):';
        Ausgabeinformation.Caption := 'verschlüsselter Text';
        B1.Caption := '';
        B2.Caption :='';
        Ausgabe.Caption := '';
   end;
2: begin
        Label5.Caption := 'N';
        Label6.Caption := 'E';
        Label3.Caption := 'öffentlich';
        Zusatzlabel.Visible := false;
        Eingabe.Visible := true;
        Benutzeranweisung.Caption := 'Bitte geben Sie den privaten Schlüssel D ein.';
        Eingabeanweisung.Caption := 'Bitte geben Sie den zu entschlüsselnden Text ein:';
        Information1.Caption := 'Anwendung des Entschlüsselungsalgorithmus (K=C^D mond N):';
        Information2.Caption := 'Umwandlung der Zahlen in Buchstaben:';
        Ausgabeinformation.Caption := 'entschlüsselter Text';
        B1.Caption := '';
        B2.Caption :='';
        Ausgabe.Caption := '';
        Edit1.Text := '';
end;

end
end;

procedure TForm1.Button2Click(Sender: TObject);
var p, i,j ,q,ofs, n, d,position, m, e, laenge, klartextlaenge : integer;
speicher : extended;
tmp : string;
Eingabe, Ausgabe : AnsiString;
code: array of byte;

begin
case radiogroup.ItemIndex of
0: begin
    p := strtoint(edit1.Text); //Einlesen der Eingabewerte
    q := strtoint(edit3.Text);
    if (IsPrimzahl(p)=false) or (IsPrimzahl(q)=false) or (p=q) then Messagebox(0,'Bitte geben sie zwei unterschiedliche Primzahlen für P und Q ein. Ansonsten wird der Verschlüsselungsalgorithmus mit hoher Wahrscheinlichkeit nicht funktionieren','Warnung',MB_OK);
    n := p*q; //Bestimmen von n
    m := (p-1)*(q-1); //Bestimmen von m
    i := 2; //Bestimmen von e
    repeat
      e := i;
      i := i+1;
    until (i+1 = n) or (ggt(e,m)=1);
    i := 1;
    repeat //Bestimmen von d
      d := i;
      i := i+1;
    until ((d*e)mod m =1) and (d <> e);
    Zusatzlabel.Caption := inttostr(n); //Ausgabe der Schlüssel
    B1.Caption := inttostr(m);
    B2.Caption :=inttostr(e);
    Form1.Ausgabe.Caption := inttostr(d);
      Edit1.Text := inttostr(n);
    Edit2.Text := inttostr(d);
    Edit3.Text := inttostr(e);

end;

1: begin
Eingabe := Form1.Eingabe.Text; //Einlesen der Eingabewerte
e :=strtoint(edit3.Text);
n :=strtoint(edit1.Text);
Eingabe := Form1.Eingabe.Text;
laenge := length(Eingabe);
SetLength(Code, laenge+1);

for i := 1 to laenge do code[i] := ord(Eingabe[i]);

Ausgabe :='';
for i:=1 to laenge do begin //Ausgabe des verschlüsselten Textes
Ausgabe := Ausgabe + ' ' + inttostr(code[i]);
end;
B1.Caption := Ausgabe;
for i := 1 to laenge do begin //Anwendung des Verschlüsselungalgorithmusses
speicher := 1;
for j := 1 to e do begin
speicher := speicher * code[i];
speicher := speicher - (Trunc(speicher/n) * n); //modfunktion für extended
end;
code[i] := round(speicher);
end;

Ausgabe :='';
for i:=1 to laenge do begin //Ausgabe des verschlüsselten Textes
Ausgabe := Ausgabe + ' ' + inttostr(code[i]);
end;
B2.Caption := Ausgabe;
end;

2: begin
Eingabe := Form1.Eingabe.Text; //Einlesen der Eingabewerte
laenge := length(Eingabe);
d :=strtoint(edit2.Text);
n :=strtoint(edit1.Text);
klartextlaenge := 0;
  ofs := PosEx(#32, Eingabe, 0);
  while ofs <> 0 do
  begin
    tmp := copy(Eingabe, 0, ofs - 1);
    SetLength(code, length(code) + 1);
    code[High(code)] := StrToInt(tmp);
    delete(Eingabe, 1, ofs);
    ofs := PosEx(#32, Eingabe, ofs);
  end;
//repeat //Einteilen des Strings in Einzelzahlen
//position := PosEx(' ', Eingabe, 1);
//Delete(Eingabe, 1, position);
//zwischenspeicherstring := Copy(Eingabe, 1, position-1);
//klartextlaenge := klartextlaenge + 1;
//code[klartextlaenge] := strtoint(zwischenspeicherstring);
//until PosEx(' ', Eingabe, 1) =0;

Ausgabe := ''; //Ausgabe der Einzelzahlen
for i:=1 to klartextlaenge do begin
Ausgabe := Ausgabe + inttostr(code[i]);
end;
B1.Caption := Ausgabe;

for i := 1 to klartextlaenge do begin //Anwendung des Verschlüsselungalgorithmusses
speicher := 1;
for j := 1 to d do begin
speicher := speicher * code[i];
speicher := speicher - (Trunc(speicher/n) * n); //modfunktion für extended
end;
code[i] := round(speicher);
end;
Ausgabe := ''; //Augabe des Entschlüsselten Textes
for i:=1 to klartextlaenge do begin
Ausgabe := Ausgabe + chr(code[i]);
end;
B2.Caption := Ausgabe;
end;
end;
end;
end.
Ich hoffe mir kann jemand helfen.
Angehängte Dateien
Dateityp: zip rsa_124.zip (274,2 KB, 2x aufgerufen)
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:03 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz