forked from CrypTools/ROT13Cipher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt.js
More file actions
28 lines (22 loc) · 695 Bytes
/
decrypt.js
File metadata and controls
28 lines (22 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* ==========================================================================
*
* Use:
* 'Uryyb Jbeyq!'.encrypt()
* => 'Hello World!'
*
* ========================================================================== */
String.prototype.decrypt = function() {
let output = ""
let alphabet = {}
const chr = x => String.fromCharCode(x)
for (let i = 0; i < 26; i++) {
alphabet[chr(65 + i)] = chr(65 + (i + 13) % 26)
alphabet[chr(97 + i)] = chr(97 + (i + 13) % 26)
}
for (let char of this) {
if (char in alphabet) output += alphabet[char]
else output += char
}
return output
}
module.exports = text => text.decrypt();