Created
August 14, 2015 23:24
-
-
Save juanplopes/074963f8837dae0f6286 to your computer and use it in GitHub Desktop.
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 next_digit(value, base): | |
return value + str(sum(int(a)*b for a,b in zip(value, base))%11%10) | |
def make_valid(value, ap2, base): | |
return next_digit(next_digit(value, base), ap2+base) | |
def is_valid_cpf(cpf): | |
return make_valid(cpf[:9], [0], [1,2,3,4,5,6,7,8,9]) == cpf | |
def is_valid_cnpj(cnpj): | |
return make_valid(cnpj[:12], [5], [6,7,8,9,2,3,4,5,6,7,8,9]) == cnpj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment