ISO 7064
From Free Pascal wiki
Revision as of 09:08, 4 December 2021 by Trev (talk | contribs) (→Function StrMOD97: Further specificity)
│
English (en) │
français (fr) │
Overview
ISO 7064 specifies a set of check character systems capable of protecting strings against errors which occur when people copy or key data.
The check character systems specified in ISO/IEC 7064:2002 can detect:
- all single substitution errors (the substitution of a single character for another, for example 4234 for 1234);
- all or nearly all single (local) transposition errors (the transposition of two single characters, either adjacent or with * one character between them, for example 12354 or 12543 for 12345);
- all or nearly all shift errors (shifts of the whole string to the left or right);
- a high proportion of double substitution errors (two separate single substitution errors in the same string, for example 7234587 for 1234567);
- a high proportion of all other errors.
Function StrMOD97
The function StrMOD97 can encode and verify a check character (an added character which may be used to verify the accuracy of the string by a mathematical relationship to that string) and a supplementary check character (a character which does not belong to the character set of the strings which are to be protected) in accordance with ISO 7064, modulo 97-10 for numeric strings with two check digits.
function StrMOD97(s: String): integer;
// Pre-condition: s can only contain digits, otherwise this function will raise an exception.
// See https://wiki.freepascal.org/International_Bank_Account_Number for handling non digits
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
- International Bank Account Number an example of usage of the above function handling both digits and non-digits.