Difference between revisions of "ISO 7064"

From Free Pascal wiki
Jump to navigationJump to search
(→‎Function StrMOD97: pre-condition)
m (→‎See also: Fix page link formatting)
(One intermediate revision by the same user not shown)
Line 9: Line 9:
 
<syntaxhighlight lang=pascal>
 
<syntaxhighlight lang=pascal>
 
function StrMOD97(s: String): integer;
 
function StrMOD97(s: String): integer;
//Pre-condition: s can only contain digits, otherwise this function wil raise an exception.
+
//Pre-condition: s can only contain digits, otherwise this function will raise an exception.
 
const
 
const
 
   modu = 97;
 
   modu = 97;
Line 33: Line 33:
 
end;     
 
end;     
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
== See also ==
 +
 +
* [[International Bank Account Number]] an example of usage of the above function.

Revision as of 06:31, 30 November 2021

English (en) français (fr)

ISO 7064 specifies a set of check character systems capable of protecting strings against errors which occur when people copy or key data.

Function StrMOD97

The function StrMOD97 can encode and verify number checksum with ISO 7064.

function StrMOD97(s: String): integer;
//Pre-condition: s can only contain digits, otherwise this function will raise an exception.
const
  modu = 97;
var
  sx: String;
  isx, ic, p: Integer;
begin
   p := Length( s );
   while ( p > 9 ) do
     begin
       sx := Copy( s, 1, 9 );
       Delete( s, 1, 9 );
       isx := StrToInt( sx );
       ic := isx mod modu;
       s := IntToStr( ic ) + s;
       p := Length( s );
     end;
   isx := StrToInt( s );
   if isx >= modu
     then ic := isx mod modu
     else ic := isx;
  result := ic;
end;

See also