Cryptography & Network Security Lab: Dayalbagh Educational Institute
Cryptography & Network Security Lab: Dayalbagh Educational Institute
Cryptography & Network Security Lab: Dayalbagh Educational Institute
By – Kanchan Pal
1904700
Assignment – 1
Submit your own complete source code in a language of your choice
for implementing:
secret = int(secret)
new_ind = 0
for i in plaintext:
if i.lower() in alphabet:
new_ind = alphabet.index(i) + secret
ciphertext += alphabet[new_ind % 26]
else:
ciphertext += i
print("The ciphertext is: " + ciphertext)
import pyperclip
def main():
myMessage ='DAYALBAGH EDUCATION INSTITUTE'
myKey = 2
ciphertext = encryptMessage(myKey, myMessage)
print("Cipher Text is")
print(ciphertext + '|')
pyperclip.copy(ciphertext)
Assignment – 2
1. Caesar Cipher.
shift = int(shift)
new_ind = 0
for i in plaintext:
if i.lower() in alphabet:
new_ind = alphabet.index(i) + shift
ciphertext += alphabet[new_ind % 26]
else:
ciphertext += i
print("The ciphertext is: " + ciphertext)
Assignment-3
Submit your own complete source code in a language of your choice
for implementing:
if null_count > 0:
return msg[: -null_count]
return msg
msg = "I AM VERY HAPPY"
cipher = encryptMessage(msg)
print("Encrypted Message: {}".
format(cipher))
1. Monoalphabetic Cipher.
monoalpha={'a':'m','b':'n','c':'b','d':'j','e':'x','f':'k','g':'l','h':'a','i':'s','j':'n','k':'o','l':'p','m':'h','n':'b','o'
:'r','p':'q','q':'z','r':'w','s':'i','t':'v','u':'t','v':'d','w':'y','x':'f','y':'u','z':'g',' ':' ',}
inverse_monoalpha={}
for i in monoalpha:
inverse_monoalpha[monoalpha[i]]=i
decrypt_msg=[]
for letter in encrypt_msg:
decrypt_msg.append(inverse_monoalpha.get(letter,letter))
print(''.join(decrypt_msg))
2. Polyalphabetic Cipher.
def encrypt(plaintext, key):
key_length = len(key)
key_as_int = [ord(i) for i in key]
plaintext_int = [ord(i) for i in plaintext]
ciphertext = ""
for i in range(len(plaintext_int)):
value = (plaintext_int[i] + key_as_int[i % key_length]) % 26
ciphertext += chr(value + 65)
return ciphertext
print(encrypt("hello","khushi"))
Assignment-5
Submit your own complete source code in a language of your choice
for implementing:
// Driver code
public static void main(String[] args)
{
long P, G, x, a, y, b, ka, kb;
2. RSA Algorithm.
Code(in java)-
/ Java Program to Implement the RSA Algorithm
import java.math.*;
import java.util.*;
class RSA {
public static void main(String args[])
{
int p, q, n, z, d = 0, e, i;
Assignment-6
Submit your own complete source code in a language of your choice
for implementing:
1. Communication between two controllers using I2C in Simplex
Mode.
3.