Beispiel #1
0
def decrypt(c,pk,sk):
	p,g,h=pk
	c1,c2=c
	x=sk
	d=calc.mod(c1,x,p)
	c=calc.GenInverse(p,d)
	return calc.mod(c*c2,1,p)
Beispiel #2
0
def GenKey(k):
    prime_min = 1 << (k - 1)
    prime_max = 1 << k
    p = calc.GenPrime(prime_min, prime_max)
    g = sympy.primitive_root(p)
    x = random.randint(0, p - 1)
    h = calc.mod(g, x, p)
    return (p, g, h), x
Beispiel #3
0
import sys
sys.path.insert(1, 'D:\Python\Week 3')
import calc as c

p=c.add(3,4)
q=c.sub(7,5)
r=c.mul(9,3)
s=c.div(16,2)
t=c.mod(15,7)
print (p,q,r,s,t)
Beispiel #4
0
import calc

a=input("Enter the a value:")
b=input("Enter the b value:")
print "Sum of the a and b is:",calc.add(a,b)
print "Difference of the a and b is:",calc.diff(a,b)
print "Multiplication of the a and b is:",calc.mul(a,b)
print "Divison of the a and b is:",calc.div(a,b)
print "Square root of the a is:",calc.sqrt(a)
print "Square root of the b is:",calc.sqrt(b)
print "floordiv of the a and b is:",calc.floordiv(a,b)
print "modulus of the a and b is:",calc.mod(a,b)
print "Prime number verification for a:",calc.prime(a)
print "Prime number verification for b:",calc.prime(b)
Beispiel #5
0
from calc import add, sqrt, mod, prime

a = input("Enter the a value:")
b = input("Enter the b value:")
print "Sum of the a and b is:", add(a, b)
print "Square root of the a is:", sqrt(a)
print "Square root of the b is:", sqrt(b)
print "modulus of the a and b is:", mod(a, b)
print "Prime number verification for a:", prime(a)
print "Prime number verification for b:", prime(b)
Beispiel #6
0
def encrypt(m, pk):
    p, g, h = pk
    r = random.randint(0, p - 1)
    c1 = calc.mod(g, r, p)
    c2 = calc.mod(calc.mod(h, r, p) * m, 1, p)  #m*h^r
    return (c1, c2)
Beispiel #7
0
#!/bin/python

import calc

run = True

while run:
	calc.print_welcome()

	numbers = calc.get_numbers()

	operation = calc.get_operation()

	if operation == 1:
		print(numbers[0], " + ", numbers[1], " = ", calc.add(numbers[0], numbers[1]))

	if operation == 2:
		print(numbers[0], " - ", numbers[1], " = ", calc.sub(numbers[0], numbers[1]))

	if operation == 3:
		print(numbers[0], " x ", numbers[1], " = ", calc.mul(numbers[0], numbers[1]))

	if operation == 4:
		print(numbers[0], " / ", numbers[1], " = ", calc.div(numbers[0], numbers[1]))

	if operation == 5:
		print(numbers[0], " % ", numbers[1], " = ", calc.mod(numbers[0], numbers[1]))

	cont = input("Would you like to do another calculation? (y/n): ")
	if cont != 'y' and cont != 'Y':
		run = False
Beispiel #8
0
 def test_mod(self): 
     self.assertEqual(calc.mod(20,6),2)
     self.assertEqual(calc.mod(20,5),0)
     self.assertEqual(calc.mod(2,6),2)
     self.assertEqual(calc.mod(20,"d"),"DTNS")
 def test_mod(self):
     self.assertTrue(calc.mod(8, 2))
     self.assertFalse(calc.mod(7, 2))
 def test_mod(self):
     assert mod(4, 4) == 0