中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

bash對字符串做簡單加解密及應用

發布時間:2020-08-09 10:43:53 來源:ITPUB博客 閱讀:169 作者:ahfhuang 欄目:建站服務器

一、生成密碼及加解密
1、原代碼

cat  gen_en_de_pswd.sh

 

#!/bin/bash

case $1 in
        1 )
           # 隨機產生n位數字符串
           echo -e "Enter your password length: "
           read length
           if [ $length -gt 10 ] ;then
              pw=`cat /dev/urandom | head -n 10 | md5sum | head -c $length`
              echo "The password is:" $pw
           elif [ $length -le 10 ] && [ $length -ge 5 ]; then
              pw=`cat /dev/urandom |head -n 10000| sed 's/[^a-zA-Z0-9]//g' | strings -n $length |head -c $length`
              echo "The password is:" $pw
           else
              echo "Your password is too short,Please try again!"
           fi
           ;;
          
        2 )
           # 對字符串做簡單的加密
           echo -e "Enter your password which need to encrypt: "
           read passwd
           en_tmp=`echo $passwd|tr '0123456789ANzmGT#$&*' 'ANzmGT#$&*0123456789'|tr 'BCDEFHIJKLMOPQRSUVWXYZabcdefghijklnopqrstuvwxy' 'OPQRSUVWXYZBCDEFHIJKLMnopqrstuvwxyabcdefghijkl'`
           len=`echo ${#en_tmp}`
           if [ $len -lt 10 ] ;then
              suf_len=`expr 10 - $len`
              suffixal=`cat /dev/urandom |head -n 1000| sed 's/[^a-zA-Z0-9]//g' | strings -n $suf_len |head -n 1|head -c $suf_len`
              en_pw=`echo ${suf_len}${en_tmp}${suffixal}|rev`
#              echo $en_pw
           elif [ $len -eq 10 ]; then
              suf_len=0
              en_pw=`echo ${suf_len}${en_tmp}|rev`
           elif [ $len -eq 11 ]; then
              suf_len=$
              en_pw=`echo ${suf_len}${en_tmp}${suf_len}|rev`
           else
              en_pw=`echo $en_tmp|rev`
#              echo $en_pw
           fi

           encrypt_pswd=''
           for i in `seq ${#en_pw}` 
           do

           if [ -n "$(echo ${en_pw:$i-1:1}| sed -n "/^[A-Z]\+$/p")" ];then

           str=`echo ${en_pw:$i-1:1} | awk -v letter_cnt=26 '
                                   BEGIN{
                                       i = 0;
                                       for(i = 0; i < letter_cnt; i++)
                                       {
                                           ch = sprintf("%c", i+65);
                                           trans_table[ch] = i;
                                           trans[25-i]=ch
          
                                       }
                                   }
                                   {
                                       if(NF == 1)
                                       {
                                           a=trans_table[$1]
                                           printf("%c", trans[a]);
                                     #     printf("%d", trans_table[$1]);
                                       }
                                   }'`
           else

           str=${en_pw:$i-1:1}
           fi

           encrypt_pswd=${encrypt_pswd}${str}
           done
          
           echo "Your encrypt password is:" $encrypt_pswd
           ;;
          
        3 )
           # 對上述2項加密的字符串進行解密
           echo -e "Enter your password which need to decode: "
           read passwd
           decode_pd=''
           for i in `seq ${#passwd}` 
           do
           if [ -n "$(echo ${passwd:$i-1:1}| sed -n "/^[A-Z]\+$/p")" ];then

           str=`echo ${passwd:$i-1:1} | awk -v letter_cnt=26 '
                                   BEGIN{
                                       i = 0;
                                       for(i = 0; i < letter_cnt; i++)
                                       {
                                           ch = sprintf("%c", i+65);
                                           trans_table[ch] = i;
                                           trans[25-i]=ch
          
                                       }
                                   }
                                   {
                                       if(NF == 1)
                                       {
                                           a=trans_table[$1]
                                           printf("%c", trans[a]);
                                     #     printf("%d", trans_table[$1]);
                                       }
                                   }'`
           else

           str=${passwd:$i-1:1}
           fi

           decode_pd=${decode_pd}${str}
#          echo $decode_pd

           done

           first_str=${decode_pd:0:1}
           last_str=${decode_pd: -1}
          
           if [ ${#decode_pd} -eq 11 ] ;then
              tmp=`echo $decode_pd`
              redundancy=${tmp: -1}
              len=`expr 10 - $redundancy`
              de_pw=`echo ${tmp:${redundancy}:${len}}|rev|tr '0123456789ANzmGT#$&*' 'ANzmGT#$&*0123456789'|tr 'BCDEFHIJKLMOPQRSUVWXYZabcdefghijklnopqrstuvwxy' 'OPQRSUVWXYZBCDEFHIJKLMnopqrstuvwxyabcdefghijkl'`
             
           elif [ ${#decode_pd} -eq 13 ] && [ $first_str == '$' ] && [ $last_str == '$' ]; then
              de_pw=`echo ${decode_pd:1:11}|rev|tr '0123456789ANzmGT#$&*' 'ANzmGT#$&*0123456789'|tr 'BCDEFHIJKLMOPQRSUVWXYZabcdefghijklnopqrstuvwxy' 'OPQRSUVWXYZBCDEFHIJKLMnopqrstuvwxyabcdefghijkl'`

           else
              de_pw=`echo $decode_pd|rev|tr '0123456789ANzmGT#$&*' 'ANzmGT#$&*0123456789'|tr 'BCDEFHIJKLMOPQRSUVWXYZabcdefghijklnopqrstuvwxy' 'OPQRSUVWXYZBCDEFHIJKLMnopqrstuvwxyabcdefghijkl'`

           fi
          
           echo "Your decode password is:" $de_pw
           ;;
        * )
           echo "Please enter one parameter,choose the number.
1.generate code 2.encrypt passwd 3.decode passwd 4.Nothing"
           ;;
esac


2、如何使用
2.1 生成隨機密碼(密碼長度自己輸入)
[oracle@hyhxdb ~]$ sh gen_en_de_pswd.sh 1
Enter your password length:
8
The password is: rK92pdQR
[oracle@hyhxdb ~]$ sh gen_en_de_pswd.sh 1
Enter your password length:
11
The password is: 584253ce235

2.2 對生成的字符串加密
[oracle@hyhxdb ~]$ sh gen_en_de_pswd.sh 2
Enter your password which need to encrypt:
rK92pdQR
Your encrypt password is: 0KVWqcz*Ce2
[oracle@hyhxdb ~]$ sh gen_en_de_pswd.sh 2
Enter your password which need to encrypt:
584253ce235
Your encrypt password is: $GmzrpmGzT&G$

2.3 對加密字符串進行解密
[oracle@hyhxdb ~]$ sh gen_en_de_pswd.sh 3
Enter your password which need to decode:
0KVWqcz*Ce2
Your decode password is: rK92pdQR
[oracle@hyhxdb ~]$ sh gen_en_de_pswd.sh 3
Enter your password which need to decode:
$GmzrpmGzT&G$
Your decode password is: 584253ce235

二、簡單的應用
1、源代碼
cat example.sh 
#!/bin/bash
function de_passwd()
{
           passwd=$1
           decode_pd=''
           for i in `seq ${#passwd}` 
           do
           if [ -n "$(echo ${passwd:$i-1:1}| sed -n "/^[A-Z]\+$/p")" ];then

           str=`echo ${passwd:$i-1:1} | awk -v letter_cnt=26 '
                                   BEGIN{
                                       i = 0;
                                       for(i = 0; i < letter_cnt; i++)
                                          {
                                              ch = sprintf("%c", i+65);
                                              trans_table[ch] = i;
                                              trans[25-i]=ch
                                         
                                          }
                                        }
                                        {
                                            if(NF == 1)
                                            {
                                                a=trans_table[$1]
                                                printf("%c", trans[a]);
                                            }
                                        }'`
           else

           str=${passwd:$i-1:1}
           fi

           decode_pd=${decode_pd}${str}

           done
          
           first_str=${decode_pd:0:1}
           last_str=${decode_pd: -1}
          
           if [ ${#decode_pd} -eq 11 ] ;then
              tmp=`echo $decode_pd`
              redundancy=${tmp: -1}
              len=`expr 10 - $redundancy`
              de_pw=`echo ${tmp:${redundancy}:${len}}|rev|tr '0123456789ANzmGT#$&*' 'ANzmGT#$&*0123456789'|tr 'BCDEFHIJKLMOPQRSUVWXYZabcdefghijklnopqrstuvwxy' 'OPQRSUVWXYZBCDEFHIJKLMnopqrstuvwxyabcdefghijkl'`
             
           elif [ ${#decode_pd} -eq 13 ] && [ $first_str == '$' ] && [ $last_str == '$' ]; then
              de_pw=`echo ${decode_pd:1:11}|rev|tr '0123456789ANzmGT#$&*' 'ANzmGT#$&*0123456789'|tr 'BCDEFHIJKLMOPQRSUVWXYZabcdefghijklnopqrstuvwxy' 'OPQRSUVWXYZBCDEFHIJKLMnopqrstuvwxyabcdefghijkl'`

           else
              de_pw=`echo $decode_pd|rev|tr '0123456789ANzmGT#$&*' 'ANzmGT#$&*0123456789'|tr 'BCDEFHIJKLMOPQRSUVWXYZabcdefghijklnopqrstuvwxy' 'OPQRSUVWXYZBCDEFHIJKLMnopqrstuvwxyabcdefghijkl'`
           fi
           echo $de_pw
}
pswd=`de_passwd 'iImzMqtcuf2'`
# echo $pswd

sqlplus -s shpgd/${pswd}@shopguide <<EOF
select sysdate from dual;
exit
EOF

2、如何使用
2.1 先對原密碼加密
[oracle@hyhxdb ~]$ sh gen_en_de_pswd.sh 2
Enter your password which need to encrypt:
shpgd123
Your encrypt password is: iImzMqtcuf2

2.2 如何應用
在源代碼中修改如下的參數即可
pswd=`de_passwd 'iImzMqtcuf2'`

執行腳本即可

[oracle@hyhxdb ~]$ sh example.sh

SYSDATE
-------------------
2017-11-07 11:59:59

注:這只是簡單的加密,在有源碼情況下其實沒什么效果,后續有待完善,學習中。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

县级市| 临漳县| 环江| 道真| 青海省| 吉水县| 玉田县| 宜宾市| 林西县| 夏邑县| 邻水| 嵩明县| 双城市| 鲁甸县| 乡宁县| 浦东新区| 舞阳县| 偃师市| 长葛市| 凭祥市| 惠州市| 池州市| 南京市| 黄骅市| 泸水县| 青岛市| 邢台县| 罗定市| 浙江省| 巴南区| 郸城县| 清流县| 邛崃市| 太和县| 迭部县| 昔阳县| 武城县| 宝鸡市| 汤原县| 安远县| 鹤庆县|