banner



How To Create An Encryption Algorithm

Create your own cipher using Javascript

Nitin Manocha

In this article, we are going to create our own cipher using Javascript.

A Ciphertext is an encrypted text converted from plaintext using an encryption algorithm.
The ciphertext is not readable. It is required to be decrypted into plaintext using a key.
The encryption-decryption algorithm used to create ciphertext are of various types, some of them are :

  1. Private-Key based: In this type, the same key is used for encryption as well as decryption. This key should be kept private.
  2. Public-key based: In this type, two different keys are used. The public key is used to encrypt the data and the private key is used to decrypt the data.
  3. Substitution method: In this, the characters are replaced by some other characters which make it difficult to read.
  4. Transposition method: In this method, the order of each letter is rearranged in a way that the data can't be read.

We are going to use the Substitution method to create the ciphertext here but you can use any method of your choice depending upon your requirement.

Terminology

cryptography: Study of encryption algorithms

plaintext: original message

ciphertext: encrypted message

cipher: Algorithm to convert plaintext into ciphertext

Let's Get Started

We are going to use the string " Let's create our own cipher " as data and a signature consisting of alphabets and numbers.
You can create a signature of your choice as per your requirement.

The user will pass a key as a parameter along with data.

Let's create a signature consisting of the following elements:

a-z , A-z , 0–9

The format of the key would be multiple numbers between 0–61 separated by . (dot)

for eg. key = 4.34.0.39

In the next step, we would convert the key in multiple sets of 2 adjacent elements.

i.e sets = {4 , 34} {0 , 39}

Lets Encrypt

  1. For each set, check the signature index for both the values of set

i.e {4 , 34} => {signature[4] , signature[34]} = {'e', 'I'}

2. Check the data and replace all the 'e' with 'I' and 'I' with 'e'

therefore the data would become 'LIts CrIatI Our Own CiphIr'

3. For set {0 , 39} => {signature[0] , signature[39]} = {'a', 'O'}

4. Now replace all the 'a' with 'O' and viceversa

the data would become 'LIts CrIOtI aur awn CiphIr'

Decryption

Let's Decrypt the data and make it readable again.

  1. Consider the set {0 , 39} first

replace all the 'a' with 'O' and 'O' with 'a'

the data would become 'LIts CrIatI Our Own CiphIr'

2. Now Consider the set {4 , 34}

replace all the 'e' with 'I' and 'I' with 'e'

We get our original data back : 'Lets Create Our Own Cipher'

How To Create An Encryption Algorithm

Source: https://blog.cloudboost.io/create-your-own-cipher-using-javascript-cac216d3d2c

Posted by: brownstered.blogspot.com

0 Response to "How To Create An Encryption Algorithm"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel