Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
|
|
@ -0,0 +1,54 @@
|
|||
array base 1
|
||||
|
||||
dim test_set$(7)
|
||||
test_set$ = {"US0378331005", "US0373831005", "U50378331005", "US03378331005", "AU0000XVGZA3", "AU0000VXGZA3", "FR0000988040"}
|
||||
|
||||
for i = 1 to test_set$[?]
|
||||
test_str$ = ""
|
||||
l = length(test_set$[i])
|
||||
if l <> 12 then
|
||||
print test_set$[i]; " Invalid, length <> 12 char."
|
||||
continue for
|
||||
end if
|
||||
if asc(mid(test_set$[i], 1, 1)) < asc("A") or asc(mid(test_set$[i], 2, 1)) < asc("A") then
|
||||
print test_set$[i]; " Invalid, number needs to start with 2 characters"
|
||||
continue for
|
||||
end if
|
||||
for n = 1 to l
|
||||
x = asc(mid(test_set$[i], n, 1)) - asc("0")
|
||||
if x > 9 then x -= 7
|
||||
if x < 10 then
|
||||
test_str$ += string(x)
|
||||
else # two digest number
|
||||
test_str$ += string(x \ 10) + string(x mod 10)
|
||||
end if
|
||||
next
|
||||
print test_set$[i]; " ";
|
||||
if luhntest(test_str$) = 1 then
|
||||
print "Invalid, checksum error"
|
||||
else
|
||||
print "Valid"
|
||||
end if
|
||||
next
|
||||
end
|
||||
|
||||
function luhntest(cardnr$)
|
||||
cardnr$ = trim(cardnr$) # remove spaces
|
||||
l = length(cardnr$)
|
||||
s1 = 0
|
||||
s2 = 0
|
||||
|
||||
# sum odd numbers
|
||||
for i = 1 to l step 2
|
||||
s1 += fromradix(asc(mid(cardnr$, i, 1)), 10)
|
||||
next
|
||||
# sum even numbers
|
||||
for i = 2 to l step 2
|
||||
j = fromradix(asc(mid(cardnr$, i, 1)), 10)
|
||||
j *= 2
|
||||
if j > 9 then j = (j mod 10) + 1
|
||||
s2 += j
|
||||
next
|
||||
|
||||
return (s1 + s2) mod 10 = 0
|
||||
end function
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
bool checkISIN(String isin) {
|
||||
int j = 0, v = 0;
|
||||
List<int> s = List.filled(24, 0);
|
||||
|
||||
for (int i = 0; i < 12; i++) {
|
||||
int k = isin.codeUnitAt(i);
|
||||
if (k >= '0'.codeUnitAt(0) && k <= '9'.codeUnitAt(0)) {
|
||||
if (i < 2) return false;
|
||||
s[j++] = k - '0'.codeUnitAt(0);
|
||||
} else if (k >= 'A'.codeUnitAt(0) && k <= 'Z'.codeUnitAt(0)) {
|
||||
if (i == 11) return false;
|
||||
k -= 'A'.codeUnitAt(0) - 10;
|
||||
s[j++] = k ~/ 10;
|
||||
s[j++] = k % 10;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isin.length > 12) return false;
|
||||
|
||||
for (int i = j - 2; i >= 0; i -= 2) {
|
||||
int k = 2 * s[i];
|
||||
v += k > 9 ? k - 9 : k;
|
||||
}
|
||||
|
||||
for (int i = j - 1; i >= 0; i -= 2) {
|
||||
v += s[i];
|
||||
}
|
||||
|
||||
return v % 10 == 0;
|
||||
}
|
||||
|
||||
void main() {
|
||||
List<String> test = [
|
||||
"US0378331005",
|
||||
"US0373831005",
|
||||
"U50378331005",
|
||||
"US03378331005",
|
||||
"AU0000XVGZA3",
|
||||
"AU0000VXGZA3",
|
||||
"FR0000988040"
|
||||
];
|
||||
|
||||
for (String isin in test) {
|
||||
print('$isin - ${checkISIN(isin)}');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
func isin t$ .
|
||||
if len t$ <> 12
|
||||
return 0
|
||||
.
|
||||
for i to 12
|
||||
k = strcode substr t$ i 1
|
||||
if k >= 48 and k <= 57
|
||||
if i <= 2
|
||||
return 0
|
||||
.
|
||||
s[] &= k - 48
|
||||
elif k >= 65 and k <= 91
|
||||
if (i = 12)
|
||||
return 0
|
||||
.
|
||||
k -= 55
|
||||
s[] &= k div 10
|
||||
s[] &= k mod 10
|
||||
else
|
||||
return 0
|
||||
.
|
||||
.
|
||||
i = len s[] - 1
|
||||
while i >= 1
|
||||
k = 2 * s[i]
|
||||
if k > 9
|
||||
k -= 9
|
||||
.
|
||||
v += k
|
||||
i -= 2
|
||||
.
|
||||
i = len s[]
|
||||
while i >= 1
|
||||
v += s[i]
|
||||
i -= 2
|
||||
.
|
||||
if v mod 10 = 0
|
||||
return 1
|
||||
.
|
||||
.
|
||||
test$[] = [ "US0378331005" "US0373831005" "U50378331005" "US03378331005" "AU0000XVGZA3" "AU0000VXGZA3" "FR0000988040" ]
|
||||
for t$ in test$[]
|
||||
if isin t$ = 1
|
||||
print t$ & " is valid"
|
||||
else
|
||||
print t$ & " is invalid"
|
||||
.
|
||||
.
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import "/str" for Char
|
||||
import "/iterate" for Stepped
|
||||
import "/fmt" for Conv, Fmt
|
||||
import "./str" for Char
|
||||
import "./iterate" for Stepped
|
||||
import "./fmt" for Conv, Fmt
|
||||
|
||||
var luhn = Fn.new { |s|
|
||||
s = s[-1..0]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue