Atbash Cipher

JavaScript Examples

Below are some examples of how to implement the Atbash Cipher in JavaScript.

JavaScript Example


function atbashCipher(text) {
    return text.split('').map(char => {
        if (/[a-zA-Z]/.test(char)) {
            const base = char <= 'Z' ? 65 : 97;
            return String.fromCharCode(25 - (char.charCodeAt(0) - base) + base);
        }
        return char;
    }).join('');
}

const plaintext = "HELLO";
const ciphertext = atbashCipher(plaintext);
console.log(`Plaintext: ${plaintext}`);
console.log(`Ciphertext: ${ciphertext}`);
            

Detailed Tutorials

Check out our detailed tutorials on how to implement the Atbash Cipher in different programming languages.