Skip to content

Instantly share code, notes, and snippets.

@fbwright
Last active August 29, 2015 14:22
Show Gist options
  • Save fbwright/7d3654faea033270e899 to your computer and use it in GitHub Desktop.
Save fbwright/7d3654faea033270e899 to your computer and use it in GitHub Desktop.
Calcolo del codice fiscale
N,L="0123456789","ABCDEFGHIJKLMNOPQRSTUVWXYZ";A=N+L;D="! %')-/135! %')-/135\"$24+#&(,.0*6987";P=" !\"#$%&'() !\"#$%&'()*+,-./0123456789";p=lambda l,i:l.split("\t")[i].strip()
def G(s,f=0):
C,V="",""
for c in s.upper():
if c in "AEIOU":V+=c
else:C+=c
C=[C,C[0]+C[2:]][f and len(C)>3];return(C+V+"X"*3)[:3]
C=lambda n,c,s,g,m,a,C:(lambda c:c+L[sum(ord(([D,P][i%2])[A.index(x)])-32 for i,x in enumerate(c))%26])(G(c)+G(n,1)+str(a)[-2:]+"ABCDEHLMPRST"[m-1]+"%02d"%(g+40*s)+{p(l,1):p(l,0)for l in open("belfiore.txt").read().splitlines()}[C.upper()])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment