0% found this document useful (0 votes)
57 views5 pages

Implementation of DIGITAL SIGNATURE Algorithm Using C/C++/Python

The document describes developing a digital signature algorithm using Python. It includes short procedures to generate keys, create signatures, and verify signatures. Key generation involves choosing random prime numbers p and q, finding a generator h, and calculating the public and private keys. Signature creation uses a randomly generated key k to calculate r and s values. Verification recreates r to check the signature is valid. The code implements these steps, taking a message as input and outputting whether the generated signature is verified.
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)
57 views5 pages

Implementation of DIGITAL SIGNATURE Algorithm Using C/C++/Python

The document describes developing a digital signature algorithm using Python. It includes short procedures to generate keys, create signatures, and verify signatures. Key generation involves choosing random prime numbers p and q, finding a generator h, and calculating the public and private keys. Signature creation uses a randomly generated key k to calculate r and s values. Verification recreates r to check the signature is valid. The code implements these steps, taking a message as input and outputting whether the generated signature is verified.
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/ 5

ASSESSMENT -10

Implementation of DIGITAL SIGNATURE Algorithm


using C/C++/Python
CSE1011-Cryptography fundamentals
L3+L4 SLOT

NAME : S Harshith
REG NO: 18BCI0099

Aim:
To develop the Digital Signature Algorithm using C/C++/Python.
Short-Procedure:
CODE:

import random
def modInverse(ai,m):
ai=ai%m
for x in range(1,m):
if((ai*x)%m==1):
return x
return 1
def hashFunction(mess):
li=[]
for i in range(0,len(mess)):
temp=list(str(ord(mess[i])))
for j in range(len(temp)):
li.append(list(bin(int(temp[j]))[2:]))
s=''
for i in range(len(li)):
if(len(li[i])!=4):
l=4-len(li[i])
li[i]=s.join(li[i])
li[i]=(l*'0')+li[i]
else:
li[i]=s.join(li[i])

var1=list("0000")
var2=list("0000")
for i in range(0,len(li),2):
for j in range(0,4):
var1[j]=str(int(var1[j])^int(li[i][j]))
var2[j]=str(int(var2[j])^int(li[i+1][j]))
temp2=s.join(var1)+s.join(var2)
temp3=0
for i in range(0,8):
temp3=temp3+(int(temp2[i])*(2**(7-i)))
return temp3

#DSA Key Generation


p=int(input("Enter the value for p: "))
q=int(input("Enter the value for q: "))
h=0
while(h**((p-1)/q)%p<1):
h=random.randint(1,p-1)

g=int(h**((p-1)/q))
x=int(random.randint(1,q))
y=(g**x)%p
print("PUBLIC KEY: ",y)
print("PRIVATE KEY: ",x)

M=list(input("Enter the message(string): "))


hm=hashFunction(M)
print("H(M): ",hm)
#DSA Signature Creation
k=int(random.randint(1,q))
print("\nSignature Key: ",k)
r=int(((g**k)%p)%q)
s=int((modInverse(k,q)*(hm+(x*r))%q))
print("(r,s)=(",r,",",s,")")

#DSA Signature Verification


w=modInverse(s,q)%q
u1=(hm*w)%q
u2=(r*w)%q
v=((g**u1)*(y**u2)%p)%q
if(v==r):
print("Signature is verified")
else:
print("Signature is false")

OUTPUT:
SCREENSHOTS OF CODE:
THE END …….

You might also like