Created
January 24, 2014 22:19
-
-
Save juanrossi/8607954 to your computer and use it in GitHub Desktop.
Función para validar un CBU
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
def validate_cbu(cbu): | |
""" | |
Validation function for the CBU (Clave Bancaria Unica) | |
Arguments: | |
cbu -- String or int of 22 characters | |
""" | |
cbu = str(cbu) | |
if len(cbu) == 22: | |
sum1 = sum2 = 0 | |
# Multipliers used to verify the CBU | |
multiplier = '7139713' | |
multiplier_2 = '3971397139713' | |
# We need to sum and multiply with the multiplier the first 7 characters | |
for i, num in enumerate(cbu[:7]): | |
sum1 += int(num) * int(multiplier[i]) | |
# We need to sum and multiply with the multiplier from character 8 to 21 | |
for i, num in enumerate(cbu[8:21]): | |
sum2 += int(num) * int(multiplier_2[i]) | |
# If 10 minus the last character of sum1 is different from CBU char 8 | |
# or if 10 minus the last character of sum2 is different from last CBU char | |
# we return False | |
if 10-int(str(sum1)[-1]) != int(cbu[7]) or 10-int(str(sum2)[-1]) != int(cbu[21]): | |
return False | |
return True | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment