Coders Packet

Caesar Cipher using Java

By Shiddhant Gupta

This project is designed for encrypting and decrypting the text using Java Programming Language.

This project is designed for encrypting and decrypting the text using Java Programming Language.

The Caesar Cipher is the simplest and oldest encryption technique. It is a method in which each letter in the plaintext is replaced by a letter with some fixed number of positions down the alphabet. For this reason, the shift cipher technique is called the Caesar cipher. The Caesar cipher is a kind of replacement (substitution) cipher, where all letter of plain text is replaced by another letter. It works with alphabets only.

PlainText means readable text. For eg: Hello everyone.

CipherText means text that has been encrypted and therefore unreadable. For eg: $%UFU%F^R

Formulas

1.)For Encryption : E(x) = ( pt + n ) mod 26

2.)For Decryption : D(x) = ( ct - n ) mod 26

where

pt denotes plaintext.

ct denotes ciphertext.

n denotes the key value.

E and D denote Encryption and Decryption.

In the above, if the result is not in the range 0 - 25 i.e. if pt+n and ct-n are not in the range 0 - 25 then we have to add or subtract 26.

For example: If D is -3 then add -3 with 26 and 23 as the answer.

Key-Value Table

Key-Value Table

For Example: Use the Caesar cipher to encrypt and decrypt the message "CODERSPACKET," and the key value of this message is 3.

Encryption

PlainText          Encryption Formula: (x + n) mod 26          CipherText

C(02)                        (02 + 3) mod 26                              05->F

O(14)                        (14 + 3) mod 26                              17->R

D(03)                        (03 + 3) mod 26                              06->G

E(04)                        (04 + 3) mod 26                              07->H

R(17)                        (17 + 3) mod 26                              20->U

S(18)                        (18 + 3) mod 26                              21->V

P(15)                        (15 + 3) mod 26                              18->S

A(00)                        (00 + 3) mod 26                              03->D

C(02)                        (02 + 3) mod 26                              05->F

K(10)                        (10 + 3) mod 26                              13->N

E(04)                        (04 + 3) mod 26                              07->H

T(19)                        (19 + 3) mod 26                              22->W

So,The encrypted message is "FRGHUVSDFNHW"

Decryption

PlainText          Encryption Formula: (x + n) mod 26          CipherText

F(05)                        (05 - 3) mod 26                               02->C

R(17)                        (17 - 3) mod 26                               14->O

G(06)                        (06 - 3) mod 26                               03->D

H(07)                        (07 - 3) mod 26                               04->E

U(20)                        (20 - 3) mod 26                               17->R

V(21)                        (21 + 3) mod 26                               18->S

S(18)                        (18 - 3) mod 26                               15->P

D(03)                        (03 - 3) mod 26                               00->A

F(05)                        (05 - 3) mod 26                               02->C

N(13)                        (13 - 3) mod 26                               10->K

H(07)                        (07 - 3) mod 26                               04->E

W(22)                       (22 - 3) mod 26                               19->T

So,The decrypted message is "CODERSPACKET"

ALL POSSIBLE OUTPUTS

Output1

Output2

Output3

Output4

Output5

Output6

Output7

Output8

 

Download project

Reviews Report

Submitted by Shiddhant Gupta (Shiddhant123)

Download packets of source code on Coders Packet