Base32 decoding binary file to ascii

I need to convert a binary file which in encoded using base32 encoding technique and convert that into readible ASCII so that i can load the same in DB.

is there any command to do the same.

sample from the binary file lools like :

^P^A3y�^@(^A^@z^S<90>^@z^Yl^@^@^@^D^@^G(²<8f>'<94>^@^@^@^@^G^@^@^@^@^@^@^@^C^@^@^@^C^@^@^@^@^G<85><81>p^@^A^@^@^@1AAA                                    ^@GAAK                                    ^@A^@^@^@^@^@^@^G(²<8f>'<95><90>^@^

ascii file looks like (tab seperated fixed length):

016 20150722 0040 001 08000400 08001900 0000004 2015072208000000 0000007

help much appreciated.

I tried using python base64 , but in vain .

---------- Post updated at 03:44 PM ---------- Previous update was at 03:39 PM ----------

That doesn't look like a base32 coded file (which shouldn't have any control chars in it.

the o/p above is from VI editor .
when i do head -2 <binary_filename> , i get data in below format.

(�(�(042393553                               00442894484608                                                                  0              0   0     (� nOUTPEAKI_000044_A011100        I_000044_A01L    INTL BT   VEUR##,0  0    ?a4�J0   @??Q�ʧ]@??Q�ʧ]              0@?@?@?@?(CAS@?@?0           0           3y�({{~�(�'��
w1AAA                                    GAAH                                    (�((�((�)�016276111                               0031402087389                                                                   0              0   0     (� nOUTPEAKI_000031_A011100        I_000031_A01V    INTL BT   VEUR##,0  0    ?l1&�y0   @i@? ��9@i@? ��9              0@i@@i@@i@@i@(CAS@i@@i@0           0           3y�(z�<{*(�'��
x1AAA                                    GAAA                                    (�(k<(�(k<(�)*035402510                               00390245518487                                                                  0              0   0     (� nOUTPEAKI_000039_A011100        I_000039_A01A    INTL BT   VEUR##,0  0    ?_!-w1�0   @o ?(�߹8o ?(�߹8o @o @o @o (CAS@o @o 0           0           3y�({�4{�(�'��
y1AAA                                    GAAK                                    (�),4(�),4(�).051300440                               0031623134206                                                                   0              0   0     (� nOUTPEAKI_000031_M031100        I_000031_M03K    INTL BT   VEUR##,0  0    ?@N���U0   @?^�J�!@?^�J�!              0@@@@(CAS@@0           0           3y�(|0|d(�'QQ
z1AAA                                    BA0Z                                    (�)0(�)0(�*d081423716                               0022996724865                                                                   0              0   0     (� nOUTPEAKI_000229_M061300        I_000229_M06N    INTL BT   VEUR##,0  0    ?��$tT0   @c*?���f@c*?���f              0@c*@c*@c*@c*(CAS@c*@c*0           0           3y�(|
X|�((�']]                                                                                                                                     ���              0@@@@(CAS@@0           0           3y�(|1AAA                                    GAAA                                    (�)�(�)�(�*033170734                               0031297519937                                                                   0              0   0     (� nOUTPEAKI_000031_A011100        I_000031_A01A    INTL BT   VEUR##,0  0    ?l1&�y0   @O?m���d@O?m���d              0@O@O@O@O(CAS@O@O0           0           3y�({X,|�(�'
}1AAA                                    GAAN                                    (�(�,(�(�,(�*\010415006                               002302637583                                                                    0              0   0     (� nOUTPEAKI_000230_A011100        I_000230_A01N    INTL BT   VEUR##,0  0    ?��}At?@h?��}At?              0@h@h@h@h(CAS@h@h0           0           3y�(|��}!�(�'��
~1AAA                                    GAAH                                    (�*U�(�*U�(�*��011645442                               0031495591454                                                                   0              0   0     (� nOUTPEAKI_000031_A011100        I_000031_A01H    INTL BT   VEUR##,0  0    ?l1&�y0   @^?|1&�y@^?|1&�y              0@^@^@^@^(CAS@^@^0           0           3y�(}}'(�'��
1AAA                                    GAAG                                    (�*(�*(�*�052219999                               0031318527373                                                                   0              0   0     (� nOUTPEAKI_000031_A011100        I_000031_A01G    INTL BT   VEUR##,0  0    ?l1&�y0   @2?Q4�J@2?Q4�J              0@2@2@2@2(CAS@2@20           0           3y�(})�},�(�'��
1AAA                                    GAAK                                    (�*��(�*��(�*��050710720                               0031756476611                                                                   0              0   0     (� nOUTPEAKI_000031_A011100        I_000031_A01K    INTL BT   VEUR##,0  0    ?l1&�y0   @ ?>�J�!@ ?>�J�!              0@ @ @ @ (CAS@ @ 0           0           3y�(}P�}d(�';;
1AAA                                    GAAK                                    (�*��(�*��(�+d056644042                               0031492531919                                                                   0              0   0     (� nOUTPEAKI_000031_A011100        I_000031_A01K    INTL BT   VEUR##,0  0    ?l1&�y0   @X?wm���=@X?wm���=              0@X@X@X@X(CAS@X@X0           0           3y�(}8}��(�'WW
1AAA                                    GAAA                                    (�+8(�+8(�+B�035440375                               0031786810780                                                                   0              0   0     (� nOUTPEAKI_000031_A011100        I_000031_A01A    INTL BT   VEUR##,0  0    ?l1&�y0   @R?q4�J@R?q4�J              0@R@R@R@R(CAS@R@R0           0           3y�}��(�'^^
1AAA                                    GAAA                                    (�*�(�*�(�+D�036662000                               0031653549112                                                                   0              0   0     (� nOUTPEAKI_000031_M031100        I_000031_M03A    INTL BT   VEUR##,0  0    ?@N���U0   @p?�-#N��w@p?�-#N��w              0@p@p@p@p(CAS@p@p0           0           3y�(~6�~BD(�'��

1AAA                                    GAAA                                    (�+��(�+��(�+�D038865390                               0031416274732                                                                   0              0   0     (� nOUTPEAKI_000031_A011100        I_000031_A01A    INTL BT   VEUR##,0  0    ?l1&�y0   @=?[�_��@@=?[�_��@              0@=@=@=@=(CAS@=@=0           0           3y�(~�~B�(�'��

1AAA                                    GAAA                                    (�+�(�+�(�+Ĩ032255999                               00912223691100                                                                  0              0   0     (� nOUTPEAKI_000091_C031100        I_000091_C03A    INTL BT   VEUR##,0  0    ?t�j~��0   @V?T�w[@V?T�w[              0@V@V@V@V(CAS@V@V0           0

At the moment the lines you have given us are meaningless.

Please do a hexdump of part of the REAL BINARY file and the expected ASCII readout.

EG:-

hexdump -C /full/path/to/binary.file

(An example.)

AMIGA:barrywalker~/Desktop/Code/Shell> hexdump -C ~/Desktop/Code/Shell/binary2
00000000  00 00 00 0a 0a 0a 09 09  09 20 20 20 00 0a 09 5c  |.........   ...\|
00000010  20 0a 00 5c 20 09 20 20  20 0a 0a 0a              | ..\ .   ...|
0000001c

hexdump o/p is as follows

9b0  00 00 40 3d 00 00 00 00  00 00 30 20 20 20 20 20  |..@=......0     |
000039c0  20 20 20 20 20 20 00 30  20 20 20 20 20 20 20 20  |      .0        |
000039d0  20 20 20 00 00 00 10 01  33 79 c2 00 28 01 00 7e  |   .....3y..(..~|
000039e0  10 a8 00 7e 42 a8 00 00  00 04 00 07 28 b2 8f 27  |...~B.......(..'|
000039f0  94 00 00 00 00 07 00 00  00 00 00 00 02 bc 00 00  |................|
00003a00  02 bc 00 00 00 00 07 85  81 85 00 01 00 00 00 31  |...............1|
00003a10  41 41 41 20 20 20 20 20  20 20 20 20 20 20 20 20  |AAA             |
00003a20  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003a30  20 20 20 20 20 20 20 00  47 41 41 41 20 20 20 20  |       .GAAA    |
00003a40  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
*
00003a60  00 01 00 00 00 00 00 00  07 28 b2 8f 2b 92 a8 00  |.........(..+...|
00003a70  07 28 b2 8f 2b 92 a8 00  07 28 b2 8f 2b c4 a8 00  |.(..+....(..+...|
00003a80  02 00 30 33 32 32 35 35  39 39 39 20 20 20 20 20  |..032255999     |
00003a90  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003aa0  20 20 20 20 20 20 20 20  20 20 00 00 30 30 39 31  |          ..0091|
00003ab0  32 32 32 33 36 39 31 31  30 30 20 20 20 20 20 20  |2223691100      |
00003ac0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003ad0  20 20 20 20 00 00 20 20  20 20 20 20 20 20 20 20  |    ..          |
00003ae0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00003af0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 00 00  |              ..|
00003b00  01 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00003b10  00 00 00 00 00 00 00 00  00 30 20 20 20 20 20 20  |.........0      |
00003b20  20 20 20 20 20 20 20 20  00 00 00 00 01 00 00 00  |        ........|

The effort to use code tags is appreciated, however you are using the wrong button, to use code tags please use the code button, the one that says code on it,

1 Like

Hi krk...

Why did you cut and paste badly almost 14KB into the file?

From that I still cannot associate the string of numbers in your post #1.

If possible do a hexdump of the first 1KB, (or maybe 2KB), of the file so I can find possible starts and ends of any __lines__...

As it stands I can't see any relationship with the numerical string(s) and the part you have shown...

EDIT:
You could look at man strings , as it extracts ascii strings from binary files...

hexdump -c <Binary-File> | head -20
0000000 020 001   3   y 302  \0   ( 001  \0   z 023 220  \0   z 031   l
0000010  \0  \0  \0 004  \0  \a   ( 262 217   ' 224  \0  \0  \0  \0  \a
0000020  \0  \0  \0  \0  \0  \0  \0 003  \0  \0  \0 003  \0  \0  \0  \0
0000030  \a 205 201   p  \0 001  \0  \0  \0   1   A   A   A
0000040
*
0000060      \0   G   A   A   K
0000070
0000080                                          \0 001  \0  \0  \0  \0
0000090  \0  \0  \a   ( 262 217   ' 225 220  \0  \a   ( 262 217   ' 225
00000a0 220  \0  \a   ( 262 217   ' 233   l  \0 002  \0   0   5   0   2
00000b0   5   3   7   8   9
00000c0
00000d0                  \0  \0   0   0   3   9   0   2   4   5   5   1
00000e0   8   4   8   7
00000f0                                                          \0  \0
0000100
*
0000120                                  \0  \0 001  \0  \0  \0  \0  \0
0000130  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
strings <Binary-File> | head -10
1AAA
GAAK
050253789
00390245518487

0
0
0
PEAK
I_000039_A01

Hi krk...

From your limited octal dump I still cannot discern any patterns that work according to your original post...

I therefore have to bow out gracefully as I cannot help you any further...

when i execute the command

file <binary_filename>

i get below message.

0420 Alliant virtual executable common library not stripped.

does that ring any bells ?

Not really.

What makes you suspect there's anything useful in this file to extract?

I need to decode the binary file ,convert it in ASCII and load its contents into oracle table.

when i do a

file -i <filename> 

i get below o/p

application/octet-stream

As per my source , this a binary file encoded with base32.
Coud you please let me how should i decode the file.I mean what shoudl be my first step. I have the specification of file like

No	Field Name	        Type	        Offset  ASCII_Length	Bytes	    Binary Type
C1	Record Type	Number(3)	 1	  3	                       1    Unsigned Char
C2	Call Date	        Date	         4	  8                            4    Long
C3	Operator	        Number (4)	 12	  4	                       2    Unsigned short
C4	Segment Number	Number(3)	 16	  3	                       1    Unsigned Char

help appreciated.

As per RFC 3548,

So none of the samples you presented by now can by any means be base32 coded.

Is it possible you have a fixed length record file to be interpreted according to above scheme?

first three lines from the fixed length ascii converted file

016 20150722 0040 001 08000400 08001900 0000004 2015072208000000 0000007 0000000003 0000003 000000000126189936 0001 0 0000 1AAA                                     GAAK                                     1 000 000000000 2015072208000400 2015072208000400 2015072208001900 0 002 000 050253789                                000 00390245518487                           000                                          0001 00000 000 0 000000000 00 000 000 000 0000000 0000000 0000000 0               000 000 00001 00000 00000000 00000000 000000000000 000000000000 0    0      2015072207200800 000000000000441471 n OUT PEAK I_000039_A01 1100         I_000039_A01 K     INTL  BT    0086 EUR 201507 201507 0002 0300 000 0000 0   000000 0     00 0 00000.001900000 00000.000000000 0000 00000 0    1 0000015.0000 00000.000480000 0000015.0000 00000.000480000 0000 0000000 0000 0000000               0 0000015.0000 0000015.0000 0000015.0000 0000015.0000 0040 CAS 0000015.0000 0000015.0000 0            0            000
016 20150722 0040 001 08012100 08021000 0000004 2015072208000000 0000007 0000000026 0000026 000000000126189937 0001 0 0000 1AAA                                     GAAK                                     1 000 000000000 2015072208012100 2015072208012100 2015072208021000 0 002 000 051612066                                000 0033497050528                            000                                          0001 00000 000 0 000000000 00 000 000 000 0000000 0000000 0000000 0               000 000 00001 00000 00000000 00000000 000000000000 000000000000 0    0      2015072207200800 000000000000441471 n OUT PEAK I_000033_A01 1100         I_000033_A01 K     INTL  BT    0086 EUR 201507 201507 0002 0300 000 0000 0   000000 0     00 0 00000.002600000 00000.000000000 0000 00000 0    1 0000049.0000 00000.002120000 0000049.0000 00000.002120000 0000 0000000 0000 0000000               0 0000049.0000 0000049.0000 0000049.0000 0000049.0000 0040 CAS 0000049.0000 0000049.0000 0            0            000
016 20150722 0040 001 07515400 08000000 0000004 2015072208000000 0000007 0000000075 0000075 000000000126189938 0001 0 0000 1AAA                                     GAAA                                     1 000 000000000 2015072207515400 2015072207515400 2015072208042800 0 002 000 036852654                                000 0031765412557                            000                                          0001 00000 000 0 000000000 00 000 000 000 0000000 0000000 0000000 0               000 000 00001 00000 00000000 00000000 000000000000 000000000000 0    0      2015072207200800 000000000000441471 n OUT OFFP I_000031_A01 1100         I_000031_A01 A     INTL  BT    0086 EUR 201507 201507 0002 0300 000 0000 0   000000 0     00 0 00000.003500000 00000.000000000 0000 00000 0    1 0000486.0000 00000.028350000 0000754.0000 00000.043980000 0000 0000000 0000 0000000               0 0000486.0000 0000754.0000 0000486.0000 0000754.0000 0040 CAS 0000486.0000 0000754.0000 0            0            000

This doesn't match neither your specification in post#12 (spaces!) nor any of your "binary" samples. What does "fixed length ascii converted" mean? Could you attach some original records without any modification?

---------- Post updated at 17:21 ---------- Previous update was at 17:15 ----------

Would this interpretation ignoring any spaces (c.f. rightmost column) ring a bell?

No      Field Name      Type            Offset  Length  Bytes   Binary Type     Value
C1      Record Type     Number(3)       1       3       1       Unsigned Char   016
C2      Call Date       Date            4       8       4       Long            20150722
C3      Operator        Number (4)      12      4       2       Unsigned short  0040
C4      Segment Number  Number(3)       16      3       1       Unsigned Char   001
                                                                                08000400
                                                                                .
                                                                                .
                                                                                .

I don't think you know what base32 is. I think this file is pure binary with no encoding at all.

Handling pure binary values is awkward in most scripting languages. Do you have a C compiler available?

Please attach some of your raw unmodified input data. Your examples don't seem to agree with each other.

I don't think it's binary either. Talking of post#14, it's a fixed field fixed record ASCII file (not text!). No idea what/why the spaces are in there.

i'll brief the requirements again.

I have a binary file (base32 encoded) and a ASCII version of the same binary file.But i don't have a conversion code/logic/algorithm.I do have file specification.
I need to figure out a way to convert the binary file to asciii fixed length file so that i can load it contents into oracle table.

I've already posted the content of the binary file , ascii file & file spec in my previous post.

You guys give a unix command(head,od,tail ... ) ,i'll apply it to the binary file and paste the o/p in here.

many thanks.

You've posted printouts of what some ASCII editors think that binary file looks like, none of which agree with each other, so we don't trust it. Try attaching the file itself.