说下这个script脚本的功能:从标准输入端读取文本,再把这些文本分别换成相对应的ASCII码,接着把编码转换成一连串的1和0(中间的空格可以忽略掉)。另外这个脚本也适合加密中文句子。 这里举一个例子吧,我们输入 hello,将被加密成0110100001100101011011000110110001101111。
该shell脚本的代码如下:
#!/bin/sh # http://hektor.umcs.lublin.pl/~mikosmul/computing/shell-scripts/encode-binary # Written by Michal Kosmulski <mkosmul _at_ users _dot_ sourceforge _dot_ net> # This script is hereby put in the public domain. # # Print a series of ones and zeros to stdout representing the # ascii codes of characters from stdin. od -t x1 | cut -c 9- | tr a-f A-F | ( while read -d ' '; do echo -e 'ibase=16;obase=2;'"$REPLY"'\nquit' \ | bc | awk '{printf "%08s", $0}' done ) |