A student thought
An algorithm may be similar to basic algorithms of Information Security books.
I'm thankful to my colleague Mr.Jayesh Patel and my cousin Maulik Trivedi who is currently a student of computer engineering department at Marwadi College of Engineering and Technology, Rajkot.
I will describe an algorithm with practical steps proven with JavaScript code or you can perform it in any language it's your choice.
Graphic layout of tool works on this algorithm and depends on your thoughts.
I am designing a webpage like the following screenshot,
Description of algorithm
A simple algorithm works with & play with an ASCII value of characters. Algorithm works within the following six different steps.
Step 1: Convert input string characters in respected ASCII codes & store it in array like the following example of JavaScript code.
- for(i = 0; i < inputString.length; i++)
- {
- asciiArr[i] = inputString[i].charCodeAt(0);
- }
Step 2: Fill A to Z array in capital or small letters:
- for(i = 0, code = 65; i < 26; i++, code++)
- {
- atozArr[i] = String.fromCharCode(code);
- }
Step 3: Choose randomly single character index from A to Z and differentiate it's position in one variable & its respected ASCII value in second variable.
Note: Here, I am referencing a function returning a random value from minimum - maximum range. Write a function outside the main function of your code.
- position = randomIndexFromInterval(0, atozArr.length - 1);
- positionAscii = atozArr[position].charCodeAt(0);
-
- function randomIndexFromInterval(min, max)
- {
- return Math.floor(Math.random() * (max - min + 1) + min);
- }
Step 4: Addition of every input String each element to
positionAscii. - for(i = 0; i < inputString.length; i++)
- {
- encryptedString[i] = parseInt(asciiArr[i]) + parseInt(atozArr[position].charCodeAt(0));
- }
Step 5: Attachment of key to encrypted string or not it's your choice & it's your modification scenario. Here I am attaching a key with an encrypted string.
Step 6: Finally your encryption is ready to send.
- for(i = 0; i < encryptedString.length; i++)
- {
- outputString.innerHTML = outputString.innerHTML + String.fromCharCode(encryptedString[i]);
- }
Here
outputString is an html element to display output on a webpage. For decryption process reverse steps apply.
Plain Text:
Hi I am writing a blog on
blogspot.com. Cypher Text:
¾u?u¶ÂuÌǾɾüu¶u·ÁļuÄÃu·ÁļÈÅÄÉ?¸ÄÂU Note: Every time cypher text will change due to selection of random position from A to Z.
So guys here is an output screenshot of my web browser Mozilla Firefox.
JavaScript Code for Practice
- function encryption()
- {
- var inputString = document.getElementById("input")
- .value;
- var outputString = document.getElementById("enc");
- var asciiArr = new Array();
- var atozArr = new Array();
- var encryptedString = new Array();
- if(inputString.length != 0)
- {
- outputString.innerHTML = "";
-
- for(i = 0; i < inputString.length; i++)
- {
- asciiArr[i] = inputString[i].charCodeAt(0);
- }
-
- for(i = 0, code = 65; i < 26; i++, code++)
- {
- atozArr[i] = String.fromCharCode(code);
- }
-
- position = randomIndexFromInterval(0, atozArr.length - 1);
- positionAscii = atozArr[position].charCodeAt(0);
-
- for(i = 0; i < inputString.length; i++)
- {
- encryptedString[i] = parseInt(asciiArr[i]) + parseInt(atozArr[position].charCodeAt(0));
- }
-
- encryptedString[asciiArr.length] = positionAscii;
-
- for(i = 0; i < encryptedString.length; i++)
- {
- outputString.innerHTML = outputString.innerHTML + String.fromCharCode(encryptedString[i]);
- }
- document.getElementById("inputBox")
- .value = outputString.innerHTML;
- }
- else
- {
- document.getElementById("enc")
- .innerHTML = "Error: Value can not be empty.";
- return false;
- }
- }
-
- function decryption()
- {
- var inputBox = document.getElementById("inputBox");
- var plainText = document.getElementById("dec");
- if(inputBox.value != 0)
- {
- var encryptedString = inputBox.value;
- var key = encryptedString[encryptedString.length - 1];
- var decryptedString = new Array();
- for(i = 0; i < encryptedString.length - 1; i++)
- {
- decryptedString[i] = encryptedString[i].charCodeAt(0) - key.charCodeAt(0);
- }
- plainText.innerHTML = "";
- for(i = 0; i < decryptedString.length; i++)
- {
- plainText.innerHTML = plainText.innerHTML + String.fromCharCode(decryptedString[i]);
- }
- }
- else
- {
- document.getElementById("dec")
- .innerHTML = "Error: Value can not be empty.";
- return false;
- }
- }
-
- function randomIndexFromInterval(min, max)
- {
- return Math.floor(Math.random() * (max - min + 1) + min);
- }