Skip to content

Instantly share code, notes, and snippets.

@alexeiramone
Last active August 29, 2015 14:01
Show Gist options
  • Save alexeiramone/bfbaf74346c30cc3ba34 to your computer and use it in GitHub Desktop.
Save alexeiramone/bfbaf74346c30cc3ba34 to your computer and use it in GitHub Desktop.
def cpf_valid(cpf, d1=0, d2=0, i=0):
try:
while i < 10:
d1, d2, i = (d1 + (int(cpf[i]) * (11-i-1))) % 11 if i < 9 else d1, (d2 + (int(cpf[i]) * (11-i))) % 11, i + 1
return (int(cpf[9]) == (11 - d1 if d1 > 1 else 0)) and (int(cpf[10]) == (11 - d2 if d2 > 1 else 0))
except:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment