PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Linux Convert Text To Binary & Back Again

Go down

Linux Convert Text To Binary & Back Again Empty Linux Convert Text To Binary & Back Again

Post by jamied_uk 30th July 2016, 14:07




Text To Binary


Code:
#!/bin/bash
# Usage: ./txt_to_binary2.sh "test123"
myvar="$@"
chrbin() {
        echo $(printf \\$(echo "ibase=2; obase=8; $1" | bc))
}

ordbin() {
  a=$(printf '%d' "'$1")
  echo "obase=2; $a" | bc
}

ascii2bin() {
    echo -n $* | while IFS= read -r -n1 char
    do
        ordbin $char | tr -d '\n'
        echo -n " "
    done
}

bin2ascii() {
    for bin in $*
    do
        chrbin $bin | tr -d '\n'
    done
}
ascii2bin "$myvar"







Binary To Text


Code:

#!/bin/bash
# Usage: ./binary_to_txt.sh "1010100 1001000 1001001 1010011 0 1001001 1010011 0 1000010 1001001 1001110 1000001 1010010 1011001 0 1100010 1101100 1100001 1100010 1101100 1100001 1100010 1101100 1100001 1100010 1101100 1100001 1100010 1101100 1100001 1100010 1101100 1100001 0 110001 110010 110011 110100 110101 110110 110111 111000 111001 110000"

myvar="$@"
chrbin() {
        echo $(printf \\$(echo "ibase=2; obase=8; $1" | bc))
}

ordbin() {
  a=$(printf '%d' "'$1")
  echo "obase=2; $a" | bc
}

ascii2bin() {
    echo -n $* | while IFS= read -r -n1 char
    do
        ordbin $char | tr -d '\n'
        echo -n " "
    done
}

bin2ascii() {
    for bin in $*
    do
        chrbin $bin | tr -d '\n'
    done
}
#ascii2bin "$myvar"

# Convert Binary To Text!
#
bin2ascii "$myvar"
jamied_uk
jamied_uk
Admin

Posts : 2950
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum