Created
August 18, 2011 19:19
-
-
Save revolunet/1154907 to your computer and use it in GitHub Desktop.
Valider un RIB en python
This file contains hidden or 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
| def validRIB(banque, guichet, compte, cle): | |
| # http://fr.wikipedia.org/wiki/Clé_RIB#V.C3.A9rifier_un_RIB_avec_une_formule_Excel | |
| import string | |
| lettres = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
| chiffres = "12345678912345678923456789" | |
| # subst letters if needed | |
| for char in compte: | |
| if char in string.letters: | |
| achar = char.upper() | |
| achiffre = chiffres[lettres.find(achar)] | |
| compte = compte.replace(char, achiffre) | |
| reste = ( 89*int(banque) + 15*int(guichet) + 3*int(compte) ) % 97 | |
| ccle = 97 - reste | |
| return (ccle == int(cle)) |
is there an example how to run this function
where do i get
bank ...... key
what if i have just an IBAN
https://www.iban.fr/exemple.html
IBAN = "FR7630001007941234567890185" # taken for website above
CP = IBAN[0:2]
CC = IBAN[2:4]
BANQUE = IBAN[4:9]
GUICHET = IBAN[9:14]
COMPTE = IBAN[14:25]
CLE = IBAN[25:27]
# print(CP, CC, BANQUE, GUICHET, COMPTE, CLE)
validRIB(BANQUE, GUICHET, COMPTE, CLE)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

here is a little update using
string.ascii_letters