Skip to content

Instantly share code, notes, and snippets.

@rjames86
Created December 24, 2019 21:35
Show Gist options
  • Select an option

  • Save rjames86/893a3bf25c407e6835a57a228ecdecc3 to your computer and use it in GitHub Desktop.

Select an option

Save rjames86/893a3bf25c407e6835a57a228ecdecc3 to your computer and use it in GitHub Desktop.

Revisions

  1. rjames86 renamed this gist Dec 24, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. rjames86 created this gist Dec 24, 2019.
    55 changes: 55 additions & 0 deletions ROT13 iOS shortcut
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    function getMeta(metaName) {
    const metas = document.getElementsByTagName('meta');

    for (let i = 0; i < metas.length; i++) {
    if (metas[i].getAttribute('property') === metaName) {
    return metas[i].getAttribute('content');
    }
    }

    return '';
    }

    const description = getMeta('og:description');

    // [97, 122]
    const lowerCase = [];
    // [65, 90]
    const upperCase = [];


    for (let i = 97; i <= 122; i++) {
    lowerCase.push(i);
    }

    for (let i = 65; i <= 90; i++) {
    upperCase.push(i);
    }

    const getRot13Val = asciiVal => {
    let newVal;
    if (upperCase.includes(asciiVal)) {
    const newIndex = (upperCase.indexOf(asciiVal) + 13) % upperCase.length;
    newVal = upperCase[newIndex];
    } else if (lowerCase.includes(asciiVal)) {
    const newIndex = (lowerCase.indexOf(asciiVal) + 13) % lowerCase.length;
    newVal = lowerCase[newIndex];
    } else {
    newVal = asciiVal;
    }
    return String.fromCharCode(newVal);
    }

    const convertToRot13 = inputString => {
    let outputString = '';
    for (const s of inputString) {
    const asciiVal = s.charCodeAt(0);
    outputString += getRot13Val(asciiVal);
    }
    return outputString;
    }

    const converted = convertToRot13(description)

    // Call completion to finish
    completion(converted);