diff --git a/Ciphers/Atbash.js b/Ciphers/Atbash.js new file mode 100644 index 0000000000..5f43737497 --- /dev/null +++ b/Ciphers/Atbash.js @@ -0,0 +1,29 @@ +/* +The Atbash cipher is a particular type of monoalphabetic cipher +formed by taking the alphabet and mapping it to its reverse, +so that the first letter becomes the last letter, +the second letter becomes the second to last letter, and so on. +*/ + +/** + * Decrypt a Atbash cipher + * @param {String} str - string to be decrypted/encrypt + * @return {String} decrypted/encrypted string + */ +function Atbash (message) { + let decodedString = '' + for (let i = 0; i < message.length; i++) { + if (/[^a-zA-Z]/.test(message[i])) { + decodedString += message[i] + } else if (message[i] === message[i].toUpperCase()) { + decodedString += String.fromCharCode(90 + 65 - message.charCodeAt(i)) + } else { + decodedString += String.fromCharCode(122 + 97 - message.charCodeAt(i)) + } + } + return decodedString +} +// Atbash Example +const encryptedString = 'HELLO WORLD' +const decryptedString = Atbash(encryptedString) +console.log(decryptedString) // SVOOL DLIOW pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy