In giro per il web trovi routine, in codice sorgente, per gestire il codice fiscale.
Basta fare una ricerca.