Skip to main content

Validate And Generate Iran National ID

Project description


# pyINID
Iran National ID Tools

- Check validity of Iran National ID as the following algorithm:

![ds = \sum_{n=1}^{10} \frac{1}{10^n}(x \bmod 10^{n + 1} - x \bmod 10^n) \times (n+1) \\
m = ds \bmod 11 \\
checksum = \left(m \lt 2 \rightarrow m \right)\wedge\left(m \ge 2 \rightarrow 11 - m\right)](http://mathurl.com/render.cgi?%5Ctextmode%20ds%20%3D%20%5Csum_%7Bn%3D1%7D%5E%7B10%7D%20%5Cfrac%7B1%7D%7B%7B10%7D%5En%7D%28x%20%5Cbmod%20%7B10%7D%5E%7Bn%20+%201%7D%20-%20x%20%5Cbmod%20%7B10%7D%5En%29%20%5Ctimes%20%28n%20+%201%29%20%20%5C%5C%0A%5C%5C%0Am%20%3D%20ds%20%5Cbmod%2011%20%20%5C%5C%0A%5C%5C%0Achecksum%20%3D%20%5Cleft%28m%20%5Clt%202%20%5Crightarrow%20m%20%5Cright%29%5Cwedge%5Cleft%28m%20%5Cge%202%20%5Crightarrow%2011%20-%20m%5Cright%29%5Cnocache)

(`checksum` will be the rightmost digit of National ID code )

- Generate a random valid Iran National ID prefixed with desired numbers

## Installation

[sudo -H ]pip(3) install pyinid

## Using as a library
### Check validity
```python
import inid

if inid.check_id('0123456789'):
print("Correct")
else:
print("Incorrect")
```
### Generate
```python
import inid
print(inid.generate_id()) # Completely Random
print(inid.generate_id('12345')) # With Desired Prefix
print(inid.generate_id('123456789')) # Only generate checksum
```
## Using as a cli tool

$ python3 -m inid


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyinid-0.3.tar.gz (2.3 kB view details)

Uploaded Source

File details

Details for the file pyinid-0.3.tar.gz.

File metadata

  • Download URL: pyinid-0.3.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/2.7

File hashes

Hashes for pyinid-0.3.tar.gz
Algorithm Hash digest
SHA256 04d76196993a73571f3f83856f4be1d8e9aab50a3d8da3329c8d3b5deb3b7e44
MD5 35a4848cd6dfd16bce98c68e54df3300
BLAKE2b-256 3f449db9a9c3bfec22aed2b515f8f4bd5b989175db33a02e635c9332fc3d5e83

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page