3

I have barcode image with type "pdf417",it content a arabic text , When read it using barcode it through a text like this "ÃÍãÏ#" how can I convert this text to its original text (arabic)

Ayman
  • 117
  • 11

2 Answers2

6

If your method gives you a byte[] use:

var str = Encoding.UTF8.GetString(yourBytes);

or, perhaps

var str = Encoding.GetEncoding(1256) // 1256 is the Windows Arabic codepage
                  .GetString(yourBytes);

If your method gives you a string do this:

// iso-8859-1 is a codepage that can be used to convert back some 
// malformed unicode strings
var str = Encoding.GetEncoding(1256)
                  .GetString(Encoding.GetEncoding("iso-8859-1")
                                     .GetBytes(yourString));

The text you had in your question in the beginning was converted with this to:

أحمد#المنير#محمد#فاطمه #حرستا 27-12-1949#

Note that only the UTF8 format will make the barcode "universal" (because UTF8 can represent all the Unicode characters). The 1256 codepage will make your barcode "regional" (you have to know where your barcode was written to imagine it could be encoded with the 1256 Windows Arabic codepage)

xanatos
  • 109,618
  • 12
  • 197
  • 280
  • The indentation (putting `GetBytes` directly below `GetString`) is misleading and initially made me think your answer was wrong. It might be better to change that to make sure others don't make the same mistake. –  Aug 11 '13 at 10:06
  • @hvd Corrected... The code was on a single line in Visual Studio... So I tried reformatting it a little, but the results weren't "optimal" :-) – xanatos Aug 11 '13 at 10:08
  • how to know what is the original language of a given string – Ayman Aug 11 '13 at 20:50
  • @ayman If the string is encoded in UTF8 you don't need. Otherwise you can't. – xanatos Aug 11 '13 at 20:58
  • Thanks, My barcode return a string and not all the string converted to clear text by this way I wander if the string is holding other encrypted information Is there a way to know if the string is encrypted ? – Ayman Aug 11 '13 at 21:03
  • @ayman No. You could try to use IlSpy to look at the code of the method. – xanatos Aug 11 '13 at 21:04
  • thank u a lot, Last thing,I used a website to read my image (barcode) and the return string was what I post here but when I read the same image using my barcode reader, it give another string which is not readable be this method what can I do ? – Ayman Aug 11 '13 at 21:21
  • @ayman Write the string and write the result of `string str = Encoding.Default.BodyName`; – xanatos Aug 12 '13 at 06:12
  • the string is "?وعغ#???و?و#???ط#???عف ?µ??ف#?ع?? 1-1-1984#01010091557#" the result is "windows-1256" – Ayman Aug 12 '13 at 06:21
  • @ayman Sadly the string is already corrupted at that point. You see the `?`? They are characters that are placed when the correct character can't be found. – xanatos Aug 12 '13 at 06:26
  • @ayman Does your library has a GetBinary/GetData instead of a GetText? – xanatos Aug 12 '13 at 06:34
  • I return the barcode to its default setting the new string is ╟وعغ#╙╤╟و╠و#┌╟╧ط#▌╟╪عف ╘µ╤╚ف#╧ع╘▐ 1-1-1984#01010091557# Do you the barcode return only string – Ayman Aug 12 '13 at 06:51
  • The last string was encoded in DOS-720 (an old arabic codepage for DOS). Try: `string str2 = Encoding.GetEncoding(1256).GetString(Encoding.GetEncoding("DOS-720").GetBytes(str));` – xanatos Aug 13 '13 at 04:53
  • thank you it work fine with first part of the string, the second part still not readable the hole string in next comment – Ayman Aug 13 '13 at 06:57
  • ╟وعغ#╙╤╟و╠و#┌╟╧ط#▌╟╪عف ╘µ╤╚ف#╧ع╘▐ 1-1-1984#01010091557#L╥═"╠├├╨,╩0╤├├├├├├ ╚├╬├╘ Z├ '>|lz╘EyNdv|S$$FK:'lUl%s}>╙V:─%PaJ9U1b@╓╨m!>h╬┌buTiKrAO╪╓fSH-╥╨)+"R.┬?╙>HnG7Jiy/s3qar╞~LJ?(,H>╨~[1$*._zT^╪.DA@=t+^╞o▐LJ1\\wKjy┴Q┌!▀_J\\P|n(a`-▐x▀8*cط4.I▀P▐D6╦#▀._zwf6v▀▀bXه;VuUR╚*P7 ╨Xr─╬/s1UsL/.#$=`m=U▌╙~A=غ╓و-╠Dع|iG,v┌4:┬Zµ╩.367tqوc[Rr▀D}┴[ه1JX-2(5"4h;8YaW-9 8i.[Lj:$c%0&L!f%─╪r5m!╤┘Ahµ)^4&┴mp&brq$-&/┘a;}┴╓rvO├-DوvfX\\Wd8*y+┌Qy╩S:-h1[z-7)0$G`}i;M▐ه├.Ty╪ ?}[~╦غn[8+`~═9?>=;25;?7928>;:67<50===09>?7;48 – Ayman Aug 13 '13 at 07:00
  • Sadly I can't help you more... arab is not my language :-) It's better you ask to the creator of you barcode reader/barcode library – xanatos Aug 13 '13 at 07:03
  • thank you anyway you help me to pass a big part of me work, If it is possible to help me to know how do you discover that this encoding was in DOS-720 – Ayman Aug 13 '13 at 07:15
  • @ayman Look at http://pastebin.com/KkjaLJv1 I have commented it. I've noticed that the `ASMO-708` codepage gave results similar to the `DOS-720`. And they are both arabic codepages. – xanatos Aug 13 '13 at 07:28
  • I believe the second part of the string was an image then it converted to string, Is there a way to know what is the method used to convert it The second part of the string in next comment – Ayman Aug 13 '13 at 08:39
  • var strImage = "L╥═\"╠├├╨,╩0╤├├├├├├ ╚├╬├╘ Z├ '>|lz╘EyNdv|S$$FK:'lUl%s}>╙V:─%PaJ9U1b@╓╨m!>h╬┌buTiKrAO╪╓fSH-╥╨)+\"R.┬?╙>HnG7Jiy/s3qar╞~LJ?(,H>╨~[1$*._zT^╪.DA@=t+^╞o▐LJ1\\\\wKjy┴Q┌!▀_J\\\\P|n(a`-▐x▀8*cط4.I▀P▐D6╦#▀._zwf6v▀▀bXه;VuUR╚*P7 ╨Xr─╬/s1UsL/.#$=`m=U▌╙~A=غ╓و-╠Dع|iG,v┌4:┬Zµ╩.367tqوc[Rr▀D}┴[ه1JX-2(5\"4h;8YaW-9 8i.[Lj:$c%0&L!f%─╪r5m!╤┘Ahµ)^4&┴mp&brq$-&/┘a;}┴╓rvO├-DوvfX\\\\Wd8*y+┌Qy╩S:-h1[z-7)0$G`}i;M▐ه├.Ty╪ ?}[~╦غn[8+`~═9?>=;25;?7928>;:67<50===09>?7;48\r"; – Ayman Aug 13 '13 at 08:39
  • or this string maybe an encrypted data, Is there a way to know if it is?? And to know the type of encryption?? Note: I read many image barcode and all of it gave a sting with the same starting charts – Ayman Aug 13 '13 at 19:18
  • @ayman No. Encryption is opaque... And even then, without the password it would be impossible to decrypt it, especially if you don't even know what it's written. – xanatos Aug 13 '13 at 19:20
  • So, the string is not represent of image. And There is know no way to know what it is? – Ayman Aug 13 '13 at 19:31
  • Any hint to know what is it plase?? – Ayman Aug 13 '13 at 19:43
  • @ayman As I have told you, ask to the persons who created the library/the barcode scanner. AND you need to know what there is in the barcode. You need a correctly decodified barcode. AND if your barcode library is made in .NET, try looking at it with IlSpy. – xanatos Aug 13 '13 at 19:45
  • this string was generated by barcode scanner and I can not reach the creator of it. And I don't know what is in the barcode but I notice that all string start with the same 29 characters which are L╥═\"╠├├╨,╩0╤├├├├├├ ╚├╬├╘ Z├ ' And my barcode does not have a library, it work directly after connect it to the USB – Ayman Aug 13 '13 at 21:13
  • Which method? If you main how to convert the string to image I try to use the following method `code var bytes = Convert.FromBase64String(strImage); Image image; using (var ms = new MemoryStream(bytes)) { image = Image.FromStream(ms); } return new Bitmap(image);` But it did not work I wonder if there are others way? – Ayman Aug 14 '13 at 07:22
  • Hi, I am curious to know if you were able to successfully decode the rest of barcode data? – HalaKuwatly Feb 02 '16 at 09:03
0

I think the second part is encrypted data cause the first couple data covers all the information of the first page of the Syrian ID

Salem Domani
  • 23
  • 2
  • 7