EN:
Iranian National Code Validation Algorithm
Here we have a detailed algorithm for validating the national code and implemented it in Python
- The national code can be 8 digits or 9 or 10 digits
- If the length of the national code is 8, we add 2 zeros to the beginning
- If the length is 9, we add a zero to the beginning
- If all the indexes of the national code are multiplied by their place value, then added together and then divided by the remainder, they must be equal to the last digit of the national code.
- Or we subtract the number 11 in response to the above statement and compare it with the last index of the national code string. If it is correct, then the national code is also correct.
I may not have been able to explain exactly what I meant, but in the code you can see everything clearly.
FA:
الگوریتم اعتبارسنجی کد ملی ایران
در اینجا ما یک الگوریتم دقیق برای اعتبار سنجی کد ملی و پیاده سازی آن در پایتون داریم
- کد ملی می تواند 8 رقمی یا 9 یا 10 رقمی باشد
- اگر طول کد ملی 8 باشد، 2 صفر به ابتدا اضافه می کنیم
- اگر طول 9 باشد به ابتدا یک صفر اضافه می کنیم
- اگر تمامی اندیس های کد ملی در ارزش مکانی خود ضرب شود سپس باهم جمع شوند و سپس تقسیم باقیمانده 11 شوند باید با آخرین رقم کد ملی برابر باشند
- یا عدد 11 را در جواب عبارت بالا منهی میکنیم و با آخرین اندیس از رشته کد ملی مقایسه میکنیم اگر درست بود ، آنگاه کد ملی نیز صحیح است
** شاید نتوانسته باشم دقیق توضیح دهم و منظور را برسانم ، اما در کد میتوانید همه چیز را به وضوح ببینید **
our tg channel: https://t.me/AppDuny
my pv in tg: https://t.me/DeAref