diff --git a/src/main/java/uk/ac/cardiff/nsa/hashenc/context/UserEncryptionContext.java b/src/main/java/uk/ac/cardiff/nsa/hashenc/context/UserEncryptionContext.java
index acfdedf..56011d8 100644
--- a/src/main/java/uk/ac/cardiff/nsa/hashenc/context/UserEncryptionContext.java
+++ b/src/main/java/uk/ac/cardiff/nsa/hashenc/context/UserEncryptionContext.java
@@ -37,7 +37,7 @@ public class UserEncryptionContext {
public UserEncryptionContext() {
encMessage = "Text";
encKey = "0";
- chosenEncFunction = "caesar-cipher";
+ chosenEncFunction = "(a) caesar-cipher";
}
public boolean isImageInitialised() {
diff --git a/src/main/java/uk/ac/cardiff/nsa/hashenc/controller/EncryptionController.java b/src/main/java/uk/ac/cardiff/nsa/hashenc/controller/EncryptionController.java
index 18849db..3ce82e5 100644
--- a/src/main/java/uk/ac/cardiff/nsa/hashenc/controller/EncryptionController.java
+++ b/src/main/java/uk/ac/cardiff/nsa/hashenc/controller/EncryptionController.java
@@ -3,8 +3,10 @@
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.TreeMap;
import java.util.stream.Collectors;
import javax.script.ScriptException;
@@ -30,7 +32,7 @@
import uk.ac.cardiff.nsa.hashenc.engine.ScriptHelper;
/**
- * Basic Encryption controller. Is not thread-safe and will leak settings between users.
+ * Basic Encryption controller.
*
*
* Note, 'message' is used here in place of 'plaintext'.
@@ -44,12 +46,12 @@ public class EncryptionController {
private final Logger log = LoggerFactory.getLogger(EncryptionController.class);
/** A fixed list of encryption script resources. */
- private final Map encryptionScriptResources = Map.of("caesar-cipher",
- new ClassPathResource("scripts/encryption/caesar-cipher.js"), "one-time-pad",
- new ClassPathResource("scripts/encryption/one-time-pad.js"), "basic(none)",
- new ClassPathResource("scripts/encryption/basic.js"), "block-cipher",
- new ClassPathResource("scripts/encryption/block-cipher.js"), "block-cipher-chaining (Experimental)",
- new ClassPathResource("scripts/encryption/block-cipher-chaining.js"), "block-cipher-counter (Experimental)",
+ private final Map encryptionScriptResources = Map.of("(a) caesar-cipher",
+ new ClassPathResource("scripts/encryption/caesar-cipher.js"), "(c) one-time-pad",
+ new ClassPathResource("scripts/encryption/one-time-pad.js"), "(z) basic (none)",
+ new ClassPathResource("scripts/encryption/basic.js"), "(b) block-cipher",
+ new ClassPathResource("scripts/encryption/block-cipher.js"), "(z) block-cipher-chaining (Experimental)",
+ new ClassPathResource("scripts/encryption/block-cipher-chaining.js"), "(z) block-cipher-counter (Experimental)",
new ClassPathResource("scripts/encryption/block-cipher-counter.js"));
/**
@@ -65,11 +67,12 @@ public class EncryptionController {
public EncryptionController() {
// Load the scripts
- encryptionScripts = new HashMap<>(encryptionScriptResources.size());
+ encryptionScripts = new TreeMap<>();
for (final Map.Entry resource : encryptionScriptResources.entrySet()) {
final String resourceAsScript = ScriptHelper.loadScriptResourceToString(resource.getValue());
encryptionScripts.put(resource.getKey(), resourceAsScript);
}
+
}
/**
diff --git a/src/main/resources/scripts/encryption/block-cipher-chaining.js b/src/main/resources/scripts/encryption/block-cipher-chaining.js
index 63d7870..4dc4ad1 100644
--- a/src/main/resources/scripts/encryption/block-cipher-chaining.js
+++ b/src/main/resources/scripts/encryption/block-cipher-chaining.js
@@ -9,8 +9,8 @@ var cipherTextAsBytes = function encrypt(messageAsBytes, keyAsBytes) {
}
// 8 bit keys, so fix the block to 8 bits or 1 byte, so byte for byte
var blockSize = 1;
- // IV is a byte between 0 and 255 (00000000 and 11111111). The IV MUST normally
- // Change for each enc operation, so this is flawed.
+ // Here, the IV is a byte between 0 and 255 (00000000 and 11111111). The IV MUST normally
+ // be random, and change for each enc operation, so this is flawed.
var iv = 100;
for (var i = 0; i < messageAsBytes.length; i = i + blockSize) {
if (i == 0){
diff --git a/src/main/resources/scripts/encryption/block-cipher.js b/src/main/resources/scripts/encryption/block-cipher.js
index 9890b25..268e3be 100644
--- a/src/main/resources/scripts/encryption/block-cipher.js
+++ b/src/main/resources/scripts/encryption/block-cipher.js
@@ -6,8 +6,7 @@ var cipherTextAsBytes = function encrypt(messageAsBytes, keyAsBytes){
for (var i=0; i 1) {
print("Caesar cipher key should be 1 byte");
diff --git a/src/main/resources/templates/enc.html b/src/main/resources/templates/enc.html
index 5977e62..540e622 100644
--- a/src/main/resources/templates/enc.html
+++ b/src/main/resources/templates/enc.html
@@ -18,9 +18,11 @@ Shall we play more games?
1
-
+
Note, these algorithms are for demonstration only! they are not usable encryption
+ schemes.
JavaScript Encryption function. Must return a byte array.
+