# Transforming a Plain Text message to Cipher Text

There are two primary ways in which a plain text can be modified to obtain cipher text: Substitution Technique and Transposition Technique.
1. Substitution Technique: Substitution technique involves the replacement of the letters by other letters and symbols. In a more straightforward way, the characters of plaintext are replaced, and other substitute characters, numbers and symbols are used at their place.
Types of Substitution Technique:

• Caesar Cipher – In this all characters of plain text is replaced by other characters with same pattern. For example, a replaced with D, B replaced with E.
• Mono Alphabetic Cipher – Major disadvantage of caesar cipher is that all elements are substituted with same technique, it make easy for cryptanalyst to crack it. In Mono Alphabetic Cipher, There is no relation between Substitution of characters. Therefore it makes harder for cryptanalyst to crack it. For example, a can be replaced with B-Z, B can be replaced with A, C-Z.
• Homophonic Substitution Cipher – In this technique, one plain text alphabet can map to more than one cipher text alphabet. This is the best substitution technique with maximum security. For example, a can be replaced with D and E.
• Polygram Substitution Cipher – In this rather than replacing one alphabet, block of alphabet is replaced. For example,
```     Polygram substitution
HELLO -------------------> YUQQW
HELL --------------------> TEUI ```
• Vigenere Cipher –
This technique uses multiple character keys. Each of the keys encrypts one single character. Each character is replaced by a number (A=0, B=1, …Z=25). After all keys are used, they are recycled. For encryption, Formula used : E=(M+K)mod 26
```Plaintext:  ATTACKATDAWN
Key:        LEMONLEMONLE
Ciphertext: LXFOPVEFRNHR ```

2. Transposition Technique:
In transposition technique, the identity of the characters remains unchanged, but their positions are changed to create the ciphertext.
Types of Transpositional Techniques:

(i) Rail Fence Technique – It uses a simple algorithm:

1. Write down plain text message as sequence of diagonals.
2. Read the plain text written in step 1 as sequence of rows.
```Plain text: come home
c       m        h        m
o       e        o        e
Cipher text : (READ ROW BY ROW) cmhmoeoe ```

(ii) Simple Columnar Transposition Technique – It uses a simple algorithm:

1. Write the plain text message row by row in predefined columns.
2. Read the message column by column. It can be in any order.
3. Message thus obtained is cipher text message.
```Plain text: come niki (suppose we have 4 columns )
C1    C2    C3    C4
c     o     m      e
n     i     k      i ```

Now we can read in any order of columns. Lets read it by 3 -> 2 -> 4 ->1

`Cipher text : mkoieicn `

(iii) Vernam Cipher – It uses a simple algorithm:

1. Treat each plain text character as a number in the increasing sequence (A=0, B=1, …Z=25).
2. Do the same for each character of the key.
3. Add each number corresponding to plain text alphabet and key.
4. If the sum produced is greater than 26, subtract 26 from it.
5. Translate each number of sum back to alphabet, it gives our ciphertext.
```Plain text:  HOW ARE YOU
Key :  NCBTZQARX
H   O   W   A   R   E   Y  O  U
7  14  22   0  17   4   24 14 20
+
N   C   B   T   Z   Q   A  R  X
13  2   1   19  25  16  0  17 23
------------------------------------
20   16  23  19  42  20  24 31  43

Subtract 26 if >26: 20   16  23  19  16  20  24  5  17
Cipher text :      U    Q   X   T    Q   U   Y  F   R
Cipher text : UQXTQUYFR ```

There are many ways to transform plain text into cipher text, but here is a simple example of a Caesar Cipher implementation in Python:

## Python

 `# code` `def` `caesar_cipher(plain_text, shift):` `    ``cipher_text ``=` `""` `    ``for` `char ``in` `plain_text:` `        ``if` `char.isalpha():` `            ``# Determine the offset based on the shift value` `            ``offset ``=` `ord``(``'a'``) ``if` `char.islower() ``else` `ord``(``'A'``)` `            ``# Apply the shift to the character and wrap around if necessary` `            ``cipher_char ``=` `chr``((``ord``(char) ``-` `offset ``+` `shift) ``%` `26` `+` `offset)` `            ``cipher_text ``+``=` `cipher_char` `        ``else``:` `            ``# Leave non-alphabetic characters unchanged` `            ``cipher_text ``+``=` `char` `    ``return` `cipher_text`

Weakness of each technique,
In the case of Substitution:

1. Because itâ€™s based on the substitution of one letter with another based on a translation table. Once the translation table is known, the code is broken.
2. Short words, words with repeated patterns, and common initial and final letters all give clues for guessing the pattern of the encryption.
3. An encryption algorithm must be regular for it to be algorithmic and for cryptographers to be able to remember it. Unfortunately, the regularity gives clues to the cryptanalyst to break a substitution.

In the case of Transposition:

Just as there are characteristic letter frequencies, there are also characteristic patterns of pairs of adjacent letters, called diagrams (groups of 2 letters) and trigrams (groups of 3 letters). The frequency of appearance of letter groups can be used to match up plaintext letters that have been separated in a ciphertext.

• Security: Transforming plain text to cipher text helps to ensure the security and privacy of the message being transmitted, making it more difficult for unauthorized users to access or read the message.
• Authentication: Cipher text can be used to authenticate the sender of a message, as only someone with the appropriate key can transform the cipher text back into plain text.
• Integrity: Cipher text can be used to verify the integrity of a message, as any changes to the cipher text during transmission will result in an incorrect decryption.
• Versatility: Cipher text can be used in a wide range of applications, from securing online transactions to protecting classified information.

• Complexity: Transforming plain text to cipher text can be a complex process that requires specialized knowledge and expertise.
• Key management: The security of cipher text is dependent on the secrecy and management of the encryption key, which can be a challenge in large-scale systems.
• Compatibility: Cipher text may not be compatible with all systems or applications, which can limit its usability and practicality.
• Processing overhead: The process of transforming plain text to cipher text can require significant computational resources, which can impact system performance.

conclusion:

transforming plain text into cipher text is an important aspect of modern communication. Encryption techniques are essential for protecting sensitive information and ensuring privacy in our increasingly connected world. There are various methods of encryption, including symmetric and asymmetric encryption, as well as hash functions, each with their own strengths and weaknesses. By understanding these techniques, we can better appreciate the role of encryption in modern communication and the importance of keeping our messages secure.

Unlock the Power of Placement Preparation!
Feeling lost in OS, DBMS, CN, SQL, and DSA chaos? Our Complete Interview Preparation Course is the ultimate guide to conquer placements. Trusted by over 100,000+ geeks, this course is your roadmap to interview triumph.