#Experiment (alters size of a variable (r)) performs USS attack RN = 10 #Number of time experiment run (final value of r) #timeSSS = [] timeUSS = [] sizeUSS = [] #sizeSSS = [] r = 1 #Consider a min value for some parameters (this is the starting value of a variable) while r <= RN: #we can replace any variable with r i.e. L1 = r depending on our experiment n = r #strands could remove n=r L = 5 #Private key length L1 = 5 #Lower bound of element length L2 = 8 #Upper bound of element length N = 5 #Number of element (words) in tuple import random #To use random gen package, contains random gen functions for secure crypto #Define strands of braid A = BraidGroup(n) #Generate words (braids), randomly generates generators from L1 -> L2 in length #Not crypto secure method of rand generating #Generates random words and appends to a tuple At PM = [1,-1] v = 0 At = [] i = 0 length = 0 m=0 while i <= N-1: length = randint(L1,L2) v = A([ (randint(1,n-1)* random.choice(PM)) for m in range (length)]) At.append(v) i=i+1 #Bob similary generates Bt and publishes it v = 0 Bt = [] i = 0 length = 0 m=0 while i <= N-1: length = randint(L1,L2) v = A([ (randint(1,n-1)* random.choice(PM)) for m in range (length)]) Bt.append(v) i = i + 1 #Alice chooses private key from At and finds the inverse i = 0 mu_a = [] #mu forms a list of the positions of Alices keys in the tuple At pow_a = [] while i == 0: mu_1 = randint(0,N-1) mu_a.append(mu_1) power = random.choice(PM) A_priv = (At[mu_1])^power pow_a.append(power) i = i + 1 while i <= L-1: mu_1 = randint(0,N-1) #Generates a random position mu mu_a.append(mu_1) #saves the position of mu in a list to use later power = random.choice(PM) A_priv = A_priv * (At[mu_1])^power #creates and saves Alices private key pow_a.append(power) i = i + 1 A_privinv = (A_priv)^-1 #Bob chooses his private key and inverse the same way i = 0 mu_b = [] pow_b = [] while i == 0: mu_1 = randint(0,N-1) mu_b.append(mu_1) power = random.choice(PM) B_priv = (Bt[mu_1])^power pow_b.append(power) i = i + 1 while i <= L-1: mu_1 = randint(0,N-1) mu_b.append(mu_1) power = random.choice(PM) B_priv = B_priv * (Bt[mu_1])^power pow_b.append(power) i = i + 1 B_privinv = (B_priv)^-1 #Alice creates a tuple of conjugacys using A_priv,A_privinv and Bt and sends to Bob i = 0 A_conj = [] while i <= N-1: A_conjx = A_privinv * Bt[i] * A_priv A_conj.append(A_conjx) i = i + 1 #Bob creates conjugacy's using B_priv,B_privinv and At and sends to Alice i = 0 B_conj = [] while i <= N-1: B_conjx = B_privinv * At[i] * B_priv B_conj.append(B_conjx) i = i + 1 # Alice picks her private key conjugates (mu)(position) from Bobs conjugate tuple B_conj i = 0 while i == 0: power_a = pow_a[i] BAB = (B_conj[mu_a[i]])^power_a i = i + 1 while i <= L-1: power_a = pow_a[i] bab = (B_conj[mu_a[i]])^power_a BAB = BAB * bab i = i + 1 #Alice computes A^-1 * BAB K1 = A_privinv * BAB # Bob picks his private key conjugates (mu)(position) from Alice conjugate tuple A_conj i = 0 while i == 0: power_b = pow_b[i] ABA = (A_conj[mu_b[i]])^power_b i = i + 1 while i <= L-1: power_b = pow_b[i] aba = (A_conj[mu_b[i]])^power_b ABA = ABA * aba i = i + 1 #Bob computes B^-1 * ABA K2 = B_privinv * ABA K3 = (K2)^-1 #K1 == K3 #check #sizeSSS.append(len(A_conjx.super_summit_set())) #timeSSS.append(timeit("A_conjx.super_summit_set()", seconds=True)) E = A_conjx.ultra_summit_set() #timeUSS.append(timeit("E = A_conjx.ultra_summit_set()", seconds=True)); #sizeUSS.append(len(E)) print('The USS of A_conjx below') print(E) F = Bt[N-1].ultra_summit_set() print('The USS of Bt below') print(F) #print("LNFs") #print([x.left_normal_form() for x in [for p in E]]) #print([y.left_normal_form() for y in [for q in F]]) print("Intersection") #{tuple(x) for x in E} & {tuple(y) for y in F} vvv = [x for x in E if tuple(x) in set(map(tuple, F))] print(vvv) #print(sizeUSS) #print(timeUSS) r = r + 1 #sizeSSS #sizeUSS #timeSSS #timeUSS