-
Notifications
You must be signed in to change notification settings - Fork 0
/
cryption
191 lines (160 loc) · 4.03 KB
/
cryption
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash
while [ $# == 0 ];
do
echo "No arguments given"
echo "Usage: Try cryption -h for more help"
break
done
if (( $# >= 3 )); then
echo "Too many arguments"
echo "Usage: cryption -h for more help"
exit 1
fi
for i in $1
do
if [ $1 == "-v" -a $# != 2 ]
then
echo -e "cryption --Encrypt and Decrypt files securely\nVersion: 1.01"
break
elif [ $1 == "-v" -a $# == 2 ]
then
echo "Usage: Try cryption -h for more help"
break
elif [ $1 == "-h" -a $# != 2 -o $1 == "--help" -a $# != 2 ]
then
cat /home/akshay/Documents/cryption_help
break
elif [ $1 == "-h" -a $# == 2 -o $1 == "--help" -a $# == 2 ]
then
echo "Usage: Try cryption -h for more help"
fi
if [ $1 != -e -a $1 != -d -a $1 != -h -a $1 != "--help" -a $1 != -v -a $1 != "-el" ]
then
echo "Invalid option"
echo "Try cryption -h for more help"
elif [ $# != 2 ]
then
echo "Wrong Syntax "
echo "Usage: Try cryption -h for more help"
fi
#FOR ENCRYPTION
for i in $2
do
if [ $1 == -e ] && [ $# == 2 ]
then
if [ -f $2 -a ! -L $2 ]
then
if [ ${i##*.} == cpt ]
then
echo "Already encrypted"
echo "Usage: Try cryption -h for more help"
break
else
ccencrypt $2
echo "File encrypted"
break
fi
elif [ -L $2 ]
then
echo "link file found"
echo "Usage: cryption -el [ link_filename ] to forcefully encrypt link_source_file "
break
elif [ -d $2 ]
then
echo "Directory Found file expected"
echo "Usage: cryption -h for more help"
break
elif [ $2 == "-h" -o $2 == "--help" ]
then
echo -e "cryption -e help page\nEncryption help: \nUsage: cryption -e [file_name]"
break
elif [ ! -f $2 ]
then
echo "No such File "
echo "Usage: Try cryption -h for more help"
break
fi
elif [ $1 == -e ] && [ $# -ne 2 ]
then
echo "Invalid usage"
echo "Try cryption -h for more help"
break
fi
#FOR DECRYPTION
for i in $2
do
if [ $1 == -d ] && [ $# == 2 ]
then
if [ -L $2 ]
then
echo "link file found"
echo "Usage: Try cryption -h for more help"
break
elif [ -f $2 ]
then
if [ ${i##*.} == cpt ]
then
ccdecrypt $2
echo "File Decrypted"
else
echo "Cannot be decrypted"
echo "Usage: Try cryption -h for more help"
fi
elif [ -d $2 ]
then
echo "Directory Found file expected"
echo "Usage: cryption -h for more help"
break
elif [ $2 == "-h" -o $2 == "--help" ]
then
echo -e "cryption -d help page\nDecryption help:\nUsage: cryption -d [file_name.cpt]"
break
elif [ ! -f $2 ]
then
echo "No such file"
echo "Usage: Try cryption -h for more help"
fi
fi
# SYMBOLIC LINK ENCRYPTION
for i in $2
do
if [ $1 == "-el" -a $# == 2 ]
then
if [ -L $2 ]
then
if [ ${i##*.} == cpt ]
then
echo "Already encrypted"
echo "Usage: Try cryption -h for more help"
break
else
var=$(readlink -f $2)
ccencrypt $var
echo "Link source file encrypted"
break
fi
elif [ -f $2 ]
then
echo "Not an link file"
echo "Usage: cryption -h for more help"
break
elif [ -d $2 ]
then
echo "Directory found link file expected"
echo "Usage: cryption -h for more help"
break
elif [ $2 == "-h" -o $2 == "--help" ]
then
echo -e "cryption -el help page\nEncryption help: \nUsage: cryption -el [link_file_name]"
break
elif [ ! -f $2 ]
then
echo "No such file"
echo "Usage: Try cryption -h for more help"
break
fi
fi
done
done
done
done