Skip to content

Instantly share code, notes, and snippets.

@doox911
Created September 23, 2021 07:27

Revisions

  1. doox911 created this gist Sep 23, 2021.
    66 changes: 66 additions & 0 deletions rot_13.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    function rot13(message) {
    const alphabet = {
    a: 'n',
    b: 'o',
    c: 'p',
    d: 'q',
    e: 'r',
    f: 's',
    g: 't',
    h: 'u',
    i: 'v',
    j: 'w',
    k: 'x',
    l: 'y',
    m: 'z',
    n: 'a',
    o: 'b',
    p: 'c',
    q: 'd',
    r: 'e',
    s: 'f',
    t: 'g',
    u: 'h',
    v: 'i',
    w: 'j',
    x: 'k',
    y: 'l',
    z: 'm',
    A: 'N',
    B: 'O',
    C: 'P',
    D: 'Q',
    E: 'R',
    F: 'S',
    G: 'T',
    H: 'U',
    I: 'V',
    J: 'W',
    K: 'X',
    L: 'Y',
    M: 'Z',
    N: 'A',
    O: 'B',
    P: 'C',
    Q: 'D',
    R: 'E',
    S: 'F',
    T: 'G',
    U: 'H',
    V: 'I',
    W: 'J',
    X: 'K',
    Y: 'L',
    Z: 'M',
    };

    let str = '';

    for(let i = 0; i< message.length; i++) {
    alphabet[message[i]]
    ? str += alphabet[message[i]]
    : str += message[i]
    }

    return str;
    }