0% found this document useful (0 votes)
2 views7 pages

CF Program 3,7,8

The document explains symmetric key cryptography, focusing on substitution and transposition techniques. It details various algorithms for each technique, including the Caesar Cipher, Playfair Cipher, Hill Cipher, One Time Pad for substitution, and Rail Cipher, Simple Columnar Transposition for transposition. Additionally, it includes programs demonstrating RSA algorithm in C and MD5 hash algorithm in Python.

Uploaded by

coc69351
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

CF Program 3,7,8

The document explains symmetric key cryptography, focusing on substitution and transposition techniques. It details various algorithms for each technique, including the Caesar Cipher, Playfair Cipher, Hill Cipher, One Time Pad for substitution, and Rail Cipher, Simple Columnar Transposition for transposition. Additionally, it includes programs demonstrating RSA algorithm in C and MD5 hash algorithm in Python.

Uploaded by

coc69351
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Program – 3

Demonstrate all types of substitution technique and


transposition technique in symmetric key cryptography

Symmetric Key Cryptography: In cryptography, a symmetric key is one that is used


both to encrypt and decrypt information. This means that to decrypt information, one must
have the same key that was used to encrypt it. There are mainly two techniques to perform
cryptography:

• Substitution Technique
• Transposition Technique

Substitution Technique: In this, we replace the characters of the original message


with other words with the help of key to encrypt the message and use same key to decrypt
the message. It is of two types:

▪ Monoalphabatic Cipher: In this, a particular character is substituted with a specific


character only throughout the encryption process.
▪ Polyalphabatic Cipher: In this, the substitution of a character differs each time the
character repeats itself in a message throughout the encryption process.

Here below are some algorithms based on Substitution technique of Symmetric Key
Cryptography:

▪ Ceaser Cipher: each letter of a given text is replaced by a letter with a fixed
number of positions down the alphabet. For example, with a shift of 1, A would be
replaced by B, B would become C, and so on. The method is apparently named after
Julius Caesar.

Text: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Shift: 23
Cipher: XYZABCDEFGHIJKLMNOPQRSTUVW

▪ Playfair Cipher: Playfair cipher is an encryption algorithm to encrypt or encode


a message. It is the same as a traditional cipher. The only difference is that it
encrypts a digraph (a pair of two letters) instead of a single letter. It initially creates
a key-table of 5*5 matrix. The matrix contains alphabets that act as the key for
encryption of the plaintext. Note that any alphabet should not be repeated. Another
point to note that there are 26 alphabets and we have only 25 blocks to put a letter
inside it. Therefore, one letter is excess so, a letter will be omitted (usually J) from
the matrix. Nevertheless, the plaintext contains J, then J is replaced by I. It means
treat I and J as the same letter, accordingly.

▪ Hill Cipher: In classical cryptography, the hill cipher is a polygraphic


substitution cipher based on Linear Algebra. It was invented by Lester S. Hill in the
year 1929. In simple words, it is a cryptography algorithm used to encrypt and
decrypt data for the purpose of data security. The algorithm uses matrix calculations
used in Linear Algebra. It is easier to understand if we have the basic knowledge of
matrix multiplication, modulo calculation, and the inverse calculation of matrices.

▪ One Time Pad: It is the only available algorithm that is unbreakable(completely


secure). It is a method of encrypting alphabetic plain text. It is one of the
Substitution techniques which converts plain text into ciphertext. In this
mechanism, we assign a number to each character of the Plain-Text. So, encrypting
every new message requires a new key of the same length as the new message in
one-time pad. So, encrypting every new message requires a new key of the same
length as the new message in one-time pad. The ciphertext generated by the One-
Time pad is random, so it does not have any statistical relation with the plain text.

Transposition Technique: In this, we interchange the positions of the characters in


the message in order to encrypt the message. We use the same algorithm to decrypt the
message. There are 3 algorithms based on Transposition technique of Symmetric Key
Cryptography:

▪ Rail Cipher: The rail fence cipher (also called a zigzag cipher) is a form of
transposition cipher. It derives its name from the way in which it is encoded.

Encryption
Input : "defend the east wall"
Key = 3
Output : dnhaweedtees alf tl
Decryption
Input : dnhaweedtees alf tl
Key = 3
Output : defend the east wall

▪ Simple Columnar Transposition: Transposition Cipher is a cryptographic


algorithm where the order of alphabets in the plaintext is rearranged to form a
cipher text. In this process, the actual plain text alphabets are not included. A simple
example for a transposition cipher is columnar transposition cipher where each
character in the plain text is written horizontally with specified alphabet width. The
cipher is written vertically, which creates an entirely different cipher text.

▪ Simple Columnar With Multiple Rounds: This technique works same as


Simple Columnar Transposition Technique but with multiple rounds (2-3 rounds).
Program – 7
Implement concept of RSA algorithm using asymmetric
cryptography in C.

#include <stdio.h>

#include <math.h>

int gcd(int a, int h)

int temp;

while (1) {

temp = a % h;

if (temp == 0)

return h;

a = h;

h = temp;

int main()

double p = 3;
double q = 7;

double n = p * q;

double e = 2;

double phi = (p - 1) * (q - 1);

while (e < phi) {

if (gcd(e, phi) == 1)

break;

else

e++;

int k = 2;

double d = (1 + (k * phi)) / e;

double msg = 12;

printf("Message data = %lf", msg);

double c = pow(msg, e);

c = fmod(c, n);

printf("\nEncrypted data = %lf", c);


double m = pow(c, d);

m = fmod(m, n);

printf("\nOriginal Message Sent = %lf", m);

return 0;

Output:
Program – 8
Write a program to implement MD5 hash algorithm in python.

import hashlib
result = hashlib.md5(b'cryptographyCF')
print("The byte equivalent of hash is : ", end ="")
print(result.digest())
import hashlib
str2hash = "cryptographyCF"
result = hashlib.md5(str2hash.encode())
print("The hexadecimal equivalent of hash is : ", end ="")
print(result.hexdigest())

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy