codeberg is different ig

This commit is contained in:
Dario48true 2025-02-14 09:25:03 +01:00
parent d801db3867
commit 6a8becba84
11 changed files with 7 additions and 15 deletions

42
bin/crypt.js Normal file
View file

@ -0,0 +1,42 @@
// Implement modulo by replacing the negative operand
// with an equivalent positive operand that has the same wrap-around effect
function mod(n, p) {
if (n < 0)
n = p - Math.abs(n) % p;
return n % p;
}
// Function will implement Caesar Cipher to
// encrypt / decrypt the msg by shifting the letters
// of the message acording to the key
function encrypt(msg, key) {
var encMsg = "";
key -= 0;
for (var i = 0; i < msg.length; i++) {
var code = msg.charCodeAt(i);
// Encrypt only letters in 'A' ... 'Z' interval
if (code >= 97 && code <= 97 + 26 - 1) {
code -= 97;
code = mod(code + key, 26);
code += 97;
}
if (code >= 65 && code <= 65 + 26 - 1) {
code -= 65;
code = mod(code + key, 26);
code += 65;
}
encMsg += String.fromCharCode(code);
}
return encMsg;
}
function decrypt(msg, key) {
return encrypt(msg, 26 - key);
}

53
bin/index.html Normal file
View file

@ -0,0 +1,53 @@
<!doctype html>
<html>
<head>
<title>/</title>
<link rel="stylesheet" href="/style.css" />
<script src="/disable_form.js" defer></script>
<script src="/bin/crypt.js"></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>
<form id="disable_enter">
<input
type="text"
value="Hello"
class="stretch"
id="plaintext"
/>
<input type="text" value="13" class="stretch" id="key" />
<button
type="button"
onclick="document.getElementById('encrypted').value = encrypt(document.getElementById('plaintext').value, document.getElementById('key').value)"
>
Encrypt
</button>
<button
type="button"
onclick="document.getElementById('plaintext').value = decrypt(document.getElementById('encrypted').value, document.getElementById('key').value)"
>
Decrypt
</button>
<input
type="text"
value="Uryyb"
class="stretch"
id="encrypted"
/>
</form>
</div>
</div>
</body>
</html>