You are on page 1of 6

NAME: MUSKAN AGARWAL

REGISTRATION NUMBER: 19BCI0067

CSE 1011:Cryptography Fundamentals


Fall Semester-2020
Lab Experiment 3
Digital Signature and ECC
1. Digital Signature (DSA signature): Generate the digital
signature for the specific document. Modify the content of
the document and verify the signature.

m
CODE:

er as
co
from Crypto.PublicKey import RSA

eH w
o.
from Crypto.Signature.pkcs1_15 import PKCS115_SigScheme
rs e
ou urc
from Crypto.Hash import SHA256
import binascii
o

keyPair = RSA.generate(bits=1024)
aC s
vi y re

pubKey = keyPair.publickey()
def Signature_verification():
ed d

verifier = PKCS115_SigScheme(pubKey)
ar stu

try:
verifier.verify(hash, signature)
is

print("Signature is valid.")
Th

except:
sh

print("Signature is invalid.")

#Making a Signature For the text File

This study source was downloaded by 100000814721861 from CourseHero.com on 11-15-2021 07:12:36 GMT -06:00

https://www.coursehero.com/file/69123540/19BCI0067-VL2020210104337-AST04-1pdf/
NAME: MUSKAN AGARWAL
REGISTRATION NUMBER: 19BCI0067
with open('text.txt', 'rb') as f:
msg = f.read()
f.close()
hash = SHA256.new(msg)
signer = PKCS115_SigScheme(keyPair)
signature = signer.sign(hash)
print("Signature:", binascii.hexlify(signature))

#Checking the non altered file initially

m
er as
with open('text.txt', 'rb') as f:

co
eH w
msg = f.read()

o.
f.close() rs e
ou urc
hash = SHA256.new(msg)
Signature_verification()
o
aC s
vi y re

t=input("Once the file has been altered,press enter: ")


#Checking After the file alteration
ed d
ar stu

with open('text.txt', 'rb') as f:


msg = f.read()
is

f.close()
Th

hash = SHA256.new(msg)
Signature_verification()
sh

input()

This study source was downloaded by 100000814721861 from CourseHero.com on 11-15-2021 07:12:36 GMT -06:00

https://www.coursehero.com/file/69123540/19BCI0067-VL2020210104337-AST04-1pdf/
NAME: MUSKAN AGARWAL
REGISTRATION NUMBER: 19BCI0067

OUTPUT:

m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh

This study source was downloaded by 100000814721861 from CourseHero.com on 11-15-2021 07:12:36 GMT -06:00

https://www.coursehero.com/file/69123540/19BCI0067-VL2020210104337-AST04-1pdf/
NAME: MUSKAN AGARWAL
REGISTRATION NUMBER: 19BCI0067
F:\>dsa.py
Signature:
b'28d0575ea0f3e46eb3e1423c3c248e29fb49a1bef501b7a0a7ec169
3135fb9ad36698bc3fcead9be21bbacb882f8c6848204525dc2f231f9
b196a0d39f6a849b7660057169ce99786885aa958d4bc3c6810fbc4
9b9cbb8893e651e88593126516e11471bc41a6788111e944d3afc1c
e9099eb00678137ca07089f6fcc7676b4d'
Signature is valid.
Once the file has been altered,press enter:
Signature is invalid.

m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh

This study source was downloaded by 100000814721861 from CourseHero.com on 11-15-2021 07:12:36 GMT -06:00

https://www.coursehero.com/file/69123540/19BCI0067-VL2020210104337-AST04-1pdf/
NAME: MUSKAN AGARWAL
REGISTRATION NUMBER: 19BCI0067
2. Design and implement a secure instant messaging service
based on Elliptic Curve Cryptography (ECC) (secure
communication using Standard Libraries)

CODE:
from tinyec import registry
from Crypto.Cipher import AES
import hashlib, secrets, binascii
def ecc_point_to_256_bit_key(point):

m
er as
sha = hashlib.sha256(int.to_bytes(point.x, 32, 'big'))

co
sha.update(int.to_bytes(point.y, 32, 'big'))

eH w
o.
return sha.digest()
rs e
ou urc
curve = registry.get_curve('brainpoolP256r1')
o

privateKey = secrets.randbelow(curve.field.n)
aC s
vi y re

publicKey = privateKey * curve.g


print("Public Key: ")
ed d

print(publicKey)
ar stu

print("\nPrivate Key: ")


print(privateKey)
is
Th
sh

This study source was downloaded by 100000814721861 from CourseHero.com on 11-15-2021 07:12:36 GMT -06:00

https://www.coursehero.com/file/69123540/19BCI0067-VL2020210104337-AST04-1pdf/
NAME: MUSKAN AGARWAL
REGISTRATION NUMBER: 19BCI0067

OUTPUT:
F:\>ecc.py
Public Key:
(55837652867918500824416910041388588712645028383018706
143430518211701167265367,
63319601760344405790878298066742583421548016204614554
115744199505148224257328) on "brainpoolP256r1" => y^2 = x^3
+
56698187605326110043627228396178346077120614539475214
109386828188763884139993x +
17577232497321838841075697789794520262950426058923084

m
er as
567046852300633325438902 (mod

co
76884956397045344220809746629001649093037950200943055

eH w
203735601445031516197751)

o.
rs e
ou urc
Private Key:
76379999197929570352928916633694982455341802781280815
o

40224010898920615985378
aC s
vi y re
ed d
ar stu
is
Th
sh

NAME: MUSKAN AGARWAL


REGISTRATION NUMBER: 19BCI0067

This study source was downloaded by 100000814721861 from CourseHero.com on 11-15-2021 07:12:36 GMT -06:00

https://www.coursehero.com/file/69123540/19BCI0067-VL2020210104337-AST04-1pdf/
Powered by TCPDF (www.tcpdf.org)

You might also like