How to read barcode on NADRA NIC?

I am writing an application that reads a barcode from a NIC released by NADRA (http://www.nadra.gov.pk/index.php?option=com_content&view=article&id=6&Itemid=9). NADRA issues CNIC to citizens of Pakistan. I want to read these barcodes that are printed on CNIC. NADRA encoded information such as: name, father's name, address, DOB, etc., but this data is stored in Urdu. I have successfully read these barcodes, but the fact is that I cannot convert my character set to Urdu. I installed Urdu fonts such as Noori Nistalique, Aswad and many others, but these characters simply show a mess of characters, not meaningful information. when I decode these barcodes in plain English, it shows the correct digital information, but does not display the information that is in Urdu.

Has anyone tried to read these barcodes and successfully decoded it? please help me or advise me what should I do ...?

here is the sample i read, it's just english:

A0U1200708091232 13501722 T31 2602 -E '/

Here is a sample that I am reading, and this is in Urdu:

آڑم 0287870180 ء 1200708091232 13501722 ٹ 31 ص 2602 -فف ف-فڈف┴ف, ف 9 ف┴ف 1 ف-فف "ففف

as you can see, the numerical information is the same, but the information encoded in urdu is mixed ...

any help ???

+4
source share
2 answers

NADRA did the trick, NADRA actually uses the last two characters with the hexadecimal value of the word, for example. if \u0622 is Alif (suppose), then NADRA uses only the last two characters to encode, 22 , so this is just a trick. I am attaching some code that converts hex to Urdu, reads the barcode data, converts it to a hexadecimal string, and then passes this string to this function, you will get all the information in Urdu, just put this string in some Urdu or in Arabic language. View (Android), Component (Java) or if you are using C # then put it in a shortcut.

 public class ConvertToUrdu { public static String convertToUrdu(String text) { StringBuilder sb = new StringBuilder(); String[] characters = text.split(","); for(String character : characters) { //if (ListDigits.Contains(ch)) //{ // continue; //} switch (character) { case "20": sb.append(" "); break; case "22": sb.append("\u0622"); break; case "27": sb.append("\u0627"); break; case "13": sb.append("\u0613"); break; case "28": sb.append("\u0628"); break; case "2B": sb.append("\u062b"); break; case "86": sb.append("\u0686"); break; case "88": sb.append("\u0688"); break; case "2F": sb.append("\u062f"); break; case "10": sb.append("\u0610"); break; case "39": sb.append("\u0639"); break; case "41": sb.append("\u0641"); break; case "3A": sb.append("\u063a"); break; case "AF": sb.append("\u06af"); break; case "2D": sb.append("\u062d"); break; case "BE": sb.append("\u06be"); break; case "CC": sb.append("\u06cc"); break; case "36": sb.append("\u0636"); break; case "2C": sb.append("\u062c"); break; case "2E": sb.append("\u062e"); break; case "43": sb.append("\u0643"); break; case "12": sb.append("\u0612"); break; case "44": sb.append("\u0644"); break; case "45": sb.append("\u0645"); break; case "BA": sb.append("\u06ba"); break; case "46": sb.append("\u0646"); break; case "29": sb.append("\u0629"); break; case "A9": sb.append("\u06a9"); break; case "C1": sb.append("\u06c1"); break; //case "45": // sb.Append("\u0645"); // break; case "7E": sb.append("\u067e"); break; case "42": sb.append("\u0642"); break; case "91": sb.append("\u0691"); break; case "31": sb.append("\u0631"); break; case "35": sb.append("\u0635"); break; case "33": sb.append("\u0633"); break; case "79": sb.append("\u0679"); break; case "2A": sb.append("\u062a"); break; case "21": sb.append("\u0621"); break; case "38": sb.append("\u0638"); break; case "37": sb.append("\u0637"); break; //case "48": // sb.Append("\\u0635\u0644\u0649\u0020\u0627\u0644\u0644\u0647\u0020\u0639\u0644\u064a\u0647\u0020\u0648\u0633\u0644\u0645"); // break; case "48": sb.append("\u0648"); break; case "98": sb.append("\u0698"); break; case "34": sb.append("\u0634"); break; case "D2": sb.append("\u06d2"); break; case "30": sb.append("\u0630"); break; case "32": sb.append("\u0632"); break; case "60": sb.append("\u0660"); break; case "61": sb.append("\u0661"); break; case "62": sb.append("\u0662"); break; case "63": sb.append("\u0663"); break; case "64": sb.append("\u0664"); break; case "65": sb.append("\u0665"); break; case "66": sb.append("\u0666"); break; case "67": sb.append("\u0667"); break; case "68": sb.append("\u0668"); break; case "69": sb.append("\u0669"); break; case "0C": sb.append(" \u200c"); break; case "D4": sb.append("\u06d4"); break; //case "0C": // sb.Append("\u060c"); // break; case "1F": sb.append("\u061f"); break; case "02": sb.append("\u0602"); break; case "1B": sb.append("\u061b"); break; case "7b": sb.append("\u007b"); break; case "7D": sb.append("\u007d"); break; //default: // sb.Append(ch); // break; } } return sb.toString(); } } 

I wrote this code for Java, you can convert it to any other language.

Hope for the best: -)

Note
For my convenience, I added a "," after two characters in the source string, for example, A0U1200708091232A0,U1,20,07,08,09,12,32 . just for debugging, so this function actually converts the second line to Urdu.

EDIT
As from the comments, here is my function that converts a string to hex, I wrote this in C #

 private string convertToHex(string text) { StringBuilder sb = new StringBuilder(); foreach (char c in text) { if (c == '\n') { sb.Append('\n'); sb.Append(','); } else { sb.Append(String.Format("{0:X}", (int)c)); sb.Append(','); //sb.Append((int)c + " "); } } return sb.ToString(); } 

In JAVA, you can convert by writing String hex = String.format("%04x", (int) c);

+6
source

In addition to @moonzai's answer above, I would like to add some details that I could still achieve (using @moonzai post off-course!).

There are still three types of CNIC:

  • Regular CNIC [Barcode Encoding: PDF417]
  • NICOP Card [Barcode Encoding: Code 128]
  • Card with DIP chip [Barcode: QR code]

The last two (2 and 3) have only an ID-card number and some additional numerical details (most likely, the number of problems in case (2) and Nadra_DB_ # in (3))
Here is the information encoded in the PDF417 (1) barcode format:

  • Check number (Brocade number), which includes the timestamp of your visit to the NADRAs office.
  • CNIC Number
  • Family Room (Handan Room)
  • Date of Birth
  • Full Name [Urdu]
  • Fathers Name [Urdu]
  • Full address with district and Teshil information [Urdu + English + English-digital]

Urdu is coded, replacing the common part of the HEX code, that is, \ u06 in the case of Java / C / C ++ / ... and "& # x6" in the case of the Web or just 0x06.
eg HEX code for "alif" is \ u0627 or ا they only added 27 and omitted & # x6.

In the case of the word "جاوید", the actual line should look like this: & # x62C & # x627 & # x648 & # x6CC & # x62F
but NADRA only added: 2C2748CC2F (ommitting all & # x6)

Below is the VBA code that helps generate a WEB string for the scanned output of a CNIC card.
I will continue to add refined code, as well as codes in other languages; especially in JS / Jquery and PHP.

  Public Function Convert2Urdu (vString As String) As String
     Dim vCharArray As Variant, vChar As String

     For i = 1 To Len (vString)
         vChar = Mid (vString, i, 1)
         vCharArray = vCharArray & GetUrduChar (Hex (AscW (vChar)))
     Next
     Convert2Urdu = vCharArray
 End function

 Private Function GetUrduChar (vHex) As String
     Select Case vHex
         'Alphabets
         Case "22", "27", "28", "7E", "2A", "79", "2B", "2C", "86", "2D", "2E", "2F", " 88 "," 30 "," 31 "," 91 "," 32 "," 98 "," 33 "," 34 "," 35 "," 36 "," 37 "," 38 "," 39 " , "3A", "41", "42", "A9", "AF", "44", "45", "46", "BA", "48", "C1", "C3", " BE "," 21 "," CC "," D2 "
             GetUrduChar = "" & vHex
         'Numerics
         Case "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F6", "F7", "F8", "F9"
             GetUrduChar = "" & vHex
         'Eraabs
         Case "10", "11", "12", "13", "14", "15", "4B", "4C", "4D", "4E", "4F", "50", " 51 "," 52 "," 53 "," 54 "," 56 "," 57 "," 58 "," 70 "
             GetUrduChar = "" & vHex
         'Punctuation
         Case "1B", "1F", "64", "6C", "D4", "6B"
             GetUrduChar = "" & vHex
         'Space
         Case "20"
             GetUrduChar = "" & "0" & ​​vHex
         Case else
            GetUrduChar = "" & Chr (vHex) & "" 'Ideally, it should be Chr (Asc (Hex)) [working on it]
     End select
 End function
+1
source

Source: https://habr.com/ru/post/1447203/


All Articles