Easy JavaScript Custom Encryption and Decryption Engine

Hello again! I’ve created a simple JavaScript program that can encrypt and decrypt basic texts.

Watch this:

And of course, this is the source code:

<!DOCTYPE html>
<html>
	<head>
		<title>Easy JavaScript Custom Encryption and Decryption Engine</title>
		<script src="jquery.js"></script>
		<style>
			input{
				margin-top: 5px;
				margin-bottom: 5px;
			}
		</style>
	</head>
	<body>
		<input id="txtinput" placeholder="Type something"><button onclick="encrypt()">Encrypt</button><button onclick="decrypt()">Decrypt</button>
		<div id="result"></div>
		<h3>Definitions</h3>
		<label>a = </label><input id="def_a" class="defi" value="a" onkeyup="savedef()"><br>
		<label>b = </label><input id="def_b" class="defi" value="b" onkeyup="savedef()"><br>
		<label>c = </label><input id="def_c" class="defi" value="c" onkeyup="savedef()"><br>
		<label>d = </label><input id="def_d" class="defi" value="d" onkeyup="savedef()"><br>
		<label>e = </label><input id="def_e" class="defi" value="e" onkeyup="savedef()"><br>
		<label>f = </label><input id="def_f" class="defi" value="f" onkeyup="savedef()"><br>
		<label>g = </label><input id="def_g" class="defi" value="g" onkeyup="savedef()"><br>
		<label>h = </label><input id="def_h" class="defi" value="h" onkeyup="savedef()"><br>
		<label>i = </label><input id="def_i" class="defi" value="i" onkeyup="savedef()"><br>
		<label>j = </label><input id="def_j" class="defi" value="j" onkeyup="savedef()"><br>
		<label>k = </label><input id="def_k" class="defi" value="k" onkeyup="savedef()"><br>
		<label>l = </label><input id="def_l" class="defi" value="l" onkeyup="savedef()"><br>
		<label>m = </label><input id="def_m" class="defi" value="n" onkeyup="savedef()"><br>
		<label>n = </label><input id="def_n" class="defi" value="n" onkeyup="savedef()"><br>
		<label>o = </label><input id="def_o" class="defi" value="o" onkeyup="savedef()"><br>
		<label>p = </label><input id="def_p" class="defi" value="p" onkeyup="savedef()"><br>
		<label>q = </label><input id="def_q" class="defi" value="q" onkeyup="savedef()"><br>
		<label>r = </label><input id="def_r" class="defi" value="r" onkeyup="savedef()"><br>
		<label>s = </label><input id="def_s" class="defi" value="s" onkeyup="savedef()"><br>
		<label>t = </label><input id="def_t" class="defi" value="t" onkeyup="savedef()"><br>
		<label>u = </label><input id="def_u" class="defi" value="u" onkeyup="savedef()"><br>
		<label>v = </label><input id="def_v" class="defi" value="v" onkeyup="savedef()"><br>
		<label>w = </label><input id="def_w" class="defi" value="w" onkeyup="savedef()"><br>
		<label>x = </label><input id="def_x" class="defi" value="x" onkeyup="savedef()"><br>
		<label>y = </label><input id="def_y" class="defi" value="y" onkeyup="savedef()"><br>
		<label>z = </label><input id="def_z" class="defi" value="z" onkeyup="savedef()"><br>
		<label>0 = </label><input id="def_n0" class="defi" value="0" onkeyup="savedef()"><br>
		<label>1 = </label><input id="def_n1" class="defi" value="1" onkeyup="savedef()"><br>
		<label>2 = </label><input id="def_n2" class="defi" value="2" onkeyup="savedef()"><br>
		<label>3 = </label><input id="def_n3" class="defi" value="3" onkeyup="savedef()"><br>
		<label>4 = </label><input id="def_n4" class="defi" value="4" onkeyup="savedef()"><br>
		<label>5 = </label><input id="def_n5" class="defi" value="5" onkeyup="savedef()"><br>
		<label>6 = </label><input id="def_n6" class="defi" value="6" onkeyup="savedef()"><br>
		<label>7 = </label><input id="def_n7" class="defi" value="7" onkeyup="savedef()"><br>
		<label>8 = </label><input id="def_n8" class="defi" value="8" onkeyup="savedef()"><br>
		<label>9 = </label><input id="def_n9" class="defi" value="9" onkeyup="savedef()"><br>
		<label>[space] = </label><input id="def_space" class="defi" value=" " onkeyup="savedef()"><br>
		<h3>Current Definitions in JSON</h3>
		<div id="currentdef"></div>
		<script>
			var separator = " ";
			var definitions = [
				{ def : "a", temp : "a" },
				{ def : "b", temp : "b" },
				{ def : "c", temp : "c" },
				{ def : "d", temp : "d" },
				{ def : "e", temp : "e" },
				{ def : "f", temp : "f" },
				{ def : "g", temp : "g" },
				{ def : "h", temp : "h" },
				{ def : "i", temp : "i" },
				{ def : "j", temp : "j" },
				{ def : "k", temp : "k" },
				{ def : "l", temp : "l" },
				{ def : "m", temp : "m" },
				{ def : "n", temp : "n" },
				{ def : "o", temp : "o" },
				{ def : "p", temp : "p" },
				{ def : "q", temp : "q" },
				{ def : "r", temp : "r" },
				{ def : "s", temp : "s" },
				{ def : "t", temp : "t" },
				{ def : "u", temp : "u" },
				{ def : "v", temp : "v" },
				{ def : "w", temp : "w" },
				{ def : "x", temp : "x" },
				{ def : "y", temp : "y" },
				{ def : "z", temp : "z" },
				{ def : "0", temp : "0" },
				{ def : "1", temp : "1" },
				{ def : "2", temp : "2" },
				{ def : "3", temp : "3" },
				{ def : "4", temp : "4" },
				{ def : "5", temp : "5" },
				{ def : "6", temp : "6" },
				{ def : "7", temp : "7" },
				{ def : "8", temp : "8" },
				{ def : "9", temp : "9" },
				{ def : " ", temp : " " },
			];
			
			if(localStorage.getItem("encdecdef") === null){
				savedef();
			}else{
				definitions = JSON.parse(localStorage.getItem("encdecdef"));
			}
			
			function savedef(){
				for(var i = 0; i < $(".defi").length; i++){
					definitions[i].temp = $(".defi:eq("+i+")").val();
				}
				loaddef();
				localStorage.setItem("encdecdef", JSON.stringify(definitions));
				$("#currentdef").html(JSON.stringify(definitions));
			}
			
			function loaddef(){
				for(var i = 0; i < $(".defi").length; i++){
					$(".defi:eq("+i+")").val(definitions[i].temp);
				}
			}
			
			loaddef();
		
			function encrypt(){
				$("#result").html("");
				var txtinput = $("#txtinput").val().toLowerCase();
				for(var i = 0; i < txtinput.length; i++){
					for(var x = 0; x < definitions.length; x++){
						if(definitions[x].def == txtinput[i]){
							$("#result").append(definitions[x].temp + separator);
						}
					}
				}
			}
			function decrypt(){
				$("#result").html("");
				var txtinput = $("#txtinput").val().toLowerCase();
				txtinput = txtinput.split(separator);
				for(var i = 0; i < txtinput.length; i++){
					for(var x = 0; x < definitions.length; x++){
						if(definitions[x].temp == txtinput[i]){
							$("#result").append(definitions[x].def);
						}
					}
				}
			}
		</script>
	</body>
</html>

Click here to download the source code.

loading...

Leave a Reply

Your email address will not be published. Required fields are marked *