Last active
December 8, 2021 07:52
-
-
Save r74tech/f6e080f1fa6368a92e57b8a725bad61a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let encryptee = "日本語English" | |
//Rot13 Encode | |
function encode(encryptee) { | |
return encryptee.replace(/[A-Z]/g, function(c) { | |
var s = c.charCodeAt(0); | |
return String.fromCharCode(s < 78 ? s + 13 : s - 13); | |
}).replace(/[a-z]/g, function(c) { | |
var s = c.charCodeAt(0); | |
return String.fromCharCode(s < 110 ? s + 13 : s - 13); | |
}).replace(/[ぁ-ゖ]/g, function(c) { | |
var s = c.charCodeAt(0); | |
return String.fromCharCode(s < 12366 ? s + 73 : s - 13); | |
}).replace(/[ァ-ヶ]/g, function(c) { | |
var s = c.charCodeAt(0); | |
return String.fromCharCode(s < 12463 ? s + 73 : s - 13); | |
}).replace(/[一-龠]/g, function(c) { | |
var s = c.charCodeAt(0); | |
return String.fromCharCode(s < 19982 ? s + 20217 : s - 13); | |
}); | |
} | |
// decode | |
function decode(decryptee) { | |
return decryptee.replace(/[a-zA-Z]/g, function (c) { | |
var s = c.charCodeAt(0); | |
return String.fromCharCode((s <= 90 ? 90 : 122) >= (s + 13) ? s + 13 : s - 13); | |
}).replace(/[ぁ-ゖ]/g, function (c) { | |
var s = c.charCodeAt(0); | |
return String.fromCharCode(s <= 12425 ? s + 13 : s - 73); | |
}).replace(/[ァ-ヶ]/g, function (c) { | |
var s = c.charCodeAt(0); | |
return String.fromCharCode(s <= 12521 ? s + 13 : s - 73); | |
}).replace(/[一-龠]/g, function (c) { | |
var s = c.charCodeAt(0); | |
return String.fromCharCode(s <= 40184 ? s + 13 : s - 20217); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment