Caesar encryption of string using JavaScript

Caesar encryption of string using JavaScript

Caesar encryption of string is basically shifting of characters by some amount. Let me put it this way, if you’ve a string “abc” and you want it to be shifted by amount 4. i.e. “efg”. This is called Caesar encryption.

Here in this example, we are going to use concept of ASCII code. Every letter in alphabet has some decimal value assigned i.e. “a” = 97, “b” = 98 …”z” = 122 or “A” = 65, “B” = 66…”Z” = 90.

The trick liesĀ  when you’ve to encrypt trailing letters like x,y,z. If your shift amount is 3 and string is “xyz” then encrypted string should be “abc”.

Output:

Leave a Reply

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