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
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)