Skip to content

Instantly share code, notes, and snippets.

@luzemma
Last active August 22, 2024 17:55
Show Gist options
  • Save luzemma/9b0e0fcf1916ac7018458f392e1385a4 to your computer and use it in GitHub Desktop.
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
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