Commit da7453ad authored by Fan Jiang's avatar Fan Jiang
Browse files

change some senarios

parent 166d9880
......@@ -35,23 +35,37 @@ class Entity:
self.rid+=1
self.mid=0
self.derive()
print self.name, '\tnext our_dh:', self.our_dh, 'key:', self.our_dh[1]+self.their_dh
print self.name, '\tnext our_dh:', self.our_dh
self.r_flag = False
if self.role == 'A':
self.Ca[self.rid]['chain'].append(self.mid)
else:
self.Cb[self.rid]['chain'].append(self.mid)
if self.role == 'A':
self.Ca[self.rid]['chain'].append(self.Ca[self.rid]['chain'][self.mid-1] + 1)
else:
self.Cb[self.rid]['chain'].append(self.Cb[self.rid]['chain'][self.mid-1] + 1)
toSend = Msg(self.name, self.rid, self.mid, self.our_dh[1])
self.mid+=1
print self.name, '\tsending: ', toSend.__dict__
print self.name, '\tkey:', self.our_dh[1],'+',self.their_dh , '=', self.our_dh[1]+self.their_dh
return toSend
def receive(self, m):
print self.name, "\treceive: ", m.__dict__
if m.rid >= self.rid:
if m.rid == self.rid + 1:
print self.name, "\tkey: ", self.our_dh[1],'+',self.their_dh , '=', self.our_dh[1]+self.their_dh
self.rid+=1
self.their_dh = m.dh
self.r_flag = True
print self.name, "\tkey: ", self.our_dh[1]+self.their_dh
self.derive()
else:
if self.role == 'B':
self.Ca[self.rid]['chain'].append(self.Ca[self.rid]['chain'][m.mid-1] + 1)
else:
self.Cb[self.rid]['chain'].append(self.Cb[self.rid]['chain'][m.mid-1] + 1)
if self.role == 'B':
c = self.Ca[self.rid]['chain'][m.mid]
else:
c = self.Cb[self.rid]['chain'][m.mid]
print self.name, "\tchain key: ", c
def genDH(self):
self.our_dh = [random.randint(0,1024), random.randint(0,1024)]
......@@ -59,8 +73,8 @@ class Entity:
def derive(self):
i = self.rid
self.R.append(i)
self.Ca.append({'rid':i,'chain':[]})
self.Cb.append({'rid':i,'chain':[]})
self.Ca.append({'rid':i,'chain':[0]})
self.Cb.append({'rid':i,'chain':[100]})
def initialize():
print "Initializing"
......@@ -83,17 +97,21 @@ def initialize():
return a, b
a, b = initialize()
m1 = a.send()
m2 = b.send()
a.receive(m2)
b.receive(m1)
a.receive(b.send())
a.receive(b.send())
a.receive(b.send())
a.receive(b.send())
b.receive(a.send())
b.receive(a.send())
b.receive(a.send())
a.receive(b.send())
a.receive(b.send())
a.receive(b.send())
a.receive(b.send())
b.receive(a.send())
b.receive(a.send())
b.receive(a.send())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment