This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Given a string containing 8-char strings of 0's and 1's, | |
#return a string containing ASCII converted from binary | |
#METHOD 1 | |
while read p; do | |
INT=$((2#$p)) #convert from base 2 to base 10 | |
# \x interprets 'nnn' as hex and prints corresponding ASCII char | |
printf "\x$(printf %x $INT)" # %x prints arg as hex | |
done <bintext.txt | |
#METHOD 2 | |
while read p; do | |
OCTAL=$(echo "obase=8; ibase=2; $p" | bc) | |
# \ interprets 'nnn' as octal and prints corresponding ASCII char | |
# but we need to escape '\' with another '\' | |
printf "\\$(printf $OCTAL)" | |
done <bintext.txt |
There are two different versions that parse a LF (linefeed) delimited textfile containing all the 8-character binary strings from the original email. To convert from space-delimited to LF-delimited text, I simply pasted the text into an Emacs buffer and ran M-x replace-text and replaced [SPACE] with [RETURN] (which has to be entered in escaped form as Ctrl-q Ctrl-j in Emacs). bintext.txt is available here.
The first version is a bit more roundabout than the second because it converts from binary to decimal to hexadecimal to ASCII (4 steps).
The second version converts from binary to octal to ASCII (3 steps).
댓글 없음:
댓글 쓰기