Creating Custom Encryption and Decryption Engine with JavaScript

In this video tutorial I will show you how to create a simple Encryption and Decryption engine in JavaScript.

Watch this tutorial here:

Here is the source code. But, like I’ve told in this video, it’s not completed yet.

<!DOCTYPE html>
<html>
	<head>
		<title>zkTutorials</title>
	</head>
	<body>
		<input placeholder="Type something" id="myinput">
		<button onclick="encrypt()">Encrypt</button>
		<button onclick="decrypt()">Decrypt</button>
		<div id="result"></div>
		<script>
			function encrypt(){
				var rawtext = document.getElementById("myinput").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("myinput").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 "a" :
						return ".";
						break;
					case "b" :
						return "0";
						break;
					case "c" :
						return "_";
						break;
					case "d" :
						return "=";
						break;
				}
			}
			function dec(x){
				switch(x){
					case "." :
						return "a";
						break;
					case "0" :
						return "b";
						break;
					case  "_":
						return "c";
						break;
					case  "=":
						return "d";
						break;
				}
			}
		</script>
	</body>
</html>
loading...