using System.Collections;
public static void Main()
Console.WriteLine(CURPRFC.CalcularRFC("JOSE ANDRE","SALAZAR","FIGUEROA", "24/02/1996"));
static public string CalcularRFC(string nombre, string apellidoPaterno, string apellidoMaterno, string fecha)
nombre = nombre.ToUpper();
apellidoPaterno = apellidoPaterno.ToUpper();
apellidoMaterno = apellidoMaterno.ToUpper();
string rfc = String.Empty;
apellidoPaterno = apellidoPaterno.Trim();
apellidoMaterno = apellidoMaterno.Trim();
apellidoPaterno = QuitarArticulos(apellidoPaterno);
apellidoMaterno = QuitarArticulos(apellidoMaterno);
rfc = apellidoPaterno.Substring(0, 1);
foreach (char c in apellidoPaterno)
rfc += apellidoMaterno.Substring(0, 1);
rfc += nombre.Substring(0, 1);
rfc += fecha.Substring(6, 2) +
CalcularHomoclave(apellidoPaterno + " " + apellidoMaterno + " " + nombre, fecha, ref rfc);
static private void CalcularHomoclave(string nombreCompleto, string fecha, ref string rfc)
System.Text.StringBuilder nombreEnNumero = new System.Text.StringBuilder();
#region Tablas para calcular la homoclave
Hashtable tablaRFC1 = new Hashtable();
Hashtable tablaRFC2 = new Hashtable();
Hashtable tablaRFC3 = new Hashtable();
nombreEnNumero.Append("0");
foreach (char c in nombreCompleto)
if (tablaRFC1.ContainsKey(c.ToString()))
nombreEnNumero.Append(tablaRFC1[c.ToString()].ToString());
nombreEnNumero.Append("00");
for (int i = 0; i < nombreEnNumero.Length - 1; i++)
valorSuma += ((Convert.ToInt32(nombreEnNumero[i].ToString()) * 10) + Convert.ToInt32(nombreEnNumero[i + 1].ToString())) * Convert.ToInt32(nombreEnNumero[i + 1].ToString());
div = Convert.ToInt32(valorSuma) % 1000;
string hc = String.Empty;
if (tablaRFC2.ContainsKey((indice == 0) ? div : mod))
hc += tablaRFC2[(indice == 0) ? div : mod];
int rfcAnumeroSuma = 0, sumaParcial = 0;
for (int i = 0; i < rfc.Length; i++)
if (tablaRFC3.ContainsKey(rfc[i].ToString()))
rfcAnumeroSuma = Convert.ToInt32(tablaRFC3[rfc[i].ToString()]);
sumaParcial += (rfcAnumeroSuma * (14 - (i + 1)));
int moduloVerificador = sumaParcial % 11;
if (moduloVerificador == 0)
sumaParcial = 11 - moduloVerificador;
rfc += sumaParcial.ToString();
static private bool EsVocal(char letra)
if (letra == 'A' || letra == 'E' || letra == 'I' || letra == 'O' || letra == 'U' ||
letra == 'a' || letra == 'e' || letra == 'i' || letra == 'o' || letra == 'u')
static private string QuitarArticulos(string palabra)
return palabra.Replace("DEL ", String.Empty).Replace("LAS ", String.Empty).Replace("DE ", String.Empty).Replace("LA ", String.Empty).Replace("Y ", String.Empty).Replace("A ", String.Empty);