Einzelnen Beitrag anzeigen

shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#6

AW: IBAN berechnen

  Alt 15. Nov 2010, 17:31
Hier hab ich mal die Kernfunktion "Modulo 97" entworfen.
Delphi-Quellcode:
// Berechne Modulo 97 Prüfziffer
// wird für IBAN benötigt
function Modulo97PruefZiffer(const X:string):Integer;
const
   m36:string = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var
   i, p : Integer;
begin
   Result := 0;

   for i := 1 to Length(X) do
   begin
      p := Pos(X[i], m36) ;
      if p = 0 then
         raise Exception.CreateFmt('Modulo97PruefZiffer(%s): invalid data', [X]);
      Dec(p);
      if p > 9 then
      begin
         Result := Result * 10 + (p div 10);
         p := p mod 10;
      end;
      Result := Result * 10 + p;
      Result := Result mod 97;
   end;
end;
Und hier noch die Test-Cases.
Die Funktion ist also getestet und dürfte korrekt sein.
Delphi-Quellcode:
Assert(Modulo97PruefZiffer('50000')=45);
Assert(Modulo97PruefZiffer('210501700012345678131468')=1);
Assert(Modulo97PruefZiffer('210501700012345678DE68')=1);
Andreas

Geändert von shmia (15. Nov 2010 um 17:34 Uhr)
  Mit Zitat antworten Zitat