<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
  </head>
  <body>
    <input type="text" id="textInput" />

    <button onclick="run()">Run</button>
    <p id="outputText"></p>

    <script>
      const text =
        "Ub1Nnr2hASYGrwzBG7O6aucdzY+90GurTInEEY7T/u4OVqbKBnISBndbXP/tldlHdACBn1Jhu3wzed3mxUxasfbZa4YWafTxjqZ5DoHQZEJesKqWfXPi55nWn48iGoSWWWr4zgXyXL4qnvKKgzud0ddCG1pCJfDXiqf1oPhZqSDulfz3sp7X5gE37Eni4NVZ";

      const predefined = new Uint8Array([
        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
        0x0f,
      ]);

      async function run() {
        const textInput = document.getElementById("textInput").value;

        const constData = new Uint8Array(
          atob(text)
            .split("")
            .map((c) => c.charCodeAt(0))
        );

        const textInputBytes = new TextEncoder().encode(textInput);

        const key = await crypto.subtle.importKey(
          "raw",
          textInputBytes,
          { name: "AES-GCM" },
          false,
          ["decrypt"]
        );

        const decryptedData = await crypto.subtle.decrypt(
          { name: "AES-GCM", iv: predefined },
          key,
          constData
        );

        const decoder = new TextDecoder();
        const outputText = decoder.decode(decryptedData);
        document.getElementById("outputText").innerText = outputText;
      }

      document.getElementById("outputText").addEventListener("click", function () {
        const text = document.getElementById("outputText").innerText;

        navigator.clipboard.writeText(text).then(function () {
          alert("Text copied to clipboard!");
        });
      });
    </script>
  </body>
</html>
