hometools

tools

This is where I'll be moving the tools from tools.alanwsmith.com

Base64
To Base64
From Base64
Dedupe Lines
Encryption

These are the tools I use to obfuscate files on the site to make it harder for bots to slurp up my content. They are not designed for authentication/authorization. They are not secure.

Encryptor CLI

~/workshop/al9000.com/content/tools/encryption/apps/cli-encryptor/release/aarch64-apple-darwin/encryptor

Usage:

encryptor INPUT_PATH OUTPUT_PATH

WASM Decryptor

Text File
import init, {
  decryptBytes,
} from "/tools/encryption/apps/wasm-decryptor/pkg/wasm_decryptor.js";

async function decryptURL(url) {
  const response = await fetch(url);
  try {
    if (response.ok) {
      const blob = await response.blob();
      const buffer = await blob.arrayBuffer();
      const encryptedBytes = new Uint8Array(buffer);
      const decryptedBytes = await decryptBytes(encryptedBytes);
      if (decryptedBytes.length === 0) {
        console.error("Decrypion failed. Check credentails");
        return undefined;
      }
      return decryptedBytes.buffer;
    } else {
      console.error(response);
      return undefined;
    }
  } catch (error) {
    console.error(error);
    return undefined;
  }
}

async function decryptTextFile(url) {
  const buffer = await decryptURL(url);
  if (!buffer) {
    return undefined;
  }
  const text = new TextDecoder().decode(buffer);
  return text;
}

async function main() {
  await init();
  const url = "/tools/encryption/apps/cli-encryptor/samples/encrypted.txt.bin";
  const text = await decryptTextFile(url);
  console.log(text);
}

main();
Single Video File
import decryptInit, {
  decryptBytes,
} from "/tools/encryption/apps/wasm-decryptor/pkg/wasm_decryptor.js";

async function decryptURL(url) {
  const response = await fetch(url);
  try {
    if (response.ok) {
      const blob = await response.blob();
      const buffer = await blob.arrayBuffer();
      const encryptedBytes = new Uint8Array(buffer);
      const decryptedBytes = await decryptBytes(encryptedBytes);
      if (decryptedBytes.length === 0) {
        console.error("Decrypion failed. Check credentails");
        return undefined;
      }
      return decryptedBytes.buffer;
    } else {
      console.error(response);
      return undefined;
    }
  } catch (error) {
    console.error(error);
    return undefined;
  }
}

async function decryptWebm(url) {
  const buffer = await decryptURL(url);
  if (!buffer) {
    return undefined;
  }
  const blob = new Blob([buffer], { type: "video/webm" });
  return URL.createObjectURL(blob);
}

async function main() {
  await decryptInit();
  const videoEl = document.querySelector("#singleDecryptedVideo");
  const videoURL = await decryptWebm(
    "/tools/encryption/apps/cli-encryptor/samples/video.webm.bin",
  );
  videoEl.src = videoURL;
}

main();
Split Video File
import init, {
  decryptBytes,
} from "/tools/encryption/apps/wasm-decryptor/pkg/wasm_decryptor.js";

async function decryptURL(url) {
  const response = await fetch(url);
  try {
    if (response.ok) {
      const blob = await response.blob();
      const buffer = await blob.arrayBuffer();
      const encryptedBytes = new Uint8Array(buffer);
      const decryptedBytes = await decryptBytes(encryptedBytes);
      if (decryptedBytes.length === 0) {
        console.error("Decrypion failed. Check credentails");
        return undefined;
      }
      return decryptedBytes.buffer;
    } else {
      console.error(response);
      return undefined;
    }
  } catch (error) {
    console.error(error);
    return undefined;
  }
}

const videos = {};

async function loadSplitEncryptedVideo(el, baseURL) {
  const uuid = self.crypto.randomUUID();
  const detailsURL = `${baseURL}/details.json`;
  const details = await fetch(detailsURL);
  if (details.ok) {
    try {
      const json = await details.json();
      el.addEventListener("canplaythrough", (event) => {
        // TODO: Set up to check against the UUID so
        // that multiple videos can be on the
        // page at once.
        console.log("Got canplaythrough.");
      });
      const mediaSource = new MediaSource();
      if (mediaSource) {
        videos[uuid] = {
          baseURL: baseURL,
          mediaSource: mediaSource,
          currentSegment: 0,
          totalSegments: json.fileCount,
        };
        el.src = URL.createObjectURL(mediaSource);
        mediaSource.addEventListener("sourceopen", async () => {
          videos[uuid].sourceBuffer = mediaSource.addSourceBuffer(
            `video/webm; codecs="vp9, opus"`,
          );
          videos[uuid].sourceBuffer.addEventListener(
            "updateend",
            async (event) => {
              if (videos[uuid].mediaSource.readyState === "open") {
                loadSegment(uuid);
              }
            },
          );
          loadSegment(uuid);
        });
      } else {
        // Presenter error message to UI here.
        console.error("MediaSource not avaialbe on this browser");
      }
    } catch (error) {
      console.error(error);
    }
  } else {
    console.error(`Could not load: ${detailsURL}`);
  }
}

async function loadSegment(uuid) {
  if (videos[uuid].currentSegment < videos[uuid].totalSegments) {
    try {
      const url = `${videos[uuid].baseURL}/${videos[uuid].currentSegment}.bin`;
      console.log(`processing segment: ${videos[uuid].currentSegment}`);
      const buffer = await decryptURL(url);
      if (buffer.length === 0) {
        console.error("Could not decrypt file. Check password");
        videos[uuid].mediaSource.endOfStream("network");
      } else {
        // const buffer = await response.arrayBuffer();
        // const bytes = new Uint8Array(buffer);
        // const responseBytes = await decrypt_file(bytes, "key");
        videos[uuid].sourceBuffer.appendBuffer(buffer);
        videos[uuid].currentSegment++;
      }
    } catch (error) {
      console.error(error);
      videos[uuid].mediaSource.endOfStream("network");
    }
  } else {
    videos[uuid].mediaSource.endOfStream();
  }
}

async function main() {
  await init();
  const videoEl = document.querySelector("#splitDecryptedVideo");
  const videoRootURL = "/tools/encryption/apps/wasm-decryptor/samples/video";
  loadSplitEncryptedVideo(videoEl, videoRootURL);
}

main();
HTML Escaper
KSUID
Lines to Line Items
Post ID
Ratio Converter
Formula for Width: STARTING_WIDTH * OUTPUT_HEIGHT / STARTING_HEIGHT
Formula for Height: STARTING_HEIGHT * OUTPUT_WIDTH / STARTING_WIDTH
sed

The latest sed command I'm using:

#!/bin/bash

DIR=~/workshop/al9000.com/content/tools

find "$DIR" \
  -type f \
  \( \
    -iname "*.html" \
    -o -iname "*.js" \
    -o -iname "*.txt" \
    -o -iname "*.json" \
  \) \
  -print0 \
| xargs -0 sed -E -i "" \
's!tools/tools!tools!g'

# Reminder: -E is for extended RegEx
# Reminder: -i is for editing the file in place
Unique Words
URLs to Links (sorted)
UUID Generator title = "UUID Generator"
YouTube Links to Neopolitan