Created
October 31, 2021 12:07
-
-
Save zeroows/2dc0f46a964df49d0900e4498ce4f4b6 to your computer and use it in GitHub Desktop.
IBAN Generator from Account number for Saudi Arabia Banks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
CHARS = {c: str(ord(c) % 55) for c in string.ascii_uppercase} | |
BANK = { | |
'Al Bilad Bank': '15', | |
'Al Inma Bank': '05', | |
'Al Jazira Bank': '60', | |
'Al Rajhi Bank': '80', | |
'Alawwal Bank': '50', | |
'Arab National Bank': '30', | |
'Bank Muscat': '76', | |
'BNP Parisbas': '85', | |
'Deutsche Bank': '81', | |
'Emirates Bank International': '95', | |
'Gulf International Bank': '90', | |
'JPMorgan Chase Bank': '86', | |
'National Bank of Bahrain': '71', | |
'National Bank of Kuwait': '75', | |
'National Bank of Pakistan': '82', | |
'National Commercial Bank': '10', | |
'SABB': '45', | |
'Samba': '40', | |
'Saudi Fransi Bank': '55', | |
'Saudi Investment Bank': '65', | |
'State Bank of India': '83', | |
'Riyad Bank': '20', | |
} | |
def make_iban(bank, account, country='SA'): | |
assert(len(bank) == 2) | |
assert(len(account) <= 18) | |
account = account.zfill(18) | |
iban = bank + account | |
check = iban + country + '00' | |
check = int(''.join(CHARS.get(c, c) for c in check)) | |
check = 98 - (check % 97) | |
check = str(check).zfill(2) | |
return country + check + iban | |
def check_iban(iban): | |
if len(iban) != 24: | |
return False | |
check = iban[4:] + iban[:4] | |
check = int(''.join(CHARS.get(c, c) for c in check)) | |
return check % 97 == 1 | |
if __name__ == '__main__': | |
iban = make_iban(BANK['Riyad Bank'], '213124234234') | |
check = check_iban(iban) | |
print(iban," IBAN is valid: ",check) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment