File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Transcipher a ROT13 cipher
3+ * @param {String } text - string to be encrypted
4+ * @return {String } - decrypted string
5+ */
6+ const transcipher = ( text ) => {
7+ const originalCharacterList = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
8+ const toBeMappedCharaterList = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'
9+ const index = x => originalCharacterList . indexOf ( x )
10+ const replace = x => index ( x ) > - 1 ? toBeMappedCharaterList [ index ( x ) ] : x
11+ return text . split ( '' ) . map ( replace ) . join ( '' )
12+ }
13+
14+ ( ( ) => {
15+ const messageToBeEncrypted = 'The quick brown fox jumps over the lazy dog'
16+ console . log ( `Original Text = "${ messageToBeEncrypted } "` )
17+ const rot13CipheredText = transcipher ( messageToBeEncrypted )
18+ console . log ( `Ciphered Text = "${ rot13CipheredText } "` )
19+ const rot13DecipheredText = transcipher ( rot13CipheredText )
20+ console . log ( `Deciphered Text = "${ rot13DecipheredText } "` )
21+ } ) ( )
You can’t perform that action at this time.
0 commit comments