Einzelnen Beitrag anzeigen

qwertz543221
(Gast)

n/a Beiträge
 
#18

Re: Chinesischer Restsatz, pseudocode gesucht

  Alt 5. Okt 2009, 18:26
Das ganze soll auch nicht nach dem original schema x°d mod n berechnet werden, da genau dies zu langsam ist., Deshalb erfolgt eine aufteilung.
Delphi-Quellcode:
 function tform1.rsadec2(text:ansistring;d,n:ansistring):ansistring;
var
i,j:int64;
wa,h:ansistring;

begin
result:='';
mathe:=tmathe.Create;
i:=1;

 while i<=length(text) do
  begin
  application.ProcessMessages;
wa:='';
 j:=i;
 while j<i+length(n) do
 begin
 wa:=wa+text[j];
 j:=j+1;
 end;
 cp:=mathe.Modulo(wa,p);
 cq:=mathe.Modulo(wa,q);
dp:= mathe.modulo(d, mathe.differenz(p,'1');
dq:= mathe.modulo(d, mathe.differenz(q,'1');

//hier ist doch potenzmod(), der quelle nach ist insgesamt nur zweimal potenzmod anzuwenden:

 mp:=mathe.PotenzModulo(cp,dp,p);
 mq:=mathe.PotenzModulo(cq,dq,q) ;

 wa:=mathe.Modulo(mathe.Summe(mathe.Produkt(mathe.Produkt(mp,yq),q),mathe.Produkt(mathe.Produkt(mq,yp),p)),n);
 // result:=result+numtotext(wa);
  i:=i+length(n)
  end;
   end;

procedure Tform1.DECmitChinRS1Click(Sender: TObject);
var d,n:ansistring;
function rsadec2(text:ansistring;d,n:ansistring):ansistring;
var
i,j:int64;
c,h,m:ansistring;

begin
result:='';
mathe:=tmathe.Create;
i:=1;
 while i<=length(text) do
  begin
  application.ProcessMessages;
c:='';
 j:=i;
 while j<i+length(n) do
 begin
 c:=c+text[j];
 j:=j+1;
 end;
 cp:=mathe.Modulo(c,p);
 cq:=mathe.Modulo(c,q);
 m:=mathe.modulo(mathe.Summe((mathe.produkt(mathe.produkt(mp,yq),q)),(mathe.produkt(mathe.produkt(mq,yp),p))),n) ;

 result:=result+numtocomb(strtoint(m));
 i:=i+length(n);

  end;
   end;
  begin
try
d:=(labeledEdit1.Text);
n:=(LabeledEdit2.Text);
memo2.Lines.add(datetimetostr(now)+': RSA - Starte Dechiffrierung mit chin RS.');
memo1.Text:=rsadec(memo1.Text,d,n);
memo2.Lines.add(datetimetostr(now)+': RSA - Dechiffriert mit chin RS.');
memo2.lines.add('---------------------------------------------------');
except
on e:exception do
begin
e.Message;
memo2.Lines.add(datetimetostr(now)+': RSA - Dechiffrierung fehlgeschlagen.');
memo2.lines.add('---------------------------------------------------');
end;
 end;
end;
  Mit Zitat antworten Zitat