Einzelnen Beitrag anzeigen

qwertz543221
(Gast)

n/a Beiträge
 
#16

Re: Umwandlung charkombination nach integer

  Alt 2. Sep 2009, 20:59
ok geht danke
hier das bisherige
Delphi-Quellcode:
function tform1.rsaenc(text:ansistring;n:ansistring):ansistring;
var
l:int64;
wa,zahl:ansistring;
begin
result:='';
mathe:=tmathe.Create;
l:=length(text);
while l mod 4 <>0
  do
  begin
  text:=text+chr(0);
  l:=length(text)
  end;
  i:=1;
  while i<=l do
begin
application.ProcessMessages;
if i mod 4 =0
    then
    begin
   // wa:=mathe.summe(mathe.produkt(inttostr(ord(text[i])),'256'),inttostr(ord(text[i+1])));
    wa:=inttostr(combtonum(text[i-3]+text[i-2]+text[i-1]+text[i]));
    wa:=mathe.PotenzModulo(wa,e,n);
    zahl:=wa;
   if length(zahl)<length(n)
      then
        while length(zahl)<>length(n) do
        zahl:='0'+zahl;
 result:=result+zahl;
  end;
 inc(i);
end;
end;

function tform1.rsadec(text:ansistring;d,n:ansistring):ansistring;
var
i:int64;
wa,z1,z2,z3,m_1,m_2,m,h:ansistring;
zahl:ansistring;

begin
result:='';
m_1:='0';
m_2:='0';
m:='0';
h:='0';
mathe:=tmathe.Create;
i:=1;
{
//chinesischer Restsatz:=>Fehlerhaft!!!
      dp:=modinvers(e,mathe.Differenz(p,'1'));
      dq:=modinvers(e,mathe.Differenz(q,'1'));
       qinv:=modinvers(p,q);     }

 while i<=length(text) do
  begin
  application.ProcessMessages;
  zahl:=copy(text,i,length(n));
  wa:=zahl;
  wa:=mathe.PotenzModulo(wa,d,n);


    //result:=result+chr(strtoint(mathe.Quotient(wa,'256')))+chr(strtoint(mathe.Modulo(wa,'256')));
  result:=result+numtocomb(strtoint(wa));
  i:=i+length(n)
  end;
   end;

function TForm1.numtocomb(num:longint):string;
var b1,b2,b3,b4:char;
begin
result:='';
b1 := Chr(num shr 24);
b2 := Chr(num shr 16 and $000000FF);
b3 := Chr(num shr 8 and $000000FF);
b4 := Chr(num and $000000FF);
result:=b1+b2+b3+b4;
end;


function TForm1.combtonum(comb:string):longint;
begin
result:=Ord(comb[1]) shl 24 or Ord(comb[2]) shl 16 or Ord(comb[3]) shl 8 or Ord(comb[4])
end;
  Mit Zitat antworten Zitat