From b0723c4bc8e7b23f8534cc209ab0a20ddcc257ed Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Fri, 30 Oct 2020 11:15:06 +0100 Subject: Added rot13 util --- generate-blog | 8 ++++++++ index.html | 6 ++++++ index.template.html | 5 +++++ utils/rot13/index.html | 35 +++++++++++++++++++++++++++++++++++ utils/rot13/script.js | 31 +++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+) create mode 100644 utils/rot13/index.html create mode 100644 utils/rot13/script.js diff --git a/generate-blog b/generate-blog index 6d3add1..6aaa1be 100755 --- a/generate-blog +++ b/generate-blog @@ -27,3 +27,11 @@ do echo "Generated article at $article_dst_path" done + +for util_path in utils/* +do + title=$(basename "$util_path") + util_dst_path="$util_path/index.html" + sed -i'' "// a\ +
  • $title
  • " index.html +done diff --git a/index.html b/index.html index a42a3ca..08d8299 100644 --- a/index.html +++ b/index.html @@ -22,6 +22,12 @@
  • How to make your own git server/website
  • +

    Utils

    + +

    Links

  • github
  • git server
  • diff --git a/index.template.html b/index.template.html index 0b1e133..375652f 100644 --- a/index.template.html +++ b/index.template.html @@ -21,6 +21,11 @@ +

    Utils

    + +

    Links

  • github
  • git server
  • 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 @@ + + + + + cacharle - rot13 + + + + + + +
    +

    rot13

    + +

    Implementation of the rot13 encryption

    + +
    Shift size:
    + + +

    Input

    + + +

    Output

    + + +
    + + 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() -- cgit