aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-10-30 11:15:06 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-10-30 11:15:06 +0100
commitb0723c4bc8e7b23f8534cc209ab0a20ddcc257ed (patch)
treee2d1e5858290b3b2832dcefe7f8b5666fb4d0972 /utils
parent8709793284d04e31822688e83abc393dbfe13b26 (diff)
downloadcacharle.xyz-b0723c4bc8e7b23f8534cc209ab0a20ddcc257ed.tar.gz
cacharle.xyz-b0723c4bc8e7b23f8534cc209ab0a20ddcc257ed.tar.bz2
cacharle.xyz-b0723c4bc8e7b23f8534cc209ab0a20ddcc257ed.zip
Added rot13 util
Diffstat (limited to 'utils')
-rw-r--r--utils/rot13/index.html35
-rw-r--r--utils/rot13/script.js31
2 files changed, 66 insertions, 0 deletions
diff --git a/utils/rot13/index.html b/utils/rot13/index.html
new file mode 100644
index 0000000..525e14f
--- /dev/null
+++ b/utils/rot13/index.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+
+<html>
+ <head>
+ <title>cacharle - rot13</title>
+ <link rel="stylesheet" type="text/css" href="../../style.css"/>
+ <meta charset="utf-8"/>
+ <link rel="icon" type="image/png" href="../../favicon.png" />
+ <style>
+ textarea {
+ resize: none;
+ }
+ input {
+ width: 50%;
+ }
+ </style>
+ </head>
+
+ <body><div id="page-wrapper">
+ <h1>rot13</h1>
+
+ <p>Implementation of the <a href="https://en.wikipedia.org/wiki/ROT13">rot13</a> encryption</p>
+
+ <div>Shift size: <span id="rot13-shift-output"></span></div>
+ <input type="range" min=0 max=26 value=13 id="rot13-shift"/>
+
+ <h3>Input</h3>
+ <textarea cols=120 rows=10 id="rot13-input">rotate me!</textarea>
+
+ <h3>Output</h3>
+ <textarea cols=120 rows=10 id="rot13-output"></textarea>
+
+ </div></body>
+ <script src="script.js" type="text/javascript"></script>
+</html>
diff --git a/utils/rot13/script.js b/utils/rot13/script.js
new file mode 100644
index 0000000..efa408b
--- /dev/null
+++ b/utils/rot13/script.js
@@ -0,0 +1,31 @@
+input = document.getElementById("rot13-input")
+output = document.getElementById("rot13-output")
+shift_range = document.getElementById("rot13-shift")
+shift_output = document.getElementById("rot13-shift-output")
+
+const letters_low = [
+ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
+ "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"
+]
+
+const letters_up = letters_low.map(c => c.toUpperCase())
+
+function rotate(text, shift) {
+ return text.split("").map(c => {
+ if (/[a-zA-Z]/.test(c)) {
+ letters = /[a-z]/.test(c) ? letters_low : letters_up
+ return letters[(letters.indexOf(c) + shift) % 26]
+ }
+ return c
+ }).join("")
+}
+
+function update() {
+ output.value = rotate(input.value, Number(shift_range.value))
+ shift_output.textContent = shift_range.value
+}
+
+input.addEventListener("keyup", update)
+shift_range.addEventListener("input", update)
+
+update()