Skip to content

Instantly share code, notes, and snippets.

@nautical
Created January 10, 2018 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nautical/f4af58a9540b94e4648852152044d968 to your computer and use it in GitHub Desktop.
Save nautical/f4af58a9540b94e4648852152044d968 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Hiding Text</title>
</head>
<body>
<input type="text" placeholder="Normal Text" id="textval">
<input type="text" placeholder="Key" id="key">
<button id="convert" onclick="convert();">Convert</button>
<br>
<input type="text" placeholder="Shared Text" id="textshared">
<input type="text" placeholder="Recovered Key" id="recoveredKey">
<button id="recover" onclick="recover();">Recover</button>
</body>
<script type="text/javascript">
var new_1 = '\uFEFF';
var new_0 = '\u200E';
var new_space = '\u200F';
var marker = new_1+new_0+new_1+new_0+new_1+new_0+new_1+new_0
function encode(string) {
return string.split('').map(function (char) {
return char.charCodeAt(0).toString(2);
}).join(' ').replace(/ /g , new_space).replace(/0/g , new_0).replace(/1/g , new_1);
}
function decode(string){
var _bin = string.split(new_space).join(" ").split(new_0).join("0").split(new_1).join("1");
return _bin.split(' ').map(function (val){
return String.fromCharCode(parseInt(val, 2));
}).join("");
}
function hideit(string,key){
return string + marker + encode(key) + marker;
}
function findit(string){
var _key = string.split(marker)[1];
return decode(_key);
}
function convert(){
var key = document.getElementById("key").value;
var text = document.getElementById("textval").value;
document.getElementById("textval").value = hideit(text,key);
alert("done");
}
function recover(){
var text = document.getElementById("textshared").value;
document.getElementById("recoveredKey").value = findit(text);
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment