June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
50
Task/IBAN/AWK/iban-1.awk
Normal file
50
Task/IBAN/AWK/iban-1.awk
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
@load "ordchr"
|
||||
|
||||
function invalid() { print("INVALID " $0); next }
|
||||
function valid() { print("VALID__ " $0) }
|
||||
|
||||
BEGIN {
|
||||
ccibanlen["AL"] = 28; ccibanlen["AD"] = 24; ccibanlen["AT"] = 20;
|
||||
ccibanlen["AZ"] = 28; ccibanlen["BH"] = 22; ccibanlen["BA"] = 20;
|
||||
ccibanlen["BR"] = 29; ccibanlen["BG"] = 22; ccibanlen["CR"] = 21;
|
||||
ccibanlen["HR"] = 21; ccibanlen["CY"] = 28; ccibanlen["CZ"] = 24;
|
||||
ccibanlen["DK"] = 18; ccibanlen["DO"] = 28; ccibanlen["EE"] = 20;
|
||||
ccibanlen["FO"] = 18; ccibanlen["FI"] = 18; ccibanlen["FR"] = 27;
|
||||
ccibanlen["GE"] = 22; ccibanlen["DE"] = 22; ccibanlen["GI"] = 23;
|
||||
ccibanlen["GR"] = 27; ccibanlen["GL"] = 18; ccibanlen["GT"] = 28;
|
||||
ccibanlen["HU"] = 28; ccibanlen["IS"] = 26; ccibanlen["IE"] = 22;
|
||||
ccibanlen["IT"] = 27; ccibanlen["KZ"] = 20; ccibanlen["KW"] = 30;
|
||||
ccibanlen["LV"] = 21; ccibanlen["LB"] = 28; ccibanlen["LI"] = 21;
|
||||
ccibanlen["LT"] = 20; ccibanlen["LU"] = 20; ccibanlen["MK"] = 19;
|
||||
ccibanlen["MT"] = 31; ccibanlen["MR"] = 27; ccibanlen["MU"] = 30;
|
||||
ccibanlen["MC"] = 27; ccibanlen["MD"] = 24; ccibanlen["ME"] = 22;
|
||||
ccibanlen["NL"] = 18; ccibanlen["NO"] = 15; ccibanlen["PK"] = 24;
|
||||
ccibanlen["PS"] = 29; ccibanlen["PL"] = 28; ccibanlen["PT"] = 25;
|
||||
ccibanlen["RO"] = 24; ccibanlen["SM"] = 27; ccibanlen["SA"] = 24;
|
||||
ccibanlen["RS"] = 22; ccibanlen["SK"] = 24; ccibanlen["SI"] = 19;
|
||||
ccibanlen["ES"] = 24; ccibanlen["SE"] = 24; ccibanlen["CH"] = 21;
|
||||
ccibanlen["TN"] = 24; ccibanlen["TR"] = 26; ccibanlen["AE"] = 23;
|
||||
ccibanlen["GB"] = 22; ccibanlen["VG"] = 24; ccibanlen["BE"] = 16;
|
||||
}
|
||||
|
||||
{
|
||||
iban = toupper($0)
|
||||
gsub(/\s+/, "", iban)
|
||||
ccode = substr(iban, 1, 2)
|
||||
|
||||
if ( ! match(iban, /^[A-Z0-9]+$/) ||
|
||||
! (ccode in ccibanlen) ||
|
||||
length(iban) != ccibanlen[ccode])
|
||||
invalid()
|
||||
|
||||
ibanrev = gensub(/^(.{4})(.+)/, "\\2\\1", 1, iban)
|
||||
ibancsum = ""
|
||||
for (i = 1; i <= length(ibanrev); i++) {
|
||||
currchar = substr(ibanrev, i, 1)
|
||||
if (match(currchar, /[A-Z]/))
|
||||
currchar = ord(currchar) - 55
|
||||
ibancsum = ibancsum currchar
|
||||
}
|
||||
|
||||
ibancsum % 97 == 1 ? valid() : invalid()
|
||||
}
|
||||
9
Task/IBAN/AWK/iban-2.awk
Normal file
9
Task/IBAN/AWK/iban-2.awk
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
cat > test.iban
|
||||
FR33 ^__^ 0BAD
|
||||
AA11 1234 6543 1212
|
||||
FR33 1234 5432
|
||||
CH93 0076 2011 6238 5295 7
|
||||
GB82 WEST 1234 5698 7654 32
|
||||
GB82 TEST 1234 5698 7654 32
|
||||
^D
|
||||
gawk -Mf iban.gawk test.iban
|
||||
6
Task/IBAN/AWK/iban-3.awk
Normal file
6
Task/IBAN/AWK/iban-3.awk
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
INVALID FR33 ^__^ 0BAD
|
||||
INVALID AA11 1234 6543 1212
|
||||
INVALID FR33 1234 5432
|
||||
VALID__ CH93 0076 2011 6238 5295 7
|
||||
VALID__ GB82 WEST 1234 5698 7654 32
|
||||
INVALID GB82 TEST 1234 5698 7654 32
|
||||
124
Task/IBAN/Fortran/iban.f
Normal file
124
Task/IBAN/Fortran/iban.f
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
program ibancheck
|
||||
|
||||
use ISO_FORTRAN_ENV
|
||||
|
||||
implicit none
|
||||
|
||||
character(4), dimension(75) :: cc = (/ &
|
||||
"AD24","AE23","AL28","AT20","AZ28","BA20","BE16","BG22","BH22","BR29", &
|
||||
"BY28","CH21","CR22","CY28","CZ24","DE22","DK18","DO28","EE20","ES24", &
|
||||
"FI18","FO18","FR27","GB22","GE22","GI23","GL18","GR27","GT28","HR21", &
|
||||
"HU28","IE22","IL23","IQ23","IS26","IT27","JO30","KW30","KZ20","LB28", &
|
||||
"LC32","LI21","LT20","LU20","LV21","MC27","MD24","ME22","MK19","MR27", &
|
||||
"MT31","MU30","NL18","NO15","PK24","PL28","PS29","PT25","QA29","RO24", &
|
||||
"RS22","SA24","SC31","SE24","SI19","SK24","SM27","ST25","SV28","TL23", &
|
||||
"TN24","TR26","UA29","VG24","XK20" /)
|
||||
|
||||
character(34), dimension(12) :: ibans = (/ "GB82 WEST 1234 5698 7654 32 ", &
|
||||
"GB82WEST12345698765432 ", &
|
||||
"gb82 west 1234 5698 7654 32 ", &
|
||||
"GB82 TEST 1234 5698 7654 32 ", &
|
||||
"GR16 0110 1250 0000 0001 2300 695 ", &
|
||||
"GB29 NWBK 6016 1331 9268 19 ", &
|
||||
"SA03 8000 0000 6080 1016 7519 ", &
|
||||
"CH93 0076 2011 6238 5295 7 ", &
|
||||
"IL62 0108 0000 0009 9999 999 ", &
|
||||
"IL62-0108-0000-0009-9999-999 ", &
|
||||
"US12 3456 7890 0987 6543 210 ", &
|
||||
"GR16 0110 1250 0000 0001 2300 695X" /)
|
||||
|
||||
integer :: i
|
||||
|
||||
do i=1, size(ibans)
|
||||
if (checkIBAN(trim(ibans(i)))) then
|
||||
print *, " valid IBAN: ", trim(ibans(i))
|
||||
else
|
||||
print *, "invalid IBAN: ", trim(ibans(i))
|
||||
end if
|
||||
end do
|
||||
|
||||
return
|
||||
|
||||
contains
|
||||
|
||||
function checkIBAN(ibancode) result(valid)
|
||||
character(len=*), intent(in) :: ibancode
|
||||
character(len=len(ibancode)) :: iban
|
||||
logical :: valid
|
||||
integer(int32) :: j, ascii, ibanSize
|
||||
character(100) :: ibanRearrange, ibantoint
|
||||
character(2) :: temp
|
||||
valid = .false.
|
||||
|
||||
iban = remove_blanks(ibancode)
|
||||
ibanSize = checkCountryCode(iban)
|
||||
if (ibanSize == len(trim(iban))) then
|
||||
ibanRearrange = iban(5:ibanSize)//iban(1:4)
|
||||
ibantoint = ""
|
||||
do j=1, ibanSize
|
||||
ascii = ichar(ibanRearrange(j:j))
|
||||
if ((ascii >= 65) .and. (ascii<=90)) then
|
||||
write (temp,fmt='(I2)') ascii-55
|
||||
ibantoint = trim(ibantoint) // temp
|
||||
else
|
||||
ibantoint = trim(ibantoint) // ibanRearrange(j:j)
|
||||
end if
|
||||
end do
|
||||
if (mod97(ibantoint) == 1) then
|
||||
valid = .true.
|
||||
end if
|
||||
end if
|
||||
end function checkIBAN
|
||||
|
||||
function mod97(strint) result(res)
|
||||
character(len=*), intent(in) :: strint
|
||||
integer :: i, num, res
|
||||
res = 0
|
||||
do i=1, len(trim(strint))
|
||||
read(strint(i:i),*) num
|
||||
res = mod((res*10 + num),97);
|
||||
end do
|
||||
end function mod97
|
||||
|
||||
function checkCountryCode(iban) result(ibanlength)
|
||||
character(len=*), intent(in) :: iban
|
||||
integer(int16) :: ibanlength, i
|
||||
ibanlength = 0
|
||||
do i=1, size(cc)
|
||||
if (iban(1:2) == cc(i)(1:2)) then
|
||||
read(cc(i)(3:4),*) ibanlength
|
||||
exit
|
||||
end if
|
||||
end do
|
||||
end function checkCountryCode
|
||||
|
||||
Recursive Function Stripper(string,ch) Result(stripped)
|
||||
Implicit None
|
||||
character(len=*), intent(in) :: string
|
||||
character, intent(in) :: ch
|
||||
character(:), allocatable :: stripped
|
||||
|
||||
IF (LEN(string)==1) THEN
|
||||
IF (string==ch) THEN
|
||||
stripped = ''
|
||||
ELSE
|
||||
stripped = string
|
||||
END IF
|
||||
ELSE
|
||||
IF (string(1:1)==ch) THEN
|
||||
stripped = stripper(string(2:),ch)
|
||||
ELSE
|
||||
stripped = string(1:1)//stripper(string(2:),ch)
|
||||
END IF
|
||||
END IF
|
||||
END Function stripper
|
||||
|
||||
Function Remove_Blanks(string) Result(stripped)
|
||||
Implicit None
|
||||
character(len=*), intent(in) :: string
|
||||
character(:), allocatable :: stripped
|
||||
|
||||
stripped = trim(Stripper(trim(Stripper(string,' ')),achar(9)))
|
||||
END Function Remove_Blanks
|
||||
|
||||
end program ibancheck
|
||||
|
|
@ -1,28 +1,22 @@
|
|||
# v0.6.0
|
||||
function validiban(iban::String)
|
||||
const COUNTRY2LENGTH = Dict(
|
||||
"AL" => 28, "AD" => 24, "AT" => 20, "AZ" => 28, "BE" => 16, "BH" => 22, "BA" => 20, "BR" => 29,
|
||||
"BG" => 22, "CR" => 21, "HR" => 21, "CY" => 28, "CZ" => 24, "DK" => 18, "DO" => 28, "EE" => 20,
|
||||
"FO" => 18, "FI" => 18, "FR" => 27, "GE" => 22, "DE" => 22, "GI" => 23, "GR" => 27, "GL" => 18,
|
||||
"GT" => 28, "HU" => 28, "IS" => 26, "IE" => 22, "IL" => 23, "IT" => 27, "KZ" => 20, "KW" => 30,
|
||||
"LV" => 21, "LB" => 28, "LI" => 21, "LT" => 20, "LU" => 20, "MK" => 19, "MT" => 31, "MR" => 27,
|
||||
"MU" => 30, "MC" => 27, "MD" => 24, "ME" => 22, "NL" => 18, "NO" => 15, "PK" => 24, "PS" => 29,
|
||||
"PL" => 28, "PT" => 25, "RO" => 24, "SM" => 27, "SA" => 24, "RS" => 22, "SK" => 24, "SI" => 19,
|
||||
"ES" => 24, "SE" => 24, "CH" => 21, "TN" => 24, "TR" => 26, "AE" => 23, "GB" => 22, "VG" => 24
|
||||
)
|
||||
function validiban(iban::AbstractString)
|
||||
country2length = Dict(
|
||||
"AL" => 28, "AD" => 24, "AT" => 20, "AZ" => 28, "BE" => 16, "BH" => 22, "BA" => 20, "BR" => 29,
|
||||
"BG" => 22, "CR" => 21, "HR" => 21, "CY" => 28, "CZ" => 24, "DK" => 18, "DO" => 28, "EE" => 20,
|
||||
"FO" => 18, "FI" => 18, "FR" => 27, "GE" => 22, "DE" => 22, "GI" => 23, "GR" => 27, "GL" => 18,
|
||||
"GT" => 28, "HU" => 28, "IS" => 26, "IE" => 22, "IL" => 23, "IT" => 27, "KZ" => 20, "KW" => 30,
|
||||
"LV" => 21, "LB" => 28, "LI" => 21, "LT" => 20, "LU" => 20, "MK" => 19, "MT" => 31, "MR" => 27,
|
||||
"MU" => 30, "MC" => 27, "MD" => 24, "ME" => 22, "NL" => 18, "NO" => 15, "PK" => 24, "PS" => 29,
|
||||
"PL" => 28, "PT" => 25, "RO" => 24, "SM" => 27, "SA" => 24, "RS" => 22, "SK" => 24, "SI" => 19,
|
||||
"ES" => 24, "SE" => 24, "CH" => 21, "TN" => 24, "TR" => 26, "AE" => 23, "GB" => 22, "VG" => 24)
|
||||
|
||||
# Ensure upper alphanumeric input.
|
||||
iban = replace(iban, " ", "")
|
||||
iban = replace(iban, "\t", "")
|
||||
iban = replace(iban, r"\s", "")
|
||||
|
||||
rst = ismatch(r"^[\dA-Z]+$", iban)
|
||||
# Validate country code against expected length.
|
||||
rst = rst && length(iban) == COUNTRY2LENGTH[iban[1:2]]
|
||||
rst = rst && length(iban) == country2length[iban[1:2]]
|
||||
# Shift and convert.
|
||||
iban = iban[5:end] * iban[1:4]
|
||||
digits = parse(BigInt, join(string(parse(Int, ch, 36)) for ch in iban))
|
||||
return rst && digits % 97 == 1
|
||||
digs = parse(BigInt, join(parse(Int, ch, 36) for ch in iban))
|
||||
return rst && digs % 97 == 1
|
||||
end
|
||||
|
||||
@show validiban("GB82 WEST 1234 5698 7654 32")
|
||||
@show validiban("GB82 TEST 1234 5698 7654 32")
|
||||
|
|
|
|||
|
|
@ -1,47 +1,45 @@
|
|||
/*REXX program validates an IBAN (International Bank Account Number). */
|
||||
@. =
|
||||
@.1 = 'GB82 WEST 1234 5698 7654 32 '
|
||||
@.2 = 'Gb82 West 1234 5698 7654 32 '
|
||||
@.3 = 'GB82 TEST 1234 5698 7654 32 '
|
||||
@.4 = 'GR16 0110 1250 0000 0001 2300 695 '
|
||||
@.5 = 'GB29 NWBK 6016 1331 9268 19 '
|
||||
@.6 = 'SA03 8000 0000 6080 1016 7519 '
|
||||
@.7 = 'CH93 0076 2011 6238 5295 7 '
|
||||
@.8 = 'IL62 0108 0000 0009 9999 999 '
|
||||
@.9 = 'IL62-0108-0000-0009-9999-999 '
|
||||
@.10 = 'US12 3456 7890 0987 6543 210 '
|
||||
@.11 = 'GR16 0110 1250 0000 0001 2300 695X '
|
||||
parse arg @.0 /*get optional first argument from C.L.*/
|
||||
do k=0+(arg()==0) while @.k\=='' /*either: 0 or 1 ──► n*/
|
||||
r = validateIBAN(@.k)
|
||||
/*REXX program validates an IBAN (International Bank Account Number). */
|
||||
@.=; @.1 = 'GB82 WEST 1234 5698 7654 32 '
|
||||
@.2 = 'Gb82 West 1234 5698 7654 32 '
|
||||
@.3 = 'GB82 TEST 1234 5698 7654 32 '
|
||||
@.4 = 'GR16 0110 1250 0000 0001 2300 695 '
|
||||
@.5 = 'GB29 NWBK 6016 1331 9268 19 '
|
||||
@.6 = 'SA03 8000 0000 6080 1016 7519 '
|
||||
@.7 = 'CH93 0076 2011 6238 5295 7 '
|
||||
@.8 = 'IL62 0108 0000 0009 9999 999 '
|
||||
@.9 = 'IL62-0108-0000-0009-9999-999 '
|
||||
@.10 = 'US12 3456 7890 0987 6543 210 '
|
||||
@.11 = 'GR16 0110 1250 0000 0001 2300 695X '
|
||||
parse arg @.0 /*get optional 1st arg from CL*/
|
||||
do k=0 + (arg()==0) while @.k\=='' /*either: 0 or 1 ──► n */
|
||||
r = val_IBAN(@.k)
|
||||
if r==0 then say ' valid IBAN:' @.k
|
||||
else say 'invalid IBAN:' @.k " " r
|
||||
if k==0 then leave /*User specified IBAN? Then we're done*/
|
||||
if k==0 then leave /*User specified IBAN? Then we're done*/
|
||||
end /*k*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────VALIDATEIBAN subroutine───────────────────*/
|
||||
validateIBAN: procedure; arg x; numeric digits 200 /*allow for big #s*/
|
||||
x=space(x,0); L=length(x) /*elide blanks; determine the length.*/
|
||||
cc = 'AD 24 AE 23 AL 28 AT 20 AZ 28 BA 20 BE 16 BG 22 BH 22 BR 29 CH 21',
|
||||
'CR 21 CY 28 CZ 24 DE 22 DK 18 DO 28 EE 20 ES 24 FI 18 FO 18 FR 27',
|
||||
'GB 22 GE 22 GI 23 GL 18 GR 27 GT 28 HR 21 HU 28 IE 22 IL 23 IS 26',
|
||||
'IT 27 KW 30 KZ 20 LB 28 LI 21 LT 20 LU 20 LV 21 MC 27 MD 24 ME 22',
|
||||
'MK 19 MR 27 MT 31 MU 30 NL 18 NO 15 PK 24 PL 28 PS 29 PT 25 RO 24',
|
||||
'RS 22 SA 24 SE 24 SI 19 SK 24 SM 27 TN 24 TR 26 VG 24' /*country list.*/
|
||||
@abc# = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' /*alphabet and decimal digits.*/
|
||||
cc_=left(x,2); kk=substr(x,3,2) /*get IBAN country code and checkDigits*/
|
||||
c#=wordpos(cc_,cc) /*find the country code index. */
|
||||
cL=word(cc,c#+1) /*get the length of the country's IBAN.*/
|
||||
e= '***error!*** invalid IBAN' /*literal used when displaying an error*/
|
||||
if c#==0 then return e 'country code:' cc_
|
||||
if \datatype(x,'A') then return e 'character:' substr(x,verify(x,@abc#),1)
|
||||
if cL\==L then return e 'length:' L ' (should be' cL")"
|
||||
y=substr(x,5)left(x,4) /*put four digs in front ───► the back.*/
|
||||
z= /* [↓] translate characters ──► digits*/
|
||||
do j=1 for L; _=substr(y,j,1)
|
||||
if datatype(_,'U') then z=z || pos(_,@abc#)+9
|
||||
else z=z || _
|
||||
end /*j*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
val_IBAN: procedure; arg x; numeric digits 200 /*allow for big numbers in the IBAN's. */
|
||||
x=space(x,0); L=length(x) /*elide blanks; determine the length. */
|
||||
cc= 'AD 24 AE 23 AL 28 AT 20 AZ 28 BA 20 BE 16 BG 22 BH 22 BR 29 CH 21 CR 21 CY 28 CZ 24',
|
||||
'DE 22 DK 18 DO 28 EE 20 ES 24 FI 18 FO 18 FR 27 GB 22 GE 22 GI 23 GL 18 GR 27 GT 28',
|
||||
'HR 21 HU 28 IE 22 IL 23 IS 26 IT 27 KW 30 KZ 20 LB 28 LI 21 LT 20 LU 20 LV 21 MC 27',
|
||||
'MD 24 ME 22 MK 19 MR 27 MT 31 MU 30 NL 18 NO 15 PK 24 PL 28 PS 29 PT 25 RO 24 RS 22',
|
||||
'SA 24 SE 24 SI 19 SK 24 SM 27 TN 24 TR 26 VG 24' /*a list of valid countries. */
|
||||
@ABC# = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' /*the Latin alphabet and decimal digits*/
|
||||
cc_=left(x, 2); kk=substr(x, 3, 2) /*get IBAN country code and checkDigits*/
|
||||
c#=wordpos(cc_, cc) /*find the country code index. */
|
||||
cL=word(cc, c# + 1) /*get the length of the country's IBAN.*/
|
||||
e= '***error*** invalid IBAN' /*literal used when displaying an error*/
|
||||
if c#==0 then return e 'country code:' cc_
|
||||
if \datatype(x, 'A') then return e 'character:' substr(x, verify(x, @ABC#), 1)
|
||||
if cL\==L then return e 'length:' L ' (should be' cL")"
|
||||
y=substr(x, 5)left(x, 4) /*put four digs in front ───► the back.*/
|
||||
z= /* [↓] translate characters ──► digits*/
|
||||
do j=1 for L; _=substr(y, j, 1)
|
||||
if datatype(_, 'U') then z=z || pos(_, @ABC#) + 9 /*if uppercase, then ··· */
|
||||
else z=z || _
|
||||
end /*j*/
|
||||
|
||||
if z//97==1 then return 0 /*check if correct remainder (modulus).*/
|
||||
return e 'check digits.'
|
||||
if z//97==1 then return 0 /*check if correct remainder (modulus).*/
|
||||
return e 'check digits.'
|
||||
|
|
|
|||
|
|
@ -1,43 +1,41 @@
|
|||
/*REXX program validates an IBAN (International Bank Account Number). */
|
||||
@. =
|
||||
@.1 = 'GB82 WEST 1234 5698 7654 32 '
|
||||
@.2 = 'Gb82 West 1234 5698 7654 32 '
|
||||
@.3 = 'GB82 TEST 1234 5698 7654 32 '
|
||||
@.4 = 'GR16 0110 1250 0000 0001 2300 695 '
|
||||
@.5 = 'GB29 NWBK 6016 1331 9268 19 '
|
||||
@.6 = 'SA03 8000 0000 6080 1016 7519 '
|
||||
@.7 = 'CH93 0076 2011 6238 5295 7 '
|
||||
@.8 = 'IL62 0108 0000 0009 9999 999 '
|
||||
@.9 = 'IL62-0108-0000-0009-9999-999 '
|
||||
@.10 = 'US12 3456 7890 0987 6543 210 '
|
||||
@.11 = 'GR16 0110 1250 0000 0001 2300 695X '
|
||||
@.12 = 'GT11 2222 3333 4444 5555 6666 7777 '
|
||||
@.13 = 'MK11 2222 3333 4444 555 '
|
||||
parse arg @.0 /*get optional first argument from C.L.*/
|
||||
do k=0+(arg()==0) while @.k\=='' /*either: 0 or 1 ──► n*/
|
||||
r = validateIBAN(@.k)
|
||||
/*REXX pgm validates an IBAN (International Bank Account Number), including date ranges.*/
|
||||
@.=; @.1 = 'GB82 WEST 1234 5698 7654 32 '
|
||||
@.2 = 'Gb82 West 1234 5698 7654 32 '
|
||||
@.3 = 'GB82 TEST 1234 5698 7654 32 '
|
||||
@.4 = 'GR16 0110 1250 0000 0001 2300 695 '
|
||||
@.5 = 'GB29 NWBK 6016 1331 9268 19 '
|
||||
@.6 = 'SA03 8000 0000 6080 1016 7519 '
|
||||
@.7 = 'CH93 0076 2011 6238 5295 7 '
|
||||
@.8 = 'IL62 0108 0000 0009 9999 999 '
|
||||
@.9 = 'IL62-0108-0000-0009-9999-999 '
|
||||
@.10 = 'US12 3456 7890 0987 6543 210 '
|
||||
@.11 = 'GR16 0110 1250 0000 0001 2300 695X '
|
||||
@.12 = 'GT11 2222 3333 4444 5555 6666 7777 '
|
||||
@.13 = 'MK11 2222 3333 4444 555 '
|
||||
parse arg @.0 /*get optional 1st arg from CL*/
|
||||
do k=0 + (arg()==0) while @.k\=='' /*either: 0 or 1 ──► n */
|
||||
r = val_IBAN(@.k)
|
||||
if r==0 then say ' valid IBAN:' @.k
|
||||
else say 'invalid IBAN:' @.k " " r
|
||||
if k==0 then leave /*User specified IBAN? Then we're done*/
|
||||
if k==0 then leave /*User specified IBAN? Then we're done*/
|
||||
end /*k*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────VALIDATEIBAN subroutine───────────────────────────────────────*/
|
||||
validateIBAN: procedure; arg x; numeric digits 200 /*allow for big #s*/
|
||||
x=space(x,0); L=length(x) /*elide blanks; determine the length.*/
|
||||
cc = 'AD 24 AE 23 AL 28 AT 20 AZ 28 BA 20 BE 16 BG 22 BH 22 BR 29 CH 21',
|
||||
'CR 21 CY 28 CZ 24 DE 22 DK 18 DO 28 EE 20 ES 24 FI 18 FO 18 FR 27',
|
||||
'GB 22 GE 22 GI 23 GL 18 GR 27 GT 28 HR 21 HU 28 IE 22 IL 23 IS 26',
|
||||
'IT 27 KW 30 KZ 20 LB 28 LI 21 LT 20 LU 20 LV 21 MC 27 MD 24 ME 22',
|
||||
'MK 19 MR 27 MT 31 MU 30 NL 18 NO 15 PK 24 PL 28 PS 29 PT 25 RO 24',
|
||||
'RS 22 SA 24 SE 24 SI 19 SK 24 SM 27 TN 24 TR 26 VG 24' /*country list.*/
|
||||
@abc# = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' /*alphabet and decimal digits.*/
|
||||
cc_=left(x,2); kk=substr(x,3,2) /*get IBAN country code and checkDigits*/
|
||||
c#=wordpos(cc_,cc) /*find the country code index. */
|
||||
cL=word(cc,c#+1) /*get the length of the country's IBAN.*/
|
||||
e= '***error!*** invalid IBAN' /*literal used when displaying an error*/
|
||||
if c#==0 then return e 'country code:' cc_
|
||||
if \datatype(x,'A') then return e 'character:' substr(x,verify(x,@abc#),1)
|
||||
if cL\==L then return e 'length:' L ' (should be' cL")"
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
val_IBAN: procedure; arg x; numeric digits 200 /*allow for big numbers in the IBAN's. */
|
||||
x=space(x,0); L=length(x) /*elide blanks; determine the length. */
|
||||
cc= 'AD 24 AE 23 AL 28 AT 20 AZ 28 BA 20 BE 16 BG 22 BH 22 BR 29 CH 21 CR 21 CY 28 CZ 24',
|
||||
'DE 22 DK 18 DO 28 EE 20 ES 24 FI 18 FO 18 FR 27 GB 22 GE 22 GI 23 GL 18 GR 27 GT 28',
|
||||
'HR 21 HU 28 IE 22 IL 23 IS 26 IT 27 KW 30 KZ 20 LB 28 LI 21 LT 20 LU 20 LV 21 MC 27',
|
||||
'MD 24 ME 22 MK 19 MR 27 MT 31 MU 30 NL 18 NO 15 PK 24 PL 28 PS 29 PT 25 RO 24 RS 22',
|
||||
'SA 24 SE 24 SI 19 SK 24 SM 27 TN 24 TR 26 VG 24' /*a list of valid countries. */
|
||||
@ABC# = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' /*the Latin alphabet and decimal digits*/
|
||||
cc_=left(x, 2); kk=substr(x, 3, 2) /*get IBAN country code and checkDigits*/
|
||||
c#=wordpos(cc_, cc) /*find the country code index. */
|
||||
cL=word(cc, c# + 1) /*get the length of the country's IBAN.*/
|
||||
e= '***error*** invalid IBAN' /*literal used when displaying an error*/
|
||||
if c#==0 then return e 'country code:' cc_
|
||||
if \datatype(x, 'A') then return e 'character:' substr(x, verify(x, @ABC#), 1)
|
||||
if cL\==L then return e 'length:' L ' (should be' cL")"
|
||||
if cc_=='BR' & date("S")<20130701 then return e "country, Brazil isn't valid until 1-July-2013."
|
||||
if cc_=='GT' & date("S")<20140701 then return e "country, Guatemala isn't valid until 1-July-2014."
|
||||
if cc_=='BA' & kk\==39 then return e "check digits for Bosnia and Herzegovina:" kk
|
||||
|
|
@ -45,12 +43,12 @@ if cc_=='MK' & kk\==07 then return e "check digits for Macedonia:"
|
|||
if cc_=='ME' & kk\==25 then return e "check digits for Montenegro:" kk
|
||||
if cc_=='PT' & kk\==50 then return e "check digits for Portugal:" kk
|
||||
if cc_=='SI' & kk\==56 then return e "check digits for Slovenia:" kk
|
||||
y=substr(x,5)left(x,4) /*put four digs in front ───► the back.*/
|
||||
z= /* [↓] translate characters ──► digits*/
|
||||
do j=1 for L; _=substr(y,j,1)
|
||||
if datatype(_,'U') then z=z || pos(_,@abc#)+9
|
||||
else z=z || _
|
||||
end /*j*/
|
||||
y=substr(x, 5)left(x, 4) /*put four digs in front ───► the back.*/
|
||||
z= /* [↓] translate characters ──► digits*/
|
||||
do j=1 for L; _=substr(y, j, 1)
|
||||
if datatype(_, 'U') then z=z || pos(_, @ABC#) + 9 /*if uppercase, then ··· */
|
||||
else z=z || _
|
||||
end /*j*/
|
||||
|
||||
if z//97==1 then return 0 /*check if correct remainder (modulus).*/
|
||||
return e 'check digits.'
|
||||
if z//97==1 then return 0 /*check if correct remainder (modulus).*/
|
||||
return e 'check digits.'
|
||||
|
|
|
|||
55
Task/IBAN/Ring/iban.ring
Normal file
55
Task/IBAN/Ring/iban.ring
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
# Project : IBAN
|
||||
# Date : 2018/01/03
|
||||
# Author : Gal Zsolt (~ CalmoSoft ~)
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
codes = list(5)
|
||||
codes[1] = "GB82 WEST 1234 5698 7654 32"
|
||||
codes[2] = "GB82 TEST 1234 5698 7654 32"
|
||||
codes[3] = "GB81 WEST 1234 5698 7654 32"
|
||||
codes[4] = "SA03 8000 0000 6080 1016 7519"
|
||||
codes[5] = "CH93 0076 2011 6238 5295 7"
|
||||
|
||||
for y = 1 to len(codes)
|
||||
see codes[y]
|
||||
flag = 1
|
||||
codes[y] = substr(codes[y], " ", "")
|
||||
checkcode(codes[y])
|
||||
check = checkiban(codes[y])
|
||||
if check = 1
|
||||
see " is valid" + nl
|
||||
else
|
||||
see " is invalid" + nl
|
||||
ok
|
||||
next
|
||||
|
||||
func checkcode(code)
|
||||
for n = 1 to 2
|
||||
if ascii(code[n]) < 65 or ascii(code[n]) > 90
|
||||
flag = 0
|
||||
ok
|
||||
next
|
||||
for m = 3 to len(code)
|
||||
if (ascii(code[m]) > 64 and ascii(code[m]) < 91) or (ascii(code[m]) > 47 and ascii(code[m]) < 58)
|
||||
else
|
||||
flag = 0
|
||||
ok
|
||||
next
|
||||
|
||||
func checkiban(code)
|
||||
code= substr(code, 5, len(code) - 4) + left(code, 4)
|
||||
for x = 1 to len(code)
|
||||
if ascii(code[x]) > 64 and ascii(code[x]) < 91
|
||||
code = left(code, x-1) + string(ascii(code[x]) - 55) + right(code, len(code) - x)
|
||||
ok
|
||||
next
|
||||
modold = left(code,9) % 97
|
||||
for p = 1 to floor((len(code)-9)/7)
|
||||
modnew = string(modold) + substr(code, 10 + (p-1) * 7, 7)
|
||||
modnew = number(modnew) % 97
|
||||
modold = modnew
|
||||
next
|
||||
modrest = right(code, len(code) - ((p-1)*7 + 9))
|
||||
modnew = string(modold) + modrest
|
||||
modnew = number(modnew) % 97
|
||||
return modnew
|
||||
Loading…
Add table
Add a link
Reference in a new issue