File tree 1 file changed +12
-17
lines changed
1 file changed +12
-17
lines changed Original file line number Diff line number Diff line change @@ -5,30 +5,25 @@ so that the first letter becomes the last letter,
5
5
the second letter becomes the second to last letter, and so on.
6
6
*/
7
7
8
-
9
8
/**
10
9
* Decrypt a Atbash cipher
11
10
* @param {String } str - string to be decrypted/encrypt
12
11
* @return {String } decrypted/encrypted string
13
12
*/
14
-
15
- const Atbash = ( message ) => {
16
- let decodedString = ''
17
-
18
- for ( let i = 0 ; i < message . length ; i ++ ) {
19
- if ( / [ ^ a - z A - Z ] / . test ( message [ i ] ) ) {
20
- decodedString += message [ i ]
21
- } else if ( message [ i ] === message [ i ] . toUpperCase ( ) ) {
22
- decodedString += String . fromCharCode ( 90 + 65 - message . charCodeAt ( i ) )
23
- } else {
24
- decodedString += String . fromCharCode ( 122 + 97 - message . charCodeAt ( i ) )
25
- }
26
- }
27
- return decodedString
13
+ function Atbash ( message ) {
14
+ let decodedString = ''
15
+ for ( let i = 0 ; i < message . length ; i ++ ) {
16
+ if ( / [ ^ a - z A - 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
28
25
}
29
-
30
26
// Atbash Example
31
27
const encryptedString = 'HELLO WORLD'
32
28
const decryptedString = Atbash ( encryptedString )
33
-
34
29
console . log ( decryptedString ) // SVOOL DLIOW
You can’t perform that action at this time.
0 commit comments