0% found this document useful (0 votes)
8 views11 pages

Cryptography Programming Practices

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

Cryptography Programming Practices

hh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

JOURNAL

PRACTICAL 1a

import [Link].*;

class CaesarCipherProgram

{
public static void main(String args[])throws Exception

String pt,ct=" ";

int key=3;

BufferedReader brk=new BufferedReader(new InputStreamReader([Link]));

[Link]("Enter Plain Text");

pt=[Link]();

pt=[Link]();

for(int i=0;i<[Link]();i++)

int acvalue=(int)[Link](i);

acvalue=acvalue+key;

if(acvalue>122)

int diff=acvalue-122;

acvalue=96+diff;

ct=ct+(char)acvalue;

[Link](ct);

Output :-
1b
Transposition ciphers
import [Link].*;
class Railfence
{
public static void main(String args[])throws Exception
{
String pt,ct="";
BufferedReader brk=new BufferedReader(new
InputStreamReader([Link]));
[Link]("Enter Plain Text ");
pt=[Link]();
pt=[Link]();
for(int i=0;i<[Link]();i++)
{
if(i%2==0)
ct=ct+[Link](i);
}
for(int i=0;i<[Link]();i++)
{
if(i%2!=0)
ct=ct+[Link](i);
}
[Link]("Cipher Text "+ct);
}
}
Output:-

Practical 2 :- RSA Encryption and Decryption


import math
p=3
q=7
n = p*q
print("n = ",n)
phi = (p-1)*(q-1)
e=2
while(e<phi):
if ([Link](e, phi) == 1):
break
else:
e += 1
print("e =",e)
k=2
d = ((k*phi)+1)/e
print("d =", d)
print(f'public key: {e, n}')
print(f'private key: {d, n}')
msg = 11
print(f' Original message:{msg}')
C = pow(msg, e)
C = [Link](C, n)
print(f'Encrypted message:{C}')
M = pow(C,d)
M = [Link](M,n)
print(f'Decrypted message: {M}')
Practical 3 :- Message Authentication Codes
Python code for implementing MD5 Algorithm:
import hashlib
result = hashlib.md5(b'Ismile')
result1 = hashlib.md5(b'Esmile')
# printing the equivalent byte value.
print("The byte equivalent of hash is : ", end ="")
print([Link]())
print("The byte equivalent of hash is : ", end ="")
print([Link]())
Code: Python code for implementing SHA Algorithm :
import hashlib
str = input(" Enter the value to encode ")
result = hashlib.sha1([Link]())
print("The hexadecima equivalent if SHA1 is : ")
print([Link]())
Practical 4 :- Digital Signatures
from [Link] import PKCS1_v1_5
from [Link] import SHA256
from [Link] import RSA
from Crypto import Random

def generate_signature(private_key,message):
key = [Link](private_key)
hashed_message = [Link]([Link]('utf-8'))
signer = PKCS1_v1_5.new(key)
signature = [Link](hashed_message)
return signature

def verify_signature(public_key,message,signature):
key = [Link](public_key)
hashed_message = [Link]([Link]('utf-8'))
verifier = PKCS1_v1_5.new(key)
return [Link](hashed_message,signature)

random_generator = [Link]().readfrom [Link]


import PKCS1_v1_5
from [Link] import SHA256
from [Link] import RSA
from Crypto import Random

def generate_signature(private_key,message):
key = [Link](private_key)
hashed_message = [Link]([Link]('utf-8'))
signer = PKCS1_v1_5.new(key)
signature = [Link](hashed_message)
return signature

def verify_signature(public_key,message,signature):
key = [Link](public_key)
hashed_message = [Link]([Link]('utf-8'))
verifier = PKCS1_v1_5.new(key)
return [Link](hashed_message,signature)

random_generator = [Link]().read
from [Link] import PKCS1_v1_5
from [Link] import SHA256
from [Link] import RSA
from Crypto import Random

def generate_signature(private_key,message):
key = [Link](private_key)
hashed_message = [Link]([Link]('utf-8'))
signer = PKCS1_v1_5.new(key)
signature = [Link](hashed_message)
return signature

def verify_signature(public_key,message,signature):
key = [Link](public_key)
hashed_message = [Link]([Link]('utf-8'))
verifier = PKCS1_v1_5.new(key)
return [Link](hashed_message,signature)

random_generator = [Link]().read
key_pair =[Link](2048,random_generator)
public_key =key_pair.publickey().export_key()
private_key = key_pair.export_key()

message = "Hello,World"

signature = generate_signature(private_key,message)
print("Generated Signature : " ,signature)
is_valid = verify_signature(public_key,message,signature)
print("Signature Verification Result : ",is_valid)
output:-
Practical 5 :-Key exchange using Diffie-Hellman

from random import randint


if __name__ == '__main__':
P = 23
G=9
print('the value of P is :%d'%(P))
print('the value of G is :%d'%(G))
a=4
print('Secret Number for alice is :%d'%(a))
x = int(pow(G,a,P))
b=6
print('Secret Number for bob is :%d'%(b))
y = int(pow(G,b,P))
ka = int(pow(y,a,P))
kb = int(pow(x,b,P))
print('Secret key for alice is :%d'%(ka))
print('Secret keyfor bob is :%d'%(kb))

Practical 6 :- IP Security(IPsec) configuration

Practical 7:-Malware Analysis and Detection

You might also like