-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRot13.sh
More file actions
93 lines (84 loc) · 3.06 KB
/
Rot13.sh
File metadata and controls
93 lines (84 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
red="\e[31m" #Color variables to be used in the script
green="\e[32m"
yellow="\e[33m"
blue="\e[34m"
cyan="\e[36m"
endcolor="\e[0m"
printf $blue
figlet "Rot13"
printf $endcolor
function pathtest(){
read -p "$(echo -e "\n$cyan[?]$endcolor$yellow Please specify the path of the file you wish to encrypt/decrypt: $endcolor")" path
if [ -f $path ];
then
echo -e "$green[!] Path contains a file$endcolor\n"
process
else
echo -e "$red[!] No file found in the specified path\n$endcolor"
pathtest
fi
}
function process(){
read -p "$(echo -e "\n$cyan[?]$endcolor$yellow Please specify wheter you'd like to$endcolor$red [E]ncrypt$endcolor$yellow or $green[D]ecrypt$endcolor$yellow the file contents: $endcolor")" file
read -p "$(echo -e "\n$cyan[?]$endcolor$yellow Please provide a name for the output file: $endcolor")" name
if [ -z $name ]
then
echo -e "$red[!] Name was not specified. Please specify a name" ; sleep 0.3
process
else
echo -e "$green[+] Name registered ($endcolor$blue$name$endcolor$green)$endcolor" ; sleep 0.3
fi
case $file in
E)
echo -e "$cyan[*]$endcolor$red File encryption was selected$endcolor\n"
echo -e "$cyan[+]$endcolor$blue Encrypting the file's contents as $name.encrypted.txt...$endcolor" ; sleep 0.3
cat $path | tr 'A-Za-z' 'N-ZA-Mn-za-m' > $name.encrypted.txt
echo -e "\n$cyan[*]$endcolor$yellow The file was encrypted with Rot13 as $endcolor$green$name.encrypted.txt$endcolor"
;;
e)
echo -e "$cyan[*]$endcolor$red File encryption was selected$endcolor\n"
echo -e "$cyan[+]$endcolor$blue Encrypting the file's contents as $name.encrypted.txt...$endcolor" ; sleep 0.3
cat $path | tr 'A-Za-z' 'N-ZA-Mn-za-m' > $name.encrypted.txt
echo -e "\n$cyan[*]$endcolor$yellow The file was encrypted with Rot13 as $endcolor$green$name.encrypted.txt$endcolor"
;;
D)
echo -e "$cyan[*]$endcolor$green File decryption was selected$endcolor\n"
echo -e "$cyan[+]$endcolor$blue Decrypting the file's contents as $name.decrypted.txt...$endcolor" ; sleep 0.3
cat $path | tr 'N-ZA-Mn-za-m' 'A-Za-z' > $name.decrypted.txt
echo -e "\n$cyan[*]$endcolor$yellow The file was decrypted with Rot13 as $endcolor$green$name.decrypted.txt$endcolor"
;;
d)
echo -e "$cyan[*]$endcolor$green File decryption was selected$endcolor\n"
echo -e "$cyan[+]$endcolor$blue Decrypting the file's contents as $name.decrypted.txt...$endcolor" ; sleep 0.3
cat $path | tr 'N-ZA-Mn-za-m' 'A-Za-z' > $name.decrypted.txt
echo -e "\n$cyan[*]$endcolor$yellow The file was decrypted with Rot13 as $endcolor$green$name.decrypted.txt$endcolor"
;;
*)
echo -e "$red[!] Invalid encryption/decryption input!$endcolor" ; sleep 0.3
process
;;
esac
read -p "$(echo -e "\n$cyan[?]$endcolor$yellow Would you like to encrypt/decyrpt another file? [Y/N] $endcolor")" choice
case $choice in
Y)
pathtest
;;
y)
pathtest
;;
N)
echo -e "$green[*] Exiting...$endcolor" ; sleep 0.3
exit 1
;;
n)
echo -e "$green[*] Exiting...$endcolor" ; sleep 0.3
exit 1
;;
*)
echo -e "$red[!] Invalid input. Exiting...$endcolor" ; sleep 0.3
exit 1
;;
esac
}
pathtest