专注各种脚本编程
Baidu
加入收藏夹
本站内容有下面分类知识,欢迎您的到来^_^
shell相关:指令篇 基础篇 脚本欣赏 编程实例 shell问问 shell视频教程 技巧篇 水平测试 E文资料 vi编辑器 高级Bash脚本编程指南
其他:mysql perl c语言 oracle
当前位置:| 主页>shell脚本欣赏>

加密文本成二进制内容的shell脚本

百度收藏 QQ搜藏

说下这个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
)

上一篇:用shell脚本显示文件下载进度功能 下一篇:使xscreensaver(屏幕保护程序)暂时失去功能的shell脚本

power by soyo123 2007-2008