Skip to content

Instantly share code, notes, and snippets.

@r74tech
Last active December 8, 2021 07:52
Show Gist options
  • Save r74tech/f6e080f1fa6368a92e57b8a725bad61a to your computer and use it in GitHub Desktop.
Save r74tech/f6e080f1fa6368a92e57b8a725bad61a to your computer and use it in GitHub Desktop.
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