diff --git a/site/bin/crypt.js b/site/bin/crypt.js new file mode 100644 index 0000000..0c446ae --- /dev/null +++ b/site/bin/crypt.js @@ -0,0 +1,62 @@ +let encrypt = function() { + key = document.getElementById("key").value; + string = document.getElementById("plaintext").value; + if (typeof key !== "number") { + throw new Error("Key must be a number"); + } + let resultArray = [] + for (let i = 0; i < string.length; i++) { + if (string.charCodeAt(i) < 97 || string.charCodeAt(i) > 122) { + resultArray.push(string[i]); + continue; + } + let code = string.charCodeAt(i) + key; + while (code > 122) { + code = (code - 122) + 96; + } + resultArray.push(String.fromCharCode(code)) + } + + document.getElementById("encoded").value = resultArray.join(" "); +} + +let bruteforce = function() { + let know_element = document.getElementById("know_element").value; + let string = document.getElementById("encoded").value; + if (typeof key !== "number") { + throw new Error("Key must be a number"); + } + + let resultArray = [] + let workingKeys = [] + + for (key = 0; key < 26; key++) { + resultArray = decrypt(key, string); + if (resultArray.includes(know_element)) { + workingKeys.push(key); + } + } + document.getElementById("key").value = workingKeys.join(","); +} + +let decrypt = function(key, string) { + resultArray = [] + for (let i = 0; i < string.length; i++) { + if (string.charCodeAt(i) < 97 || string.charCodeAt(i) > 122) { + resultArray.push(string[i]); + continue; + } + let code = string.charCodeAt(i) - key; + while (code - 96) { + code = (code + 122) - 96; + } + resultArray.push(String.fromCharCode(code)) + } + return resultArray.join(" "); +} + +let manual_decrypt = function() { + let key = document.getElementById("key").value; + let string = document.getElementById("encoded").value; + document.getElementById("plaintext").value = decrypt(key, string); +} diff --git a/site/bin/index.html b/site/bin/index.html new file mode 100644 index 0000000..815dfad --- /dev/null +++ b/site/bin/index.html @@ -0,0 +1,25 @@ + + + + / + + + + +
+
+
+ Dario48's website +
+ +
+
+
+
+ +