实现如下图所示:
[root@localhost shell]# bash zong.sh
==================凯撒加密解密==============================
1)输入字符串,进行凯撒加密(输入的字符串只能是字母、数字、空格)
2)已有加密后的字符串进行解密
3)退出
INPUT:q
shell代码如下:
#!/bin/bash jiami(){ echo {a..z} | xargs -n1 >file echo {a..z} {A..Z} @ @ | xargs -n1 >>file read -p "Input:" num num1=`echo $num |sed ‘s/ /@/g‘ | tr ‘0-9‘ ‘A-J‘` a=${#num1} for i in `seq $a` do q=`echo $num1 | cut -c $i` w=`cat -n file | awk ‘/‘$q‘/‘ | head -1|awk ‘{print $1}‘` w=$(($w+1)) d=`cat file | sed -n ‘‘$w‘p‘` echo -n "$d" done echo } jiemi(){ echo {a..z} | xargs -n1 >file echo {a..z} {A..Z} {A..Z} @ @ | xargs -n1 >>file read -p "Input:" num num1=`echo $num |sed ‘s/@/@/g‘` a=${#num1} for i in `seq $a` do q=`echo $num1 | cut -c $i` w=`cat -n file | awk ‘/‘$q‘/‘ | tail -1|awk ‘{print $1}‘` w=$(($w-1)) d=`cat file | sed -n ‘‘$w‘p‘` v=`echo -n "$d"` echo -n $v | sed ‘s/@/ /g‘ | tr ‘A-J‘ ‘0-9‘ done echo } together(){ case $choice in 1) jiami ;; 2) jiemi ;; 3) exit 0 ;; *) exit 0 ;; esac } while : do cat << EOF ==================凯撒加密解密============================== 1)输入字符串,进行凯撒加密(输入的字符串只能是字母、数字、空格) 2)已有加密后的字符串进行解密 3)退出 EOF read -p "INPUT:" choice together echo done
实现效果如下:
==================凯撒加密解密==============================
1)输入字符串,进行凯撒加密(输入的字符串只能是字母、数字、空格)
2)已有加密后的字符串进行解密
3)退出
INPUT:1
Input:a 123b
b@CDEc
==================凯撒加密解密==============================
1)输入字符串,进行凯撒加密(输入的字符串只能是字母、数字、空格)
2)已有加密后的字符串进行解密
3)退出
INPUT:2
Input:b@CDEc
a 123b
本文出自 “IT生活” 博客,请务必保留此出处http://dingxue.blog.51cto.com/12290895/1972182
原文地址:http://dingxue.blog.51cto.com/12290895/1972182