RosettaCodeData/Task/Validate-International-Securities-Identification-Number/FutureBasic/validate-international-securities-identification-number.basic
2026-02-01 16:33:20 -08:00

42 lines
1.1 KiB
Text

//
// Validate International Securities Identification Number
// Using FutureBasic 7.0.33, December 2024 R.W.
//
// At entry ISIN string
// Exits with Boolean Valid or Invalid
//
local fn ISINisValid (ISIN as CFStringRef) as Boolean
// Base36 = @"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Int r, v = 0, c, x2(9) = {0,2,4,6,8,1,3,5,7,9}
if len(ISIN) <> 12 then return _False
if ucc(ISIN, 0) < _"A" || ucc(ISIN, 1) < _"A" then return _False
// convert Base 36 digits to Base 10
uint64 n = 0
for r = 0 to len(ISIN) - 1
c = ucc(ISIN, r)
select
case c >= _"A" && c <= _"Z" : n = n * 100 + c - 55
case c >= _"0" && c <= _"9" : n = n * 10 + c - 48
case else : return _False
end select
next
// Luhn test
while n
v += n % 10 + x2(n / 10 % 10)
n /= 100
wend
end fn = !(v mod 10)
window 1,@"Validate ISIN"
//Test data
CFStringRef cc(6) = {@"US0378331005", @"US0373831005", @"U50378331005", ¬
@"US03378331005", @"AU0000XVGZA3", @"AU0000VXGZA3", @"FR0000988040"}
for int x = 0 to 6
print cc(x),
if fn ISINisValid(cc(x)) then print @"Valid" else print @"Invalid"
next
handleEvents