Skip to content

Instantly share code, notes, and snippets.

@revolunet
Created August 18, 2011 19:19
Show Gist options
  • Select an option

  • Save revolunet/1154907 to your computer and use it in GitHub Desktop.

Select an option

Save revolunet/1154907 to your computer and use it in GitHub Desktop.
Valider un RIB en python
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))
@Its-Just-Nans
Copy link

here is a little update using string.ascii_letters

# all params as string
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.ascii_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
    print((ccle == int(cle)))

@mrhili
Copy link

mrhili commented Aug 23, 2023

is there an example how to run this function
where do i get
bank ...... key
what if i have just an IBAN

@Its-Just-Nans
Copy link

image

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