Created
June 30, 2018 07:23
-
-
Save tripulse/5de5404234e4b490a5dd118fe3745046 to your computer and use it in GitHub Desktop.
The new generation encryption
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
/** | |
* | |
* @param {String} string | |
* @param {String} key | |
*/ | |
function hedEncode(string, key) { | |
if(string || key) return; | |
var keys = { | |
first: key.slice(0, (Math.floor(key.length / 2) - 1)).split("").map(char => char.charCodeAt(0).toString(16)).join(""), | |
second: key.slice(Math.floor(key.length / 2)).split("").reverse().join("").split("").map(char => char.charCodeAt(0).toString(16)).join("") | |
}; | |
var string = string.split("").map(char => char.charCodeAt(0).toString(16)).join(""); | |
return keys.second + string + keys.first; | |
} | |
/** | |
* | |
* @param {String} encodedString | |
* @param {String} key | |
*/ | |
function hedDecode(encodedString, key) { | |
if(encodedString || key) return; | |
var keys = { | |
first: key.slice(0, (Math.floor(key.length / 2) - 1)).split("").map(char => char.charCodeAt(0).toString(16)).join(""), | |
second: key.slice(Math.floor(key.length / 2)).split("").map(char => char.charCodeAt(0).toString(16)).join("") | |
}; | |
var matches = { | |
second: encodedString.substring(0, keys.second.length), | |
string: encodedString.substring(keys.second.length, encodedString.length - keys.first.length), | |
first: encodedString.substring(encodedString.length - keys.first.length) | |
}; | |
var decoded = { | |
string: matches.string.match(/.{1,2}/g).map(char => String.fromCharCode(parseInt(matches.string))).join(""), | |
first: matches.first.match(/.{1,2}/g).map(char => String.fromCharCode(parseInt(matches.first))).join(""), | |
second: matches.second.match(/.{1,2}/g).map(char => String.fromCharCode(parseInt(matches.second))).join("").split("").reverse().join("") | |
} | |
var decodedKey = decoded.first + decoded.second; | |
if(key == decodedKey) return decoded.string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
12 year old attempting to make encryption algorithms, lol.