-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.sh
executable file
·86 lines (56 loc) · 1.54 KB
/
test.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
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
#! /bin/sh
tests=0
successes=0
failures=0
H () {
printf "\n%-20s " "$*"
}
title() {
thistest="$1"
tests=$(($tests + 1))
}
successes=0
pass () {
printf '.'
successes=$(($successes + 1))
}
failures=0
fail () {
printf '(%s)' "$thistest"
failures=$(($failures + 1))
}
H "xor"
title "single-byte decimal"
printf 'hello' | ./xor 22 | grep -q '~szzy' && pass || fail
title "single-byte hex"
printf 'hello' | ./xor 0x16 | grep -q '~szzy' && pass || fail
title "single-byte -x"
printf 'hello' | ./xor -x 16 | grep -q '~szzy' && pass || fail
H "hex/unhex"
title "hex"
printf ' hello' | ./hex | grep -q '68 65 6c 6c 6f' && pass || fail
title "unhex"
echo '68 65 6c 6c 6f' | ./unhex | grep -q 'hello' && pass || fail
H "slice"
title "slice begin"
printf 'hello' | ./slice 2 | grep -qx 'llo' && pass || fail
title "slice begin + end"
printf 'hello' | ./slice 2 4 | grep -qx 'll' && pass || fail
title "slice begin + end + begin"
printf 'hello' | ./slice 0 2 4 | grep -qx 'heo' && pass || fail
H "hd"
title "hd short"
printf 'hello' | ./hd | grep -qx '00000000 68 65 6c 6c 6f.*hello' && pass || fail
H "Everything else"
title "entropy"
printf 'hello' | ./entropy | grep -q 1.921928 && pass || fail
title "pyesc"
printf '\0hello\n' | ./pyesc | grep -xq '.x00hello.n' && pass || fail
title "freq"
printf 'hello' | ./freq | grep -xq '2 6c l' && pass || fail
title "histogram"
printf 'hello' | ./freq | ./histogram | grep -xq '6c l ## 2' && pass || fail
echo
echo
echo "$successes of $tests tests passed ($failures failed)."
exit $failures