-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtester.sh
executable file
·61 lines (53 loc) · 1.21 KB
/
tester.sh
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
#! /bin/bash
EXEC=${1:-ft_ssl}
DEST_MINE="mine.log"
DEST_SSL="ssl.log"
ALGORITHMS=("md5" "sha1" "sha224" "sha256" "sha384" "sha512")
HAS_ERROR=0
CMD=
ALGO=
# $1 msg_lengh
function check_one()
{
CMD="python3 -c \"print('a'*${1})\" | <exec>"
python3 -c "print('a'*${1})" | openssl $ALGO > $DEST_SSL
python3 -c "print('a'*${1})" | ./${EXEC} $ALGO > $DEST_MINE
diff $DEST_SSL $DEST_MINE
if [ $? -eq 0 ] ; then
CHECK_RES=1
else
CHECK_RES=0
fi
}
# $1=Test nb
function print_result()
{
echo -n $'\033[36m'"Test #${1}:"$'\033[33m'"'${CMD}'" $'\033[0m'
if [ $CHECK_RES -eq 1 ] ; then
echo $'\033[32m'"[PASS]"$'\033[0m'
else
echo $'\033[31m'"[FAIL]"$'\033[0m'
HAS_ERROR=1
fi
}
if [ ! -f $EXEC ] ; then
echo "error: target executable $EXEC not found."
fi
for name in ${ALGORITHMS[@]}; do
ALGO=$name
echo $'\033[33m'"TEST ALGO:" $'\033[36m'${ALGO}$'\033[0m'
check_one "10"
print_result "1"
check_one "63"
print_result "2"
check_one "61"
print_result "3"
check_one "420420"
print_result "4"
check_one "696969"
print_result "5"
check_one "0"
print_result "6"
done
rm $DEST_MINE $DEST_SSL
exit $HAS_ERROR