如何在Linux中创建可以使用ROT13解密和加密文件的菜单?

时间:2013-10-17 23:53:01

标签: linux bash unix

#!/bin/bash

    selection=
    until [ "$selection" = "0"]; do
     echo ""
     echo "PROGRAM MENU"
     echo "1 - Encrypt text with Rot13"
     echo "2 - DEcrypt text with Rot13"
     echo ""
     echo "0 - Exit program"
     echo ""
     echo -n "Enter Selection:"
     read selection
     echo ""
     case $selection in
         1 ) echo "Line to be encrypted"
         rot13 "a-z"
         2 ) echo "Line to be decrypted"
         rot13 "n-za-m"
         3 ) exit;;
         * ) echo "Please enter 1,2, or 0"
     esac
done

我想读取.txt文件,加密,保存,然后解密。

1 个答案:

答案 0 :(得分:2)

快速谷歌搜索“rot13 in bash”给出了这个:using rot13 and tr command for having an encrypted email address

简而言之:

echo 'fooman@example.com' | tr '[A-Za-z]' '[N-ZA-Mn-za-m]'

这应该是ROT13 fooman@example.com。从这里它很容易添加一个菜单项,提供文件而不是管道,并将输出保存到文件。通过快速搜索也可以轻松找到所有其他操作。