I want to make new custom encryption engine with javascript, but i have a problem when i make a decryption function. In my decryption function I don't understand how to switch 3 characters to 1 character. In the decryption function section, 3 characters from the case I do not want are changing to the characters that are returned.
If you need my full code, i can share in here.
So please help me to solve this problem. Sorry for my bad English :)
<body>
<h3>Encrypt and Decrypt</h3>
<!-- Encrypt -->
<!-- <input placeholder="Ketikan sesuatu disini, pasti bisa:v" id="input"><br>
<button onclick="encrypt()">Encrypt</button> -->
<!-- Decrypt -->
<br><input placeholder="Ketikan sesuatu disini, pasti bisa:v" id="input2"><br>
<button onclick="decrypt()">Decrypt</button>
<!-- Result -->
<div id="result"></div>
<!-- Enginenya -->
<script>
function encrypt(){
var rawtext = document.getElementById("input").value;
var temptext = "";
for(i = 0; i < rawtext.length; i++){
temptext += enc(rawtext[i]);
}
document.getElementById("result").innerHTML = temptext;
}
function decrypt(){
var rawtext = document.getElementById("input2").value;
var temptext = "";
for(i = 0; i < rawtext.length; i++){
temptext += dec(rawtext[i]);
}
document.getElementById("result").innerHTML = temptext;
}
function enc(x){
switch(x){
case " " :
return " ";
break;
case "A" :
return "+/=";
break;
case "B" :
return "36=";
break;
}
}
function dec(x){
switch(x){
case "+/=" :
return "A";
break;
case "36=" :
return "B";
break;
}
}
</script>
</body>