crypt beta
This commit is contained in:
parent
70b64b2251
commit
bd5a51bccb
2 changed files with 87 additions and 0 deletions
62
site/bin/crypt.js
Normal file
62
site/bin/crypt.js
Normal file
|
@ -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);
|
||||||
|
}
|
25
site/bin/index.html
Normal file
25
site/bin/index.html
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>/</title>
|
||||||
|
<link rel="stylesheet" href="/style.css" />
|
||||||
|
<script src="/script.js" defer></script>
|
||||||
|
</head>
|
||||||
|
<body id="body">
|
||||||
|
<div class="border">
|
||||||
|
<div class="column">
|
||||||
|
<div class="stretch row">
|
||||||
|
Dario48's website
|
||||||
|
<div style="aspect-ratio: 1 / 1">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onclick="document.getElementById('body').remove();"
|
||||||
|
>
|
||||||
|
X
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue