Example #1
0
def send_a_qmail(message, port, destAddr, destPort, batch_size=4):
    """ Alice sends to Bob a quantum email

    :nqubit:int, the number of qubits
    :message:str, the secret message that wants to be sent 
    """
    nqubit = batch_size

    print('Alice wants to send %s' % message)
    # Initialize with Bob
    classicC = SocketChannel(port + 10, False)
    # connect to Bob
    classicC.connect(destAddr, destPort + 10)

    #send message per batch bits
    Lbins = str_to_lbin(message, batch_size)

    #generate key
    print('generating key...')
    otpkey = generate_otp_key(len(Lbins) * batch_size)
    print('X-encryption key %s' % otpkey['x'],
          'Z-encryption key %s' % otpkey['z'])

    # send key to Bob
    classicC.send(pickle.dumps(otpkey))
    print("I am Alice I sent:", otpkey)
    # close the classic channel as we don't need it anymore
    classicC.close()
    time.sleep(2)

    key_per_batch = [{
        'x': x,
        'z': z
    } for x, z in zip(wrap(otpkey['x'], batch_size),
                      wrap(otpkey['z'], batch_size))]

    # TODO: setup quantum channel
    n_master = batch_size
    n_slave = batch_size
    slave_offset = 0
    channel = Channel(slave_offset, port, remote_port=destPort)

    # bob_meas_results = [] # Bob
    for bin_batch, k in zip(Lbins, key_per_batch):
        print('Performing QOTP for string', bin_batch)
        qcirc = encode_cinfo_to_qstate(bin_batch)  # Alice
        qotp_send(qcirc, k, channel)
        # print('Bob measures',bob_meas_results[-1]) # Bob
    print("Transmission complete.")
Example #2
0
def main():
   channel = SocketChannel(1330, False)
   channel.connect('localhost', 1220)
   channel.send("Hello server")
   print("Recieved msg: %s".format{channel.recieve()})