Skip to content

Commit 23d1bfd

Browse files
authored
Update AtBash.js
1 parent 4f19129 commit 23d1bfd

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

Ciphers/AtBash.js

+22-25
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
function enAtbash(mensage) {
2-
3-
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
4-
var tebahpla = "ZYXWVUTSRQPONMLKJIHGFEDCBA";
5-
var alphabet1 = "abcdefghijklmnopqrstuvwxyz";
6-
var tebahpla1 = "zyxwvutsrqponmlkjihgfedcba";
7-
var decoded_string = "";
8-
9-
for (var i = 0; i < mensage.length; i++) {
10-
var coded_letra = mensage.charAt(i);
11-
12-
if (/[^a-zA-Z]/.test(mensage[i])) {
13-
decoded_string = decoded_string+mensage[i];
14-
}
15-
else if (mensage[i] === mensage[i].toUpperCase()) {
16-
var letraPosMayus = alphabet.indexOf(coded_letra);
17-
var tebLetraPosMayus = tebahpla.charAt(letraPosMayus);
18-
decoded_string = decoded_string+tebLetraPosMayus;
19-
} else {
20-
var letraPosMinus1 = alphabet1.indexOf(coded_letra);
21-
var tebLetraPosMinus1 = tebahpla1.charAt(letraPosMinus1);
22-
decoded_string = decoded_string + tebLetraPosMinus1;
23-
}
1+
const enAtbash = (message) => {
2+
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
3+
const tebahpla = 'ZYXWVUTSRQPONMLKJIHGFEDCBA'
4+
const alphabet1 = 'abcdefghijklmnopqrstuvwxyz'
5+
const tebahpla1 = 'zyxwvutsrqponmlkjihgfedcba'
6+
let decodedString = ''
247

8+
for (let i = 0; i < message.length; i++) {
9+
const codedLetra = message.charAt(i)
10+
if (/[^a-zA-Z]/.test(message[i])) {
11+
decodedString = decodedString + message[i]
12+
} else if (message[i] === message[i].toUpperCase()) {
13+
const letraPosMayus = alphabet.indexOf(codedLetra)
14+
const tebLetraPosMayus = tebahpla.charAt(letraPosMayus)
15+
decodedString = decodedString + tebLetraPosMayus
16+
} else {
17+
const letraPosMinus1 = alphabet1.indexOf(codedLetra)
18+
const tebLetraPosMinus1 = tebahpla1.charAt(letraPosMinus1)
19+
decodedString = decodedString + tebLetraPosMinus1
2520
}
26-
return decoded_string;
21+
}
22+
return decodedString
2723
}
2824

29-
document.write(enAtbash("Hello World!"));
25+
// testing code
26+
console.log(enAtbash('Hello World!'))

0 commit comments

Comments
 (0)