forked from maxdougherty/snap_autograder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw2Encryptify.html
415 lines (351 loc) · 18.9 KB
/
hw2Encryptify.html
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Snap! Build Your Own Blocks. Beta</title>
<link rel="shortcut icon" href="favicon.ico">
<script src="jschannel.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript" src="underscore-min.js"></script>
<!--<script type="text/javascript" src='gradingLog.js'></script>-->
<script type="text/javascript" src='spriteEventLog.js'></script>
<script type="text/javascript" src='scriptAnalysis.js'></script>
<meta charset="utf-8">
<!-- Moved down to the bottom to have var id. -->
<script type="text/javascript" src="morphic.js"></script>
<script type="text/javascript" src="widgets.js"></script>
<script type="text/javascript" src="blocks.js"></script>
<script type="text/javascript" src="threads.js"></script>
<script type="text/javascript" src="objects.js"></script>
<script type="text/javascript" src="gui.js"></script>
<script type="text/javascript" src="paint.js"></script>
<script type="text/javascript" src="lists.js"></script>
<script type="text/javascript" src="byob.js"></script>
<script type="text/javascript" src="xml.js"></script>
<script type="text/javascript" src="store.js"></script>
<script type="text/javascript" src="locale.js"></script>
<script type="text/javascript" src="cloud.js"></script>
<script type="text/javascript" src="sha512.js"></script>
<script type="text/javascript" src="snap-edx-overrides.js"></script>
<link rel="stylesheet" type="text/css" href="AG_status_bar.css" />
<link rel="stylesheet" type="text/css" href="hintstyle.css" />
<script type="text/javascript" src="AGAgent.js"></script>
<script type="text/javascript" src='feedbackLog.js'></script>
<script type='text/javascript'>
var starter_path = null;
// The id is to act as a course identifier.
// NOTE: FOR NOW YOU ALSO HAVE TO ADD THE ID TO THE BOTTOM OF THE PAGE.
var courseID = "CS10"; // e.g. "BJCx"
// Specify a prerequisite task id, should be null if no such requirement.
var preReqTaskID = null;
var preReqID = courseID + preReqTaskID;
// taskID uniquely identifies the task for saving in browser sessionStorage.
var taskID = "_hw2Encryptify";
var id = courseID + taskID;
var isEDX = isEDXurl();
// if this question is not meant to be graded, change this flag to false
var graded = true;
// to hide feedback for this problem, change this flag to false
var showFeedback = true;
// to allow for the ability to regrade certain tests, change this flag to true
var regradeOn = false;
// Add tests to the outputLog. Function is called by runAGTest(id, outputLog)
// var testLog;
function AGTest(outputLog) {
//NOTES FOR CS10 Readers:
// If there are comments in the scripting area, some tests will fail. Delete comments before clicking "Get Feedback."
// Make sure all of the blocks being tested are present in the scripting area for the first (original) sprite.
var validKeyExists = function() {
return spriteContainsBlock("valid key? %", 0);
}
var fb = new FeedbackLog(null, id, 'this is a feedback log test', 0);
fb.snapWorld = world;
// Create a first test chunk
var first_chunk = fb.newChunk('Make the "valid key? %" block.');
// Add a first tip to that first test chunk
var first_tip = first_chunk.newTip('Make sure to name your block exactly "valid key? %", and place it in the scripting area.',
'Great job!');
var ass_test1 = first_tip.newAssertTest(
validKeyExists,
"Testing to see if a 'valid key? %' block is in the scripting area.",
"There is a 'valid key? %' block in the scripting area.",
"Make sure there is a 'valid key? %' block in the scripting area.",
1);
var second_tip = first_chunk.newTip("Make sure 'valid key? %' doesn't give false positives. (-2 points)",
'Great job!');
second_tip.newIOTest('r', //testClass
"valid key? %", //blockSpec
["hors eee"], //input
false, //output
5000000, //timeout
false, //isolated
1); //points
second_tip.newIOTest('r', //testClass
"valid key? %", //blockSpec
["h0rs3"], //input
false, //output
5000000, //timeout
false, //isolated
1); //points
second_tip.newIOTest('r', //testClass
"valid key? %", //blockSpec
["horse!"], //input
false, //output
5000000, //timeout
false, //isolated
1); //points
// second_tip.newIOTest('r', //testClass
// "valid key? %", //blockSpec
// [" "], //input
// false, //output
// 5000000, //timeout
// false, //isolated
// 1); //points
var third_tip = first_chunk.newTip("Make sure 'valid key? %' doesn't give false negatives. (-2 points)",
'Great job!');
third_tip.newIOTest('r', //testClass
"valid key? %", //blockSpec
["horse"], //input
true, //output
5000000, //timeout
false, //isolated
1); //points
third_tip.newIOTest('r', //testClass
"valid key? %", //blockSpec
["HoRsE"], //input
true, //output
5000000, //timeout
false, //isolated
1); //points
third_tip.newIOTest('r', //testClass
"valid key? %", //blockSpec
["horsesROCK"], //input
true, //output
5000000, //timeout
false, //isolated
1); //points
var encryptPhraseExists = function() {
return spriteContainsBlock("encrypt phrase % using key %", 0);
}
var second_chunk = fb.newChunk('Make the "encrypt phrase % using key %" block.');
var first_tip2 = second_chunk.newTip('Make sure to name your block exactly "encrypt phrase % using key %", and place it in the scripting area.',
'Great job!');
var ass_test1_2 = first_tip2.newAssertTest(
encryptPhraseExists,
"Testing to see if a 'encrypt phrase % using key %' block is in the scripting area.",
"There is a 'encrypt phrase % using key %' block in the scripting area.",
"Make sure there is a 'encrypt phrase % using key %' block in the scripting area.",
1);
var second_tip2 = second_chunk.newTip("Make sure 'encrypt phrase % using key %' correctly encrypts the given phrase (alphabetical characters only) (-3 points).",
'Great job!');
second_tip2.newIOTest('r', //testClass
"encrypt phrase % using key %", //blockSpec
["thewolfsniffedhappily", "ajk"], //input
"wifzrogvqlggfeibssloj", //output
5000000, //timeout
false, //isolated
1); //points
second_tip2.newIOTest('r', //testClass
"encrypt phrase % using key %", //blockSpec
["HellomynameISJOSHHUG", "zyz"], //input
"hellomynameisjoshhug", //output
5000000, //timeout
false, //isolated
1); //points
var third_tip2 = second_chunk.newTip("Make sure 'encrypt phrase % using key %' filters out weird characters from the given phrase when encrypting. (-1 point)",
'Great job!');
third_tip2.newIOTest('r', //testClass
"encrypt phrase % using key %", //blockSpec
["The WOLF sniffed,,;;;;;5555 hapPily.", "ajk"], //input
"wif zrog vqlggfe ibssloj", //output
5000000, //timeout
false, //isolated
1); //points
third_tip2.newIOTest('r', //testClass
"encrypt phrase % using key %", //blockSpec
["H.e.l.l.o., m!y! n~a~m~e~ I^S^ J*O*S*H* H(U)G.", "zyz"], //input
"hello my name is josh hug", //output
5000000, //timeout
false, //isolated
1); //points
var fourth_tip2 = second_chunk.newTip("Make sure 'encrypt phrase % using key %' keeps spaces when encrypting. (-0.5 points)",
'Great job!');
fourth_tip2.newIOTest('r', //testClass
"encrypt phrase % using key %", //blockSpec
["I am the True King of the wolves", "horse"], //input
"k ap yjf ywzf mkqi tg yjf otnhfx", //output
5000000, //timeout
false, //isolated
1); //points
var createCiphertextExists = function() {
return spriteContainsBlock("create ciphertext alphabet from key %", 0);
}
var third_chunk = fb.newChunk('Make the "create ciphertext alphabet from key %" block.');
var first_tip3 = third_chunk.newTip('Make sure to name your block exactly "create ciphertext alphabet from key %", and place it in the scripting area.',
'Great job!');
var ass_test1_3 = first_tip3.newAssertTest(
createCiphertextExists,
"Testing to see if a 'create ciphertext alphabet from key %' block is in the scripting area.",
"There is a 'create ciphertext alphabet from key %' block in the scripting area.",
"Make sure there is a 'create ciphertext alphabet from key %' block in the scripting area.",
1);
var second_tip3 = third_chunk.newTip("Make sure 'create ciphertext alphabet from key %' correctly creates a cipheralphabet. (-4 points) (partial credit...?)",
'Great job!');
second_tip3.newIOTest('r', //testClass
"create ciphertext alphabet from key %", //blockSpec
["ajk"], //input
["b", "c", "d", "e", "f", "g", "h", "i", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "a", "j", "k"], //output
5000000, //timeout
false, //isolated
1); //points
second_tip3.newIOTest('r', //testClass
"create ciphertext alphabet from key %", //blockSpec
["horse"], //input
["a", "b", "c", "d", "f", "g", "i", "j", "k", "l", "m", "n", "p", "q", "t", "u", "v", "w", "x", "y", "z", "h", "o", "r", "s", "e"], //output
5000000, //timeout
false, //isolated
1); //points
second_tip3.newIOTest('r', //testClass
"create ciphertext alphabet from key %", //blockSpec
["ajka"], //input
["b", "c", "d", "e", "f", "g", "h", "i", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "j", "k", "a"], //output
5000000, //timeout
false, //isolated
1); //points
var decryptPhraseExists = function() {
return spriteContainsBlock("decrypt phrase % using key %", 0);
}
var fourth_chunk = fb.newChunk('Make the "decrypt phrase % using key %" block.');
var first_tip4 = fourth_chunk.newTip('Make sure to name your block exactly "decrypt phrase % using key %", and place it in the scripting area.',
'Great job!');
var ass_test1_4 = first_tip4.newAssertTest(
decryptPhraseExists,
"Testing to see if a 'decrypt phrase % using key %' block is in the scripting area.",
"There is a 'decrypt phrase % using key %' block in the scripting area.",
"Make sure there is a 'decrypt phrase % using key %' block in the scripting area.",
1);
var second_tip4 = fourth_chunk.newTip("Make sure 'decrypt phrase % using key %' correctly decrypts the given phrase (alphabetical characters only) (-2 points).",
'Great job!');
second_tip4.newIOTest('r', //testClass
"decrypt phrase % using key %", //blockSpec
["wif", "ajk"], //input
"the", //output
5000000, //timeout
false, //isolated
1); //points
second_tip4.newIOTest('r', //testClass
"decrypt phrase % using key %", //blockSpec
["wifzrogvqlggfeibssloj", "ajk"], //input
"thewolfsniffedhappily", //output
5000000, //timeout
false, //isolated
1); //points
var third_tip4 = fourth_chunk.newTip("Make sure 'decrypt phrase % using key %' filters out weird characters from the given phrase when decrypting. (-1 point)",
'Great job!');
third_tip4.newIOTest('r', //testClass
"decrypt phrase % using key %", //blockSpec
["w.i,f!", "ajk"], //input
"the", //output
5000000, //timeout
false, //isolated
1); //points
third_tip4.newIOTest('r', //testClass
"decrypt phrase % using key %", //blockSpec
["wif... zrog vq***lggfe ibss[[loj", "ajk"], //input
"the wolf sniffed happily", //output
5000000, //timeout
false, //isolated
1); //points
var fourth_tip4 = fourth_chunk.newTip("Make sure 'decrypt phrase % using key %' keeps spaces when decrypting. (-0.5 points)",
'Great job!');
fourth_tip4.newIOTest('r', //testClass
"decrypt phrase % using key %", //blockSpec
["w i f", "ajk"], //input
"t h e", //output
5000000, //timeout
false, //isolated
1); //points
return fb;
}
</script>
<script type="text/javascript" src='feedbackLog.js'></script>
<script type="text/javascript" src="AGFormatting.js"></script>
<script type="text/javascript">
var world;
window.onload = function () {
//INITIALIZE UP SNAP
world = new WorldMorph(document.getElementById('world'));
new IDE_Morph().openIn(world);
var ide = world.children[0];
//Reduce Stage Size on initialization
ide.toggleStageSize(true);
initializeSnapAdditions(world, id);
//AUTOGRADER ADDITION -
//Forced to use setTimeout() to let the world load before... Maybe not.
//Create a gradingLog and initialize the AG status bar (AGSB).
//Initialize AGSB button.
var grade_button = document.getElementById("autograding_button");
grade_button.addEventListener('click', button_listener);
var world_canvas = document.getElementById('world');
world_canvas.addEventListener("mouseup", update_listener);
// Start Snap Environment Loop
setInterval(loop, 1);
};
function loop() {
world.doOneCycle();
}
</script>
<script type="text/javascript" src='feedbackLog.js'></script>
<script type="text/javascript" src="AG_EDX.js"></script>
</head>
<body style="margin: 0;">
<canvas id="world" tabindex="1" style="position: absolute;" ></canvas>
<!-- Snap Autograding Button -->
<div id="autograding_bar">
<div tabindex="0" class="onclick-menu" id='onclick-menu' style="display:inline-block">
<span title="Menu">☰</span>
<div class='hover_darken'></div>
<nav id="navigation" class="site-navigation" role="navigation">
<ul id="dropdown-closed" class="bubble">
<!--<li class="menu-item-sub-menu" id="enabled-button"><a id="feedback-button">View Feedback</a></li>
<li class="menu-divider-sub-menu" id='menu-divider'></li>-->
<li class="menu-item-sub-menu" id="enabled-button"><a id="undo-button">Revert To Last Attempt</a></li>
<li class="menu-item-sub-menu" id="enabled-button"><a id="revert-button">Revert To Best Attempt</a></li>
<!--<li class="menu-item-sub-menu" id="enabled-button"><a id="last-submit">Revert To Last edX Submission</a></li>-->
<li class="menu-item-sub-menu" id="enabled-button"><a id="reset-button">Reset</a></li>
<li class="menu-divider-sub-menu" id='menu-divider'></li>
<li class="menu-item-sub-menu" id='enabled-button' onclick="openPopup();"><a id="help-button">Help</a></li>
</ul>
</nav>
</div>
<div id="autograding_button" style="display:inline-block;">
<span></span>
<div class='hover_darken'></div>
</div>
<div id="numtips" style="display:inline-block"></div>
</div>
<!-- Snap Autograding Menu -->
<!-- Autograding Menu Help Button -->
<div class="overlay is-hidden" id="overlay">
<p class="help-text" id="full-screen-arrow">↘</p>
<p class="help-text" id="full-screen-help">This full-screen button will pop out the Snap! window.</p>
<p class="help-text" id="menu-item-arrow">↗</p>
<p class="help-text" id="menu-item-help">The first two menu items will revert your current Snap! state to one of your previous attempts, depending on whether you wish to revert to your last graded attempt or to your best attempt.</br></br>The 'Reset' button will revert to a blank Snap! project, or to a provided starter file if one is given for this problem.</p>
<p class="help-text" id="ag-button-arrow">↑</p>
<p class="help-text" id="ag-button-help">Clicking this button will grade your current attempt and send the results to edX.</p>
</div>
<div style="display:inline-block" class="view-results" id="circle" onclick="openResults();">Results
</div>
<div class="overlay is-hidden" id="ag-output">
<div class="popup-content" id="ag-results">
<span class="button-close" onclick="closeResults();" id="popup">X</span>
<!--<p id = "different-feedback"></p>
<p id = "edx-submit-different"></p>-->
<div id="toggle-correct-tests"></div>
<p id="comment"></p>
</div>
</div>
</div>
<script type="text/javascript" src="AG_status_bar.js" />
</body>
</html>