Posts

Showing posts from December, 2015

Brazilian "SSN" (CPF) and "EIN" (CNPJ) generator in Ruby

In this post I used two official documents of Brazil's government called CPF which is the equivalent of the Social Security Number in the USA (SSN) and another one called CNPJ that would be the Employer Identification Number in the USA (EIN). I always had a certain curiosity about how numbers of official documents (social security number, credit cards, etc) are generated. Certainly they're not just randomly chosen numbers and must follow a determined logic during its generation, otherwise they wouldn't be valid numbers. It happens that for every number that is used there is a calculation behind it which the result will determine the document validity. There are several websites that offers this kind of service in a easy way, not just for one document. Here I'll show you the algorithm of CPF/CNPJ generation and its implementations which are very similar. Both were wrote in Ruby. Well, I coded two very simple scripts following just what came in my mind at the moment. T...