Python My Number verification module released

It is a module that verifies My Number with pip installable Python. We are doing a cross check with the ruby version and 10,000 cases. The article Calculate the check digit of My Number was wonderful, so I was able to make a Python version by referring to it.

install

install


pip install mynumber

https://pypi.python.org/pypi/mynumber

sample code

install


# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
from mynumber import MyNumber

#My number verification
my_number = 123456789018
print MyNumber.validate(my_number)

#More my number verification
for my_number in MyNumber.gets(1000):
    assert MyNumber.validate(my_number)

#My number verification by iterator:There is duplication
for my_number in MyNumber():
    assert MyNumber.validate(my_number)

Decree on which

○ Ministry of Internal Affairs and Communications Ordinance No. 85

Article 5 The formula specified by the Ordinance of the Ministry of Internal Affairs and Communications in Article 8 of the Ordinance shall be the formula listed below.

Formula

11 - \Bigl( \displaystyle\sum_{n=1}^{11} P_n \times Q_n \Bigr) \% 11 However, if $ \ Bigl (\ displaystyle \ sum_ {n = 1} ^ {11} P_n \ times Q_n \ Bigr) % 11 ≤ 1 $, then $ 0 $

Formula sign

$ Pn $: The number of the $ n $ digit when the least significant digit of the 11-digit number other than the inspection digit that constitutes the personal number is the $ 1 $ digit $ Qn $: $ n + 1 $ when $ 1 ≤ n ≤ 6 $, $ n-5 $ when $ 7 ≤ n ≤ 11 $

Articles of Original and Calculate Check Digit of My Number I quoted the formula of.

Introduction of other language version

-Ruby --Calculate my number check digit -Calculate the check digit of My Number in C ++

Validated with Ruby version

I cross-checked with the code of the article Calculate the check digit of my number.

ruby_mynumber_validate.rb


#!/usr/bin/env ruby
def validate_my_number(mynumber)
  #Integer sequence
  digits = mynumber.to_s.chars.map(&:to_i)
  #Only 12 digits allowed
  return false unless digits.length == 12
  #Separate check digit
  check_digit = digits.pop

  #Check the remaining numbers from the smallest
  digits.reverse!

  #Calculate the remainder of dividing the sum of the sequences by 11.
  remainder =  (1..11).inject(0) {|sum, i|
    p = digits[i-1]
    q = (i <= 6) ? i+1 : i-5
    sum + p*q
  } % 11

  case remainder
    when 0,1
      check_digit === 0
    else
      check_digit === (11 - remainder)
  end
end

my_numbers = [
    xxxxx,
    xxxxx,
    xxxxx,
    xxxxx,
]

my_numbers.each do |num|
  r = validate_my_number(num)
  if r == false then
    p num
  end
end




Recommended Posts

Python My Number verification module released
My Numpy (Python)
My pyproj (python)
My pandas (python)
My str (python)
My pyautogui (python)
My PySide (Python)
My urllib (python)
My pyperclip (python)
[My memo] python
Python collections module
My ConfigParser (Python)
My Webdriver (Python)
My arcpy (python)
My win32gui (Python)
My os (python)
My python environment memo
Python module (Python learning memo ④)
Create a Python module
python original module import
My Beautiful Soup (Python)
[My memo] python -v / python -V
Python Tips (my memo)
Prime number 2 in Python
My python data analysis container
How Python module import works
[Python] ModuleNotFoundError: No module named'urlparse'
About the Python module venv
Numpy random module random number generator
Automatic update of Python module
ABC161D Lunlun Number with python3
My python data analytics environment
Ruby, Python Module Installation Guide
Python debug and test module
[python] Random number generation memorandum