CF Program 3,7,8
CF Program 3,7,8
• Substitution Technique
• Transposition Technique
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
▪ 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
#include <stdio.h>
#include <math.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;
if (gcd(e, phi) == 1)
break;
else
e++;
int k = 2;
double d = (1 + (k * phi)) / e;
c = fmod(c, n);
m = fmod(m, n);
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: