Skip to content Skip to sidebar Skip to footer

What process/algorithm is used to calculate the check digit and what mod is used for ISBN?

  • Download sample - 31.7 KB

Introduction

The purpose of this article is to acquire nearly some of the most common identification numbers and check digit algorithms involved in the verification of these identification numbers. Nosotros volition not exist covering all of the identification numbers as in that location are a lot many out in that location to be covered in this commodity. Still, in one case you go through this article you will sympathise the most common algorithms involved.

Many products that we employ have an identification number that may or may not have a bar-code. Some examples are books, electronics, grocery items, credit cards, money orders, driver'south license, etc. The identification number helps encode the data about the production. These numbers are usually separated by a space or a hyphen and each part holds specific information near the production. We will embrace the nearly mutual ones in this article but earlier that nosotros should take some basic understanding of how the identification number is verified.

Check Digits

A check digit is added to the identification number (ordinarily the final digit). This digit is used to verify the identification number for its legitimacy. Check digit is added to the number to detect any errors fabricated while typing the number into the system. The check digit is calculated with an algorithm. Some nigh mutual algorithms are mod9, mod10, and mod11. We volition farther discover that the mod10 algorithm is the most common and is used in most of the identification numbers.

Now will hash out some of the common identification numbers used.

IMEI (International Mobile Equipment Identity)

The IMEI number is a unique 15 digit number used to place mobile phones as well as some of the satellite phones. The IMEI number can exist found on the box in which the phone was packed, inside the phone in the battery compartment, and you tin even find the IMEI by typing *#06# or *#0000# on some phones. The IMEI number is used past the GSM network to identify a valid device.

Structure of IMEI

The IMEI number is a 15 digit number (14 digit plus the concluding digit which is the check digit). The IMEI contains the origin, model, and the serial number of the device plus the cheque digit for validation. The showtime 8 digits, known as the TAC (Type Allocation Code), concur the information about the origin and model. The next six digits are the serial number divers past the manufacturer. The last digit is the check digit. Figure i.1 illustrates the structure of an IMEI number.

imei structure

Calculation of the Bank check Digit

The check digit is calculated using the LUHN's algorithm (mod10 algorithm). The LUHN'south algorithm was created by Hans Peter Luhn, a scientist at IBM. Here are the steps to calculate the bank check digit using mod10 algorithm:

  1. Starting from the right, double every second digit.
  2. Add the digits together if the doubling gives yous a two digit number.
  3. Now add together the doubled digits with the digits that were not doubled.
  4. Divide the sum by ten and bank check if the remainder is zero. If the residuum is zero then that is the bank check digit. If the number is not null, then subtract the remainder from 10. The resulting number will be the check digit.

Here is an illustration:

C implementation - validate an IMEI number:

          int          imei(char          a[]) {          int          i,len,mul,sum;          int          chksum;          int          m10;     len = strlen(a);          if(len!=15)          return          -1;         chksum = char2int(a[len-1]);       mul =          2; sum=0;          for(i=len-2;i>=0;i--)    {          if( (char2int(a[i])*mul)          >=          10          )      sum +=  ((char2int(a[i])*mul ) /          x) +((char2int(a[i])*mul ) %          10          );          else          sum += char2int(a[i])*mul;          if(mul==2) mul=1;          else          mul=two;    }      m10 = sum%ten;          if(m10) m10 =          10          - m10;          if(m10 == chksum)          render          1;          else          return          0; }

Summary

  • IMEI is a unique 15 digit number assigned to mobile phones.
  • It is used by GSM networks to verify the legitimacy of the device.
  • First 8 digits are known as TAC (Type Allocation Lawmaking), next six digits are the serial number, and the final digit is the check digit.
  • IMEI number uses mod10 or LUHN'due south algorithm to verify the number.

Bank Carte du jour numbers

Depository financial institution card number are found on credit, debit, and other cards issued from the bank and some gift cards tin also be verified with Luhn'south algorithm. The first digit of the carte du jour number is the Major Industry Identified (MII), which tells us which category of the entity issued the bill of fare. For example, if the number begins with i or 2, it's issued by Airlines industry. If the number begins with 4, 5, or 6, information technology is issued by the financial and banking industry. The offset half dozen digits of the card number (including the MII) is known every bit the Issuer Identification number (IIN). Examples - 4 stands for Visa, 51 or 55 stand for MasterCard, and 34 or 37 for American Express. The numbers left are issued by the bank and the final digit is the check digit.

Verifying the card number using mod10 algorithm

Mod10 algorithm is used to verify bank carte du jour numbers. We have already discussed this algorithm, then nosotros will not go into the details once more.

Here is an illustration:

C implementation of mod10 (Luhn's Algorithm):

          int          ibm_mod10(char          a[]) {          int          i, len, mul, sum;          int          chksum;          int          m10;            len = strlen(a);      chksum = char2int(a[len-i]);       mul =          2; sum=0;          for(i=len-2; i>=0; i--)    {          if( (char2int(a[i])* mul)          >=          10          )      sum +=  ((char2int(a[i])* mul ) /          10) +((char2int(a[i])* mul ) %          10          );          else          sum += char2int(a[i])* mul;          if(mul==ii) mul=1;          else          mul=2;    }      m10 = sum%10;          if(m10) m10 =          ten          - m10;          if(m10 == chksum)          return          one;          else          return          0; }

Routing Numbers

Routing number is a nine digit bank code designed to facilitate the sorting, bundling, and shipment of paper checks dorsum to the drawer'south business relationship. The RTN is besides used by Federal Reserve Bank to process Fedwire fund transfers, and by the Automatic Clearing firm to procedure straight deposits and other automatic transfers.

Routing number format

Routing number appears in two formats: ) Fraction form and MICR (Magnetic ink character recognition) form. Both forms give the same information. Fraction form was used when MICR form was non invented, all the same it is still used equally a backup.

MICR form: XXXXYYYYC

Here XXXX is the Federal Reserve Routing Symbol, YYYY is ABA Institution Identifier, and C is the cheque digit.

Calculation of the Check Digit

The bank check digit tin can be calculated by using this formula:

check digit (d9) = [7x(d1 + d4 + d7) + iii(d2 + d5+ d8) + ix(d3 + d6)] mod ten

Let's calculate the check digit for this routing number: 2540 7011 half-dozen. Here, the cheque digit is half dozen. According to the formula, check digit (d9) = 7x(two+0+1) + 3x(5+vii+1) + 9x(4+0)

=> 7x3 + 3x13 + 9x4 => 21 + 39 + 36 => 96. Now, 96 modernistic 10 => vi. Hence vi is the bank check digit.

Here is an illustration:

C implementation - validate a routing number:

            int          routing(char          a[]) {          int          checksum =          0, len=0, sum=0, m10=0;          len = strlen(a);          if(len!=ix)          return          -1;               checksum = char2int(a[len-1]);          sum = (vii          * ( char2int(a[0]) + char2int(a[iii]) + char2int(a[6]) )) +            (3          * ( char2int(a[i]) + char2int(a[4]) + char2int(a[7]) )) +           (ix          * ( char2int(a[2]) + char2int(a[5]) ));          m10 = sum %          10;          if(m10 == checksum)          return          1;          else          render          0; }

USPS money club number

The United states of america Postal office uses an identification number for postal orders. It's an 11 digit number and the last number is the bank check digit every bit we have seen in other cases.

Adding of the check digit

To calculate the cheque digit, add up the first 10 digits and the sum is divided by 9. The remainder is the check digit. Let'south calculate the check digit for 84310325021. Check digit => 8+four+2+1+0+iii+2+5+0+ii+ane => 28 mod 9 => one. Hence 1 is the check digit.

C implementation - validate a USPS Money guild number:

            int          uspsmo(char          a[]) {          int          len=0, i, sum=0, checksum=0, mod9=0;          len = strlen(a);          if(len!=11)          render          -1;          checksum = char2int(a[len-1]);          for(i=0; i<len-ane; i++)       sum += char2int(a[i]);             mod9 = sum %          9;          if(mod9 == checksum )          return          1;          else          return          0; }

International Standard Book Number (ISBN)

This is a unique number created by Gordon Foster in 1961. The 10 digit format was developed by ISO (International Organization for Standardization). An ISBN is assigned to each edition of a book.

  • ten digit is assigned before Jan 1, 2007 and 13 digits is assigned after that.
  • Three parts:
    1. the group identifier
    2. the publisher code
    3. the item number (title of the book).
  • Separated past spaces or hyphen.
  • Group Identifier: i-5 digits (country, linguistic communication).
  • The Publisher code: The national ISBN agency assigns the publisher number.
  • The publisher selects the item number.

Case: 9971-v-0210-0, 0-943396-04-2, 0-85131-041-nine

Adding of the bank check digit

  • ISBN check digit (10 digits) - mod11 algorithm
  • The last digit in an ISBN is the check digit, must range from 0 to 10. The ISBN uses a weighted arrangement of checking. Each digit from left to right is assigned a weight from ten to one. Each digit is multiplied by its position weight and the resulting numbers are summed.

    Allow's calculate the check digit for 0-07-063546-3.

    (0x1) + (0x2) + (7x3) + (0x4) + (6x5) + (3x6) + (5x7) + (4x8) + (6x9) => 190 190mod11 => 3.

    Hence 3 is the check digit. Here is an illustration.

    isbn-10 digits (mod11)

    C implementation - Validate an ISBN number (10 digits):

                  int            isbn_10(char            a[]) {            int            checksum =            0;            int            i, len,pos=one,sum=0, m11;                    len = strlen(a);            if(len!=10)            render            -1;          checksum = char2int(a[len-ane]);            for( i=0,pos=i; i<len-1; i++,pos++)      sum += char2int(a[i]) * pos;          m11 = sum %            eleven;            if(m11 == checksum)            return            1;            else            return            0;           }
  • ISBN check digit (xiii digits)
  • Each digit, starting from the left to right, is multiplied by 1 or 3 alternatively. The sum of the products modulo x gives united states of america either aught or a number between ane to ix. Decrease the number from 10 and it gives us the checksum.

                978-0-07-063546-3            1x9 + 3x7 + 1x8 + 3x0 + 1x0 + 3x7 + 1x0 + 3x6 + 1x3 + 3x5 + 1x4 + 3x6 =>  ix + 21 + 8 + 21 + xviii + 3 + 15 + 4 + 18 => 117 => 117 mod 10 => 7 => 10 – seven => 3.

    Hence 3 is the check digit.

    Here is an analogy:

    isbn-13

    C implementation - validate an ISBN number (13 digits):

                  int            isbn_13(char            a[]) {            int            checksum =            0;            int            i, len,mul=ane,sum=0, m10;               len = strlen(a);            if(len!=13)            return            -ane;          checksum = char2int(a[len-1]);            for(i=0; i<len-1; i++)     {       sum += char2int(a[i]) * mul;            if(mul==three) mul=i;            else            mul =            3;     }          m10 = sum%10;            if( (x-m10) == checksum)            return            1;            else            return            0; }

ISSN (International Standard Serial Number)

An ISSN is a unique eight number used to identify a print or electronic journal publication. The code format is divided past a hyphen into a four digit number. The final number is the bank check digit equally in the other codes that we accept covered.

Adding of the check digit

Starting from the left, each digit is multiplied past its position in the number. Add those numbers and the sum is divided past 11 (mod11). If the remainder is not zilch, so the residual is subtracted from 11 and that gives us the cheque digit. And then for instance, this number – 0378-5955.

Leave out the terminal digit because we desire to verify this digit: 0x8 + 3x7 + 7x6 + 8x5 + 5x4 + 9x3 + 5x2 = >160 % 11 = 6.

Now because the remainder is a non-nada digit, we will subtract it from xi to get the check digit, and then 11 - 6 => 5. Hence the check digit is 5.

Here is an illustration:

C implementation - validate an ISSN:

            int          issn(char          a[]) {          int          len=0, m11=0, pos=8, i=0, sum=0, checksum=0;        len = strlen(a);          if(len!=8)          return          -ane;            checksum = char2int(a[len-1]);          for(i=0,pos=8; i<len-1; i++,pos--)       sum += char2int(a[i]) * pos;          m11 = sum %          11;          if(m11!=0) m11 =          xi          - m11;          if(m11 == checksum)          return          1;          else          render          0; }

UPC and EAN

The UPC (Universal Production Lawmaking) is a barcode symbol and is used to runway trade items in stores. The most mutual course of UPC is the UPC-A which consists of 12 digits which is unique for a merchandise particular. It consists of a strip of black and white spaces which can be scanned. The area that can be scanned in a UPC-A follows this pattern:

          SLLLLLLLMRRRRRRE          Hither Due south -> Outset, M -> Eye and E -> Terminate L -> Left and R -> Right make the barcode unique. The concluding digit in the barcode is the check digit.

Adding and Verification of the check digit

Verification: To verify the number, we can use this formula:

          [3.d1 + one.d2 + 3.d3 + 1.d4 + 3.d5 + 1.d6 + three.d7 + 1.d8 + 3.d9 + 1.d10 + 3.d11 + one.d12] mod10 = 0        

Here d1, d2, d3...etc. are the digits. Starting from the left, we multiply the digits with 3 and i alternatively.

Example: 036000 291452

3x0 + 1x3 + 3x6 + 1x0 + 3x0 + 1x0 + 3x2 + 1x9 + 3x1 + 1x4 + 3x5 + 1x2 => 0+three+18+0+0+0+9+3+4+xv+ii => lx => 60mod10 => 0.

Hence the number is verified:

Adding: To calculate the check digit, we use the same formula only subtract the remainder from 10 to get the check digit.

Example: 036000 29145?

3x0 + 1x3 + 3x6 + 1x0 + 3x0 + 1x0 + 3x2 + 1x9 + 3x1 + 1x4 + 3x5 + x =>  0+three+xviii+0+0+0+9+three+four+xv+10 => 58 => 58mod10 => 8 x - 8 => two

Hence 2 is the check digit.

C implementation - validate a UPC number (12 digits):

            int          upc_a(char          a[]) {          int          checksum =          0;          int          i, len,mul=3,sum=0, m10=0;          len = strlen(a);          if(len!=12)          return          -1;          for(i=0; i<len; i++)     {       sum += char2int(a[i]) * mul;          if(mul==3) mul=one;          else          mul =          3;     }          m10 = sum%10;          if(m10 ==          0)          return          1;          else          return          0; }

EAN

The EAN-13 (European Article Number) is a 13 digit barcode which is a superset of the UPC (12 digits), and is used worldwide for marking products sold at retail points of sale (POS). EAN likewise indicates the country in which the visitor who sells the product is based in.

Calculation of the check digit

Verification: To verify the number, multiply the digits with 1 or 3 with respect to the position they have in the digits, starting from the left.

Example: viii 901526 206056

1x8 + 3x9 + 1x0 + 3x1 + 1x5 + 3x2 + 1x6 + 3x2 + 1x0 + 3x6 + 1x0 + 3x5+ 1x6 => eight + 27 + three + v + half dozen + 6 + 6 + 18 + fifteen + half-dozen => 100 mod10 => 0. Hence number is verified

Adding: We use the same method as in a higher place, however nosotros will omit the concluding digit from the calculation because that is the digit we desire to detect. Here if the remainder is a non-zero number then it is subtracted from x.

Case: 8 901526 206056

1x8 + 3x9 + 1x0 + 3x1 + 1x5 + 3x2 + 1x6 + 3x2 + 1x0 + 3x6 + 1x0 + 3x5 => 8 + 27 + 3 + 5 + half-dozen + 6 + 6 + 18 + 15 => 94 mod10 => half-dozen. 10 - 4 = > 6.

Hence 6 is the check digit.

C implementation - validate an EAN (xiii digits):

            int          ean(char          a[]) {          int          len=0,i=0, sum=0, mul=one, mod10, checksum;          len = strlen(a);          if(len!=13)          render          0;               checksum = char2int(a[len-one]);          for(i=0; i<len-i; i++)       {         sum += char2int(a[i]) * mul;          if(mul==one) mul =          3;          else          mul =          1;                }      mod10 = sum %          10;       mod10 =          10          - mod10;          if(mod10 == checksum)          return          1;          else          render          0; }

  • Click here to download latest source code

If you have any suggestions, email me at shine_hack@yahoo.com.

  • http://www.techrevelation.info

wagnershadeopleil.blogspot.com

Source: https://www.codeproject.com/Articles/459507/Identification-numbers-and-check-digit-algorithms

Post a Comment for "What process/algorithm is used to calculate the check digit and what mod is used for ISBN?"