Einzelnen Beitrag anzeigen

Benutzerbild von kwhk
kwhk

Registriert seit: 25. Mär 2009
Ort: Dresden
168 Beiträge
 
Delphi 10.3 Rio
 
#4

AW: Prüfziffer für IBAN berechnen

  Alt 12. Sep 2013, 12:05
So habe ich das gelöst, die 24-stellige Zahl in 18 + 6 Stellen aufgeteilt und solange 97 abgezogen, bis ein Rest von < 97 übrigbleibt. Damit es schneller geht, auch das 10er-Vielfache von 97 abgezogen. Das ist mathematisch korrekt und man vermeidet das unmittelbare Rechnen (Division) mit einer so großen Zahl. Was fehlt, ist INT128 oder eine andere Zahlendarstellung.
Auf dem IBM-Großrechner (wo ich herkomme) gibt es das dezimal-gepackte Format (DP).
Eine 9-stellige Zahl steht in 5 Bytes sieht dann so aus: X'123456789C' das C ist das Vorzeichen (C für + und D für Minus) Es sind max. 16 Bytes möglich, das sind 31 Ziffern. Die 24-stellige BBAN würde also kein Problem machen, und das ist schon seit 1960 so. Auf dem PC gibt es nun riesengroße Festplatten, riesengroßen Hauptspeicher... Aber mit großen Zahlen kann er immer noch nicht rechnen.
Code:
    sBBAN := sBLZ+sKTO;   // 6-st + 8-st
    Val(sBBAN,iBBAN,rc);  // die ersten 14 Stellen modulo 97 rechnen mittels Subtraktion

    While iBBAN > 970 do
      Begin
            if iBBAN > 970000000000000000 then iBBAN := iBBAN - 970000000000000000
        else if iBBAN > 97000000000000000 then iBBAN := iBBAN -  97000000000000000
        else if iBBAN >  9700000000000000 then iBBAN := iBBAN -   9700000000000000
        else if iBBAN >   970000000000000 then iBBAN := iBBAN -    970000000000000
        else if iBBAN >    97000000000000 then iBBAN := iBBAN -     97000000000000
        else if iBBAN >     9700000000000 then iBBAN := iBBAN -      9700000000000
        else if iBBAN >      970000000000 then iBBAN := iBBAN -       970000000000
        else if iBBAN >       97000000000 then iBBAN := iBBAN -        97000000000
        else if iBBAN >        9700000000 then iBBAN := iBBAN -         9700000000
        else if iBBAN >         970000000 then iBBAN := iBBAN -          970000000
        else if iBBAN >          97000000 then iBBAN := iBBAN -           97000000
        else if iBBAN >           9700000 then iBBAN := iBBAN -            9700000
        else if iBBAN >            970000 then iBBAN := iBBAN -             970000
        else if iBBAN >             97000 then iBBAN := iBBAN -              97000
        else if iBBAN >              9700 then iBBAN := iBBAN -               9700
        else if iBBAN >               970 then iBBAN := iBBAN -                970;
      End; // While iBBAN > 970

    iBBAN := (iBBAN * 1000000) + 131400; // 6 Dezimalstellen nach links + Rest

    While iBBAN > 96 do // nun weiter mit modulo 97
      Begin
            if iBBAN > 970000000 then iBBAN := iBBAN - 970000000
        else if iBBAN > 97000000 then iBBAN := iBBAN -  97000000
        else if iBBAN >  9700000 then iBBAN := iBBAN -   9700000
        else if iBBAN >   970000 then iBBAN := iBBAN -    970000
        else if iBBAN >    97000 then iBBAN := iBBAN -     97000
        else if iBBAN >     9700 then iBBAN := iBBAN -      9700
        else if iBBAN >      970 then iBBAN := iBBAN -       970
        else if iBBAN >       96 then iBBAN := iBBAN -        97;
      End; // While iBBAN > 96

    iPZ := 98 - iBBAN; // Prüfziffer = 98 - (Rest von mod97)
Hartmut

Geändert von kwhk (12. Sep 2013 um 12:39 Uhr)
  Mit Zitat antworten Zitat