-
Notifications
You must be signed in to change notification settings - Fork 0
/
p4gradingscript
executable file
·127 lines (121 loc) · 4.54 KB
/
p4gradingscript
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
#!/bin/bash
# FYI, this command removes file abc if it is empty: [ -s abc ] || rm -f abc
usage="usage: $0 encryptionport decryptionport"
#use the standard version of echo
echo=/bin/echo
#Make sure we have the right number of arguments
if test $# -gt 2 -o $# -lt 2
then
${echo} $usage 1>&2
exit 1
fi
#Record the ports passed in
encport=$1
decport=$2
#Run the daemons
otp_enc_d $encport &
otp_dec_d $decport &
${echo} '#-----------------------------------------'
${echo} '#START OF GRADING SCRIPT'
${echo} '#keygen 20 > key20'
keygen 20 > key20
${echo} "#5 POINTS: key20 must exist"
[ -s key20 ] || rm -f key20
if [ -f key20 ]; then ${echo} 'key20 exists!'; else ${echo} 'key20 DOES NOT EXIST'; fi
${echo}
${echo} "#-----------------------------------------"
${echo} "#5 POINTS: Number of characters in key20, should be 20:"
wc -m key20
${echo}
${echo} "#-----------------------------------------"
${echo} '#keygen 70000 > key70000'
keygen 70000 > key70000
${echo} "#5 POINTS: Number of characters in key70000, should be 70000:"
[ -s key70000 ] || rm -f key70000
wc -m key70000
${echo}
${echo} "#-----------------------------------------"
${echo} '#otp_enc plaintext1 key20 $encport'
${echo} "#10 POINTS: Should return error about too-short key"
otp_enc plaintext1 key20 $encport
${echo}
${echo} "#-----------------------------------------"
${echo} '#otp_enc plaintext1 key70000 $encport'
${echo} "#20 POINTS: Should return encrypted version of plaintext1"
otp_enc plaintext1 key70000 $encport
${echo}
${echo} '#-----------------------------------------'
${echo} '#otp_enc plaintext1 key70000 $encport > ciphertext1'
otp_enc plaintext1 key70000 $encport > ciphertext1
${echo} "#10 POINTS: ciphertext1 must exist"
[ -s ciphertext1 ] || rm -f ciphertext1
if [ -f ciphertext1 ]; then ${echo} 'ciphertext1 exists!'; else ${echo} 'ciphertext1 DOES NOT EXIST'; fi
${echo}
${echo} '#-----------------------------------------'
${echo} '#10 POINTS: ciphertext1 must be same number of chars as source'
${echo} '#wc -m plaintext1'
wc -m plaintext1
${echo} '#Should be same: wc -m ciphertext1'
wc -m ciphertext1
${echo}
${echo} '#-----------------------------------------'
${echo} '#5 POINTS: ciphertext1 should look encrypted'
cat ciphertext1
${echo}
${echo} '#-----------------------------------------'
${echo} '#otp_dec ciphertext1 key70000 $encport'
${echo} '#5 POINTS: Should fail giving error that otp_dec cannot find otp_dec_d'
otp_dec ciphertext1 key70000 $encport
${echo}
${echo} '#-----------------------------------------'
${echo} '#20 POINTS: should return decrypted ciphertext1 that matches source'
${echo} '#cat plaintext1'
cat plaintext1
${echo} '#otp_dec ciphertext1 key70000 $decport'
otp_dec ciphertext1 key70000 $decport
${echo}
${echo} '#-----------------------------------------'
${echo} '#otp_dec ciphertext1 key70000 $decport > plaintext1_a'
otp_dec ciphertext1 key70000 $decport > plaintext1_a
${echo} "#10 POINTS: plaintext1_a must exist"
[ -s plaintext1_a ] || rm -f plaintext1_a
if [ -f plaintext1_a ]; then ${echo} 'plaintext1_a exists!'; else ${echo} 'plaintext1_a DOES NOT EXIST'; fi
${echo}
${echo} '#-----------------------------------------'
${echo} '#5 POINTS: plaintext1 must be same number of chars as plaintext1_a'
${echo} '#wc -m plaintext1'
wc -m plaintext1
${echo} '#Should be same: wc -m ciphertext1'
wc -m plaintext1_a
${echo}
${echo} '#-----------------------------------------'
${echo} '#20 POINTS: concurrent test of encryption - look for 4 ciphertext# files'
${echo} '#5 POINTS: Should be only one error about plaintext5 being bad'
rm -f ciphertext*
rm -f plaintext*_*
otp_enc plaintext1 key70000 $encport > ciphertext1
otp_enc plaintext2 key70000 $encport > ciphertext2
otp_enc plaintext3 key70000 $encport > ciphertext3
otp_enc plaintext4 key70000 $encport > ciphertext4
otp_enc plaintext5 key70000 $encport > ciphertext5
[ -s ciphertext1 ] || rm -f ciphertext1
[ -s ciphertext2 ] || rm -f ciphertext2
[ -s ciphertext3 ] || rm -f ciphertext3
[ -s ciphertext4 ] || rm -f ciphertext4
[ -s ciphertext5 ] || rm -f ciphertext5
ls
${echo}
${echo} '#-----------------------------------------'
${echo} '#15 POINTS: concurrent test of decryption - look for 4 plaintext#_a files'
otp_dec ciphertext1 key70000 $decport > plaintext1_a
otp_dec ciphertext2 key70000 $decport > plaintext2_a
otp_dec ciphertext3 key70000 $decport > plaintext3_a
otp_dec ciphertext4 key70000 $decport > plaintext4_a
[ -s plaintext1_a ] || rm -f plaintext1_a
[ -s plaintext2_a ] || rm -f plaintext2_a
[ -s plaintext3_a ] || rm -f plaintext3_a
[ -s plaintext4_a ] || rm -f plaintext4_a
ls
${echo}
${echo} '#SCRIPT COMPLETE'
${echo}