Last active
August 22, 2024 17:55
-
-
Save luzemma/9b0e0fcf1916ac7018458f392e1385a4 to your computer and use it in GitHub Desktop.
Calcula el digito verificador (homoclave) de los 10 prímeros dígitos del RFC
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
void main() { | |
final taxId = ''; // Escribe los 10 primeros caracteres del RFC | |
final lastDigit = calculateVerifierDigit(taxId); | |
print('El último dígito debe ser $lastDigit'); | |
} | |
String calculateVerifierDigit(String taxId) { | |
const dictionary = '0123456789ABCDEFGHIJKLMN&OPQRSTUVWXYZ Ñ'; | |
final index = taxId.length + 1; | |
var sum = 0; | |
for (var i = 0; i < taxId.length; i++) { | |
sum += dictionary.indexOf(taxId[i]) * (index - i); | |
} | |
final intVerifierDigit = (11000 - sum) % 11; | |
return intVerifierDigit == 10 ? 'A' : intVerifierDigit.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment