示例#1
0
def smptest(secret, sock, is_server):
    global axolotl
    # Create an SMP object with the calculated secret
    smp = SMP(secret)

    if is_server:
        # Do the SMP protocol
        buffer = sock.recv(2439, socket.MSG_WAITALL)
        padlength = ord(buffer[-1:])
        buffer = axolotl.decrypt(buffer[:-padlength])
        buffer = smp.step2(buffer)
        buffer = axolotl.encrypt(buffer)
        padlength = 4539 - len(buffer)
        buffer = buffer + padlength * chr(padlength)  # pad to fixed length
        sock.send(buffer)

        buffer = sock.recv(3469, socket.MSG_WAITALL)
        padlength = ord(buffer[-1:])
        buffer = axolotl.decrypt(buffer[:-padlength])
        buffer = smp.step4(buffer)
        buffer = axolotl.encrypt(buffer)
        padlength = 1369 - len(buffer)
        buffer = buffer + padlength * chr(padlength)  # pad to fixed length
        sock.send(buffer)

    else:
        # Do the SMP protocol
        buffer = smp.step1()
        buffer = axolotl.encrypt(buffer)
        padlength = 2439 - len(buffer)
        buffer = buffer + padlength * chr(padlength)  # pad to fixed length
        sock.send(buffer)

        buffer = sock.recv(4539, socket.MSG_WAITALL)
        padlength = ord(buffer[-1:])
        buffer = axolotl.decrypt(buffer[:-padlength])
        buffer = smp.step3(buffer)
        buffer = axolotl.encrypt(buffer)
        padlength = 3469 - len(buffer)
        buffer = buffer + padlength * chr(padlength)  # pad to fixed length
        sock.send(buffer)

        buffer = sock.recv(1369, socket.MSG_WAITALL)
        padlength = ord(buffer[-1:])
        buffer = axolotl.decrypt(buffer[:-padlength])
        smp.step5(buffer)

    # Check if the secrets match
    if smp.match:
        print 'Secrets Match!'
        sleep(1)
        smp_match = True
    else:
        print 'Secrets DO NOT Match!'
        smp_match = False
    return smp_match
示例#2
0
文件: axotor.py 项目: felipedau/pyaxo
def smptest(secret, sock, is_server):
    global axolotl
    # Create an SMP object with the calculated secret
    smp = SMP(secret)

    if is_server:
        # Do the SMP protocol
        buffer = sock.recv(2439, socket.MSG_WAITALL)
        padlength = ord(buffer[-1:])
        buffer = axolotl.decrypt(buffer[:-padlength])
        buffer = smp.step2(buffer)
        buffer = axolotl.encrypt(buffer)
        padlength = 4539-len(buffer)
        buffer = buffer+padlength*chr(padlength) # pad to fixed length
        sock.send(buffer)

        buffer = sock.recv(3469, socket.MSG_WAITALL)
        padlength = ord(buffer[-1:])
        buffer = axolotl.decrypt(buffer[:-padlength])
        buffer = smp.step4(buffer)
        buffer = axolotl.encrypt(buffer)
        padlength = 1369-len(buffer)
        buffer = buffer+padlength*chr(padlength) # pad to fixed length
        sock.send(buffer)

    else:
        # Do the SMP protocol
        buffer = smp.step1()
        buffer = axolotl.encrypt(buffer)
        padlength = 2439-len(buffer)
        buffer = buffer+padlength*chr(padlength) # pad to fixed length
        sock.send(buffer)

        buffer = sock.recv(4539, socket.MSG_WAITALL)
        padlength = ord(buffer[-1:])
        buffer = axolotl.decrypt(buffer[:-padlength])
        buffer = smp.step3(buffer)
        buffer = axolotl.encrypt(buffer)
        padlength = 3469-len(buffer)
        buffer = buffer+padlength*chr(padlength) # pad to fixed length
        sock.send(buffer)

        buffer = sock.recv(1369, socket.MSG_WAITALL)
        padlength = ord(buffer[-1:])
        buffer = axolotl.decrypt(buffer[:-padlength])
        smp.step5(buffer)

    # Check if the secrets match
    if smp.match:
        print 'Secrets Match!'
        sleep(1)
        smp_match = True
    else:
        print 'Secrets DO NOT Match!'
        smp_match = False
    return smp_match
示例#3
0
def smptest(secret, sock, is_server):
    # Create an SMP object with the calculated secret
    smp = SMP(secret)

    if is_server:
        # Do the SMP protocol
        buffer = a.decrypt(sock.recv(2311, socket.MSG_WAITALL))
        buffer = smp.step2(buffer)
        buffer = a.encrypt(buffer)
        buffer = buffer+(4412-len(buffer))*b'\x00' # pad to fixed length
        sock.send(buffer)

        buffer = a.decrypt(sock.recv(3345, socket.MSG_WAITALL))
        buffer = smp.step4(buffer)
        buffer = a.encrypt(buffer)
        buffer = buffer+(1243-len(buffer))*b'\x00' # pad to fixed length
        sock.send(buffer)

    else:
        # Do the SMP protocol
        buffer = smp.step1()
        buffer = a.encrypt(buffer)
        buffer = buffer+(2311-len(buffer))*b'\x00' # pad to fixed length
        sock.send(buffer)

        buffer = a.decrypt(sock.recv(4412, socket.MSG_WAITALL))
        buffer = smp.step3(buffer)
        buffer = a.encrypt(buffer)
        buffer = buffer+(3345-len(buffer))*b'\x00' # pad to fixed length
        sock.send(buffer)

        buffer = a.decrypt(sock.recv(1243, socket.MSG_WAITALL))
        smp.step5(buffer)

    # Check if the secrets match
    if smp.match:
    	writeToScreen(' Secrets Match!')
        #chat_window.insert(tk.END, 'Secrets Match!')
        smp_match = True
    else:
    	writeToScreen(' Secrets DO NOT Match!')
        #chat_window.insert(tk.END, 'Secrets DO NOT Match!')
        smp_match = False
    return smp_match    
示例#4
0
    counts = numpy.zeros(size, dtype=numpy.int32)
    flags = numpy.zeros(size, dtype=numpy.uint8)

    for a, b in enumerate(pos_to_use):
        counts[b] = draw[a]
        flags[b] = 1

    sam.append((counts, flags))

# Construct the flag index array, put relevant index into each sample...
fia = FlagIndexArray(size)
fia.addSingles()

for i in xrange(len(sam)):
    ind = fia.flagIndex(sam[i][1])
    sam[i] = (sam[i][0], sam[i][1], ind)

# Construct the SMP object...
smp = SMP(fia)
smp.setSampleCount(samCount)

for s in sam:
    smp.add(s[2], s[0])

# Get and print out the mean and its distance from the actual multinomial...
mean = smp.mean()

print 'Mean =', mean
print 'error =', numpy.fabs(mn - mean).sum() / mn.shape[0]
print 'cError =\n', numpy.fabs(mn - mean)
示例#5
0
  sam.append((counts,flags))



# Construct the flag index array, put relevant index into each sample...
fia = FlagIndexArray(size)
fia.addSingles()

for i in xrange(len(sam)):
  ind = fia.flagIndex(sam[i][1])
  sam[i] = (sam[i][0],sam[i][1],ind)



# Construct the SMP object...
smp = SMP(fia)
smp.setSampleCount(samCount)

for s in sam:
  smp.add(s[2],s[0])



# Get and print out the mean and its distance from the actual multinomial...
mean = smp.mean()

print 'Mean =', mean
print 'error =', numpy.fabs(mn-mean).sum()/mn.shape[0]
print 'cError =\n', numpy.fabs(mn-mean)