encrypth.sh用于对字符串加密,代码:
#!/bin/sh
if [[ $# != 1 ]];then
echo " Usage: encrypt.sh clear_word"
exit 1
fi
word=$(echo $1 | od -An -tx1 | sed 's/..$//')
for i in $(seq 1 ${#1});do
num=$(echo $word | awk -v c=$i '{print "ibase=16;"toupper($c)}' | bc)
code=$(awk -v char=$num 'BEGIN{print xor(char,120)}')
#xor(char,120)函数中的120是"x"字符的ascii值。
password=$password$code
done
echo ${password}
unset code word num
decrypt.sh 用于解密
代码:
#!/bin/sh
if [[ $# != 1 ]];then
echo "Usage: decrypt.sh
password"
exit 1
fi
for i in $(echo $1 | fold -2);do
code=$(awk "BEGIN{print xor($i,120)}")
letter=$(perl -e "print pack(c,$code)")
word=$word$letter
done
echo ${word}
unset word letter code
运行:
代码:
$ ./encrypt.sh db2inst
28267417221112
$ ./decrypt.sh 28267417221112
db2inst