-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·174 lines (153 loc) · 2.95 KB
/
run.sh
File metadata and controls
executable file
·174 lines (153 loc) · 2.95 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
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
#!/bin/bash
#Functions
xor () {
tput setaf 055
echo "Reading the contents of your file..."
tput setaf 255
x=$*
#Remove spaces
filter=$(echo "$x" | tr -d '\n')
sleep 1
echo "Your file has been analysed!"
#Convert
tput setaf 055
echo "Applying XOR..."
tput setaf 255
i=2
n=2
current=""
rm -f $location
while [ $i -le ${#filter} ]
do
if [ ${filter:i-2:2} == "48" ]
then
current=$(echo $(("0x00 ^ 0x${secret:n-2:2}")))
else
current=$(echo $(("0x${filter:i-2:2} ^ 0x${secret:n-2:2}")))
fi
#Line Feed
if [ $current -eq 10 ]
then
current="\n"
else
#Null byte
if [ $current -eq 0 ]
then
current=72
fi
current=$(printf "%x" $current)
if [ ${#current} -le 1 ]
then
current=$(echo "0$current")
fi
current=$(echo $current | xxd -p -r)
fi
#Redirect
printf "$current" >> "$location"
let i=i+2
let n=n+2
if [ $n -ge ${#secret} ]
then
let n=0
fi
done
echo "Your file has been processed!"
}
#Variables
content=""
#Intro
banner () {
tput setaf 055
printf " __ _ _ _ _\n / _(_) | ___ | | ___ ___| | _____ _ __\n| |_| | |/ _ \ | |/ _ \ / __| |/ / _ \ '__|\n| _| | | __/ | | (_) | (__| < __/ |\n|_| |_|_|\___| |_|\___/ \___|_|\_\___|_|\n\n"
tput setaf 1
echo "WARNING!: If you exit the program while it's running, your files may be deleted!"
tput setaf 255
}
#Password
prompt () {
tput setaf 055
echo "Give the password for your file..."
tput setaf 255
read -s -p "Password: " secret
echo ""
read -s -p "Re-enter password: " check_secret
echo ""
if [[ $secret != $check_secret ]]
then
echo "Passwords do not match!"
prompt
else
secret=$(printf "$secret" | xxd -p)
fi
}
banner
tput setaf 055
echo "Searching for your file(s)..."
tput setaf 255
sleep 1
#Main code
declare -a dir
declare -a file
#sort arguments for files and directories
while [ ! -z $1 ]
do
if [ -d $1 ]
then
dir+=($1)
shift
continue
elif [ -f $1 ]
then
file+=($1)
shift
continue
fi
echo "ERROR: $1 is not a file OR directory, skipping..."
shift
done
#check for files and directories
if [[ -z $dir && -z $file ]]
then
echo "ERROR: no file AND directory found!"
exit 1
fi
tput setaf 130
echo "Total directories found: ${#dir[@]}"
echo "Total files found: ${#file[@]}"
tput setaf 255
prompt
e=0
if [ ! -z $file ]
then
tput setaf 055
echo "Processing files... this may take a while"
tput setaf 255
while [ $e -lt ${#file[@]} ]
do
location=${file[$e]}
content=$(xxd -p ${file[$e]})
xor "$content"
e=$[$e+1]
done
fi
e=0
if [ ! -z $dir ]
then
echo "Processing directories... this may take a while"
while [ $e -lt ${#dir[@]} ]
do
for f in ${dir[$e]}*
do
if test -f "$f"
then
location=$f
content=$(xxd -p $f)
xor "$content"
fi
done
e=$[$e+1]
done
fi
tput setaf 002
echo "All files are encrypted, have a nice day!"
tput setaf 255