Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@ The game will include the following activities:
<br>
1. Breaking the Substitution Cipher
2. Reverse engineering a hash and finding a collision
3. Launching a DDoS attack / Rate limiting a DDoS attack
3. Launching a DDoS attack / Rate limiting a DDoS attack

## Running Tests

To verify the hash function works correctly run:

```bash
node test/simpleHash.test.js
```
5 changes: 4 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,4 +588,7 @@ function clearPythonOutput() {

// Initialize Pyodide when the sandbox is first interacted with
document.getElementById('pythonCode').addEventListener('focus', initPyodide);
document.querySelector('.sandbox-controls button').addEventListener('click', initPyodide);
document.querySelector('.sandbox-controls button').addEventListener('click', initPyodide);

// Export simpleHash for Node.js environments
if (typeof module !== 'undefined') module.exports = { simpleHash };
23 changes: 23 additions & 0 deletions test/simpleHash.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const assert = require('assert');

// Minimal DOM stubs so script.js can be loaded under Node
const dummy = new Proxy(function () {}, {
get: (target, prop) => {
if (prop === 'width' || prop === 'height') return 0;
return dummy;
},
apply: () => dummy,
set: () => true,
});
global.window = dummy;
global.document = dummy;

const { simpleHash } = require('../script.js');

// Test that simpleHash produces expected hash for known input
assert.strictEqual(simpleHash('AaBb'), 'A2B2');

// Two different inputs with identical character counts yield the same hash
assert.strictEqual(simpleHash('abc'), simpleHash('cba'));

console.log('All tests passed.');