Skip to content

Commit 985e193

Browse files
authored
Update Atbash.js
1 parent 5023cdd commit 985e193

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

Ciphers/Atbash.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
/*
2-
The Atbash cipher is a particular type of monoalphabetic cipher
3-
formed by taking the alphabet and mapping it to its reverse,
4-
so that the first letter becomes the last letter,
5-
the second letter becomes the second to last letter, and so on.
2+
The Atbash cipher is a particular type of monoalphabetic cipher
3+
formed by taking the alphabet and mapping it to its reverse,
4+
so that the first letter becomes the last letter,
5+
the second letter becomes the second to last letter, and so on.
66
*/
77

88
/**
99
* Decrypt a Atbash cipher
1010
* @param {String} str - string to be decrypted/encrypt
1111
* @return {String} decrypted/encrypted string
1212
*/
13-
function Atbash(message) {
14-
let decodedString = ''
15-
for(let i = 0; i < message.length; i++) {
16-
if(/[^a-zA-Z]/.test(message[i])) {
17-
decodedString += message[i]
18-
} else if(message[i] === message[i].toUpperCase()) {
19-
decodedString += String.fromCharCode(90 + 65 - message.charCodeAt(i))
20-
} else {
21-
decodedString += String.fromCharCode(122 + 97 - message.charCodeAt(i))
22-
}
23-
}
24-
return decodedString
13+
function Atbash (message) {
14+
let decodedString = ''
15+
for (let i = 0; i < message.length; i++) {
16+
if (/[^a-zA-Z]/.test(message[i])) {
17+
decodedString += message[i]
18+
} else if (message[i] === message[i].toUpperCase()) {
19+
decodedString += String.fromCharCode(90 + 65 - message.charCodeAt(i))
20+
} else {
21+
decodedString += String.fromCharCode(122 + 97 - message.charCodeAt(i))
22+
}
23+
}
24+
return decodedString
2525
}
2626
// Atbash Example
2727
const encryptedString = 'HELLO WORLD'

0 commit comments

Comments
 (0)
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