Exemple #1
0
def test_ceil():
    test_inputs = [1.0, 2.0, 1, 2, 2.1, 2.5, 2.9]
    correct_outputs = [1, 2, 1, 2, 3, 3, 3]
    test_outputs = []
    for in_num in test_inputs:
        test_outputs.append(common.ceil(in_num))

    assert all([isinstance(x, int) for x in test_outputs])
    assert test_outputs == correct_outputs
Exemple #2
0
def send_file(sock, path):
    fin = open(repopath(sock) + "\\" + path, "rb")
    data = fin.read()
    exactlength = len(data) + ceil(len(data), 256) * 64
    #       length of file    + number of hashes   *  64 bytes per hash
    # SEND HEAD
    message = makeheader(4, path, exactlength)
    sock.send(message)
    # SEND BODY
    r = upload(sock, data)
    sock.send(sha(data)[:8])
Exemple #3
0
def request_send(sock,path=None,exactsize=None):
    if not exactsize:
        print "Requesting to send", path
        length = ceil(os.stat(path).st_size,16)*16 + 256 #now length is a generous estimate of ciphertext filesize
        message = makeheader(3,length)
        sock.send(message) #send request has no body
    else:
        print "Requesting to send", exactsize, "bytes"
        sock.send(makeheader(3,exactsize))
    reply = sock.recv(1)
    if ord(reply) != 1:
        print "Upload request denied. Sorry."
        return False
    return True
Exemple #4
0
def send_file(sock,path):
    cipher = []
    print "Encrypting..."
    cipher = easyaes.encrypt(g.password,path=path) #easyaes needs your password to make an IV)
    print "Done"
    print list(sha(cipher)[:8])
    
    exactlength = len(cipher)+ceil(len(cipher),256)*64
    #       length of file     +   number of hashes   *  64 bytes per hash
    # SEND HEAD
    message = makeheader(4,getrel(path),exactlength)
    sock.send(message)
    # SEND BODY
    r = upload(sock,cipher)
    print "File sent,", r, "blocks resent"