13 February 2011

new utility, basecon.pl

I've posted a new utility, basecon.pl, to the Tools page.  basecon.pl is a simple utility that converts base inputs to selected base output.  Currently, basecon.pl can accept input and output types of ascii, binary, decimal, hexadecimal, and octal.  The following is sample output from basecon.pl:
user@host [0] basecon.pl -h

basecon.pl converts base inputs to selected base output

Usage:  basecon.pl [ -h ]
        basecon.pl [ -V ]
        basecon.pl < -i IBASE > < -o OBASE > [ -v | -c [ -s CSEP ]]
                        [ -d ISEP ] val0 (val1 val2 ... valN)

    -h          This help output
    -V          Display basecon.pl version and exit
    -i IBASE    Base value of input
    -o OBASE    Base value to set for output
        Base Values:
                  a     ascii
                  b     binary
                  d     decimal
                  h     hexadecimal
                  o     octal
    -v          Verbose output (mutually exclusive to '-c')
    -c          CSV output (mutually exclusive to '-v')
    -s CSEP     CSV output delimiter (default is a pipe, '|')
    -d ISEP     Delimiter within an input string value

Note:   If output is set to ascii, unprintable ascii characters are
        replaced with '[Dval]', thus BS (backspace) would output as [D8]

Sample: convert from octal to ascii, verbose output, with '-' as 
    internal value delimiter:

        host [0] basecon.pl -v -io -oa -d - 150 105-146-147 154 141
        octal   =>      ascii
        150     =>      h
        105-146-147     =>      E-f-g
        154     =>      l
        141     =>      a

# input file:
  user@host [0] tail -5 infile0
  10.132.41.251
  10.132.41.252
  10.132.41.253
  10.132.41.254
  10.132.41.255
# decimal conversion to hexadecimal
  user@host [0] basecon.pl -id -oh -d . `tail -5 infile0`
  0a.84.29.fb
  0a.84.29.fc
  0a.84.29.fd
  0a.84.29.fe
  0a.84.29.ff
# decimal conversion to binary (verbose)
  user@host [0] basecon.pl -v -id -ob -d . `tail -5 infile0`
  decimal =>      binary
  10.132.41.251   =>      00001010.10000100.00101001.11111011
  10.132.41.252   =>      00001010.10000100.00101001.11111100
  10.132.41.253   =>      00001010.10000100.00101001.11111101
  10.132.41.254   =>      00001010.10000100.00101001.11111110
  10.132.41.255   =>      00001010.10000100.00101001.11111111
# decimal conversion to octal (verbose)
  user@host [0] basecon.pl -v -id -oo -d . `tail -5 infile0`
  decimal =>      octal
  10.132.41.251   =>      012.204.051.373
  10.132.41.252   =>      012.204.051.374
  10.132.41.253   =>      012.204.051.375
  10.132.41.254   =>      012.204.051.376
  10.132.41.255   =>      012.204.051.377
# decimal conversion to ascii (verbose)
  user@host [0] basecon.pl -v -id -oa -d . 84.105.77.79.83.67.76.73
  decimal =>      ascii
  84.105.77.79.83.67.76.73        =>      T.i.M.O.S.C.L.I
# ascii conversion to decimal (csv output)
  user@host [0] basecon.pl -c -ia -od -d " " "TiMOS CLI"
  ascii|decimal
  TiMOS CLI|84 105 77 79 83 67 76 73
# ascii conversion to hexadecimal (verbose)
  user@host [0] basecon.pl -v -ia -oh -d " " "TiMOS CLI"
  ascii   =>      hexadecimal
  TiMOS CLI       =>      54 69 4d 4f 53 43 4c 49
# ascii conversion to binary (verbose)
  user@host [0] basecon.pl -ia -ob -d " " "TiMOS CLI"
  01010100 01101001 01001101 01001111 01010011 01000011 01001100 01001001
# ascii conversion to octal (verbose)
  user@host [0] basecon.pl -v -ia -oo -d " " "TiMOS CLI"
  ascii   =>      octal
  TiMOS CLI       =>      124 151 115 117 123 103 114 111
# binary conversion to decimal (csv output, : delimiter)
  user@host [0] basecon.pl -c -s : -ib -od -d . 00001010.10000100.00101001.11111101
  binary:decimal
  00001010.10000100.00101001.11111101:10.132.41.253
# binary conversion to octal (csv output)
  user@host [0] basecon.pl -c -ib -oo -d . 00001010.10000100.00101001.11111101
  binary|octal
  00001010.10000100.00101001.11111101|012.204.051.375
# binary conversion to ascii
  user@host [0] basecon.pl -ib -oa -d " " "01000011 01001100 01001001"
  C L I
# binary conversion to hexadecimal
  user@host [0] basecon.pl -ib -oh -d " " "01000011 01001100 01001001"
  43 4c 49
# octal conversion to decimal (verbose)
  user@host [0] basecon.pl -v -io -od -d . 012.204.051.375 124.151.115.117.123.114.111
  octal   =>      decimal
  012.204.051.375 =>      10.132.41.253
  124.151.115.117.123.103.114.111 =>      84.105.77.79.83.67.76.73
# octal conversion to binary (verbose)
  user@host [0] basecon.pl -v -io -ob -d . 012.204.051.374 012.204.051.376
  octal   =>      binary
  012.204.051.374 =>      00001010.10000100.00101001.11111100
  012.204.051.376 =>      00001010.10000100.00101001.11111110
# octal conversion to ascii (verbose)
  user@host [0] basecon.pl -v -io -oa -d " " "124 151 115 117 123 103 114 111"
  octal   =>      ascii
  124 151 115 117 123 103 114 111 =>      T i M O S C L I
# octal conversion to hexadecimal (verbose)
  user@host [0] basecon.pl -v -io -oh -d . 012.204.051.375 117.123.114.111
  octal   =>      hexadecimal
  012.204.051.375 =>      0a.84.29.fd
  117.123.114.111 =>      4f.53.4c.49
# hexadecimal conversion to decimal (verbose)
  user@host [0] basecon.pl -v -ih -od -d : 0a:84:29:fd 08:00:27:d2:4e:8b
  hexadecimal     =>      decimal
  0a:84:29:fd     =>      10:132:41:253
  08:00:27:d2:4e:8b       =>      8:0:39:210:78:139
# hexadecimal conversion to octal (verbose)
  user@host [0] basecon.pl -v -ih -oo -d : 0a:84:29:fd 08:00:27:d2:4e:8b
  hexadecimal     =>      octal
  0a:84:29:fd     =>      012:204:051:375
  08:00:27:d2:4e:8b       =>      010:000:047:322:116:213
# hexadecimal conversion to binary (verbose)
  user@host [0] basecon.pl -v -ih -ob -d : 0a:84:29:fd 08:00:27:d2:4e:8b
  hexadecimal     =>      binary
  0a:84:29:fd     =>      00001010:10000100:00101001:11111101
  08:00:27:d2:4e:8b       =>      00001000:00000000:00100111:11010010:01001110:10001011
# hexadecimal conversion to ascii (verbose)
  user@host [0] basecon.pl -v -ih -oa -d " " "54 69 4d 4f 53 43 4c 49"
  hexadecimal     =>      ascii
  54 69 4d 4f 53 43 4c 49 =>      T i M O S C L I

No comments: