def main(OpeClass, sentence): """Creates an OPE instance, inserts the given words, and does some range query checks.""" client = create_ope_client(OpeClass, Cipher=DumbCipher, local_size=5) # break up the sentence into words that will be inserted words = list(map(lambda s: s.lower().strip('.,;'), sentence.split())) swords = sorted(words) # insert each word as the key, and its index as that data/payload. for ind, word in enumerate(words): client.insert(word, str(ind)) print("Inserted all words in the sentence:") print(sentence) # traverse the whole thing print() print("Full traversal:") for word, indstr in client.traverse(): print(" ", word, indstr) # do a range search start, end = words[1], words[-1] print() print("The words between", start, "and", end, "are:") for word, indstr in client.range_search(start, end): print(" ", word, indstr) print("(note: range is inclusive on the left, exclusive on the right)")
def main(datafile, num_queries, image_dims, imfile): """Creates a POPE instance, inserts everything from the data file, then performs some random queries and makes an image showing the growth of comparable elements.""" # process output file name if imfile is not None: imfroot, imfext = os.path.splitext(imfile) if imfext == '': imfext = 'png' # read data into a list of (key, value) pairs data = [] with open(datafile) as data_in: for line in data_in: try: name, salstring = line.strip().split(',') salary = float(salstring) data.append((salary, name)) except ValueError: print("WARNING: invalid read of line:") print(line.rstrip()) print("Successfully read {:,} entries from {}".format(len(data), datafile)) # create POPE instance and insert all values client = create_ope_client(Pope, Cipher=DumbCipher, local_size=32) # extract and sort key values for use in generating random queries allkeys = [] for k, v in data: ck = convkey(k) client.insert(ck, v) allkeys.append((k, ck)) allkeys.sort() print("Successfully inserted {:,} entries into POPE".format(len(data))) # perform random range queries and collect data revealed = RevealedKeys(allkeys) rct = set() img = Image.new('L', (image_dims[0], num_queries[-1] + 1), 127) count = 0 update_bigimage(count, img, allkeys, revealed) while count < num_queries[-1]: print(".", end='') sys.stdout.flush() a, b = random_query(allkeys, revealed) akey = client._crypt.encode(convkey(a, left=True)) bkey = client._crypt.encode(convkey(b, right=True)) client._serv.range_search(akey, bkey) count += 1 update_revealed(client._serv._root, revealed, client, rct) update_bigimage(count, img, allkeys, revealed) if count in num_queries: sqim = make_sqimage(min(image_dims), allkeys, revealed) aim = img.crop((0, 0, image_dims[0], count)) aim = aim.resize(image_dims, Image.NEAREST) print("\nGenerated images for count", count) if imfile: sqim.save(imfroot + '-sqr-' + str(count) + '.' + imfext) aim.save(imfroot + '-all-' + str(count) + ',' + imfext) else: sqim.show() aim.show() print("Performed {} random range queries".format(count))
def main(datafile, num_queries, image_dims, imfile): """Creates a POPE instance, inserts everything from the data file, then performs some random queries and makes an image showing the growth of comparable elements.""" # process output file name if imfile is not None: imfroot, imfext = os.path.splitext(imfile) if imfext == '': imfext = 'png' # read data into a list of (key, value) pairs data = [] with open(datafile) as data_in: for line in data_in: try: name, salstring = line.strip().split(',') salary = float(salstring) data.append((salary, name)) except ValueError: print("WARNING: invalid read of line:") print(line.rstrip()) print("Successfully read {:,} entries from {}".format(len(data), datafile)) # create POPE instance and insert all values client = create_ope_client(Pope, Cipher=DumbCipher, local_size=32) # extract and sort key values for use in generating random queries allkeys = [] for k, v in data: ck = convkey(k) client.insert(ck, v) allkeys.append((k, ck)) allkeys.sort() print("Successfully inserted {:,} entries into POPE".format(len(data))) # perform random range queries and collect data revealed = RevealedKeys(allkeys) rct = set() img = Image.new('L', (image_dims[0], num_queries[-1]+1), 127) count = 0 update_bigimage(count, img, allkeys, revealed) while count < num_queries[-1]: print(".", end='') sys.stdout.flush() a, b = random_query(allkeys, revealed) akey = client._crypt.encode(convkey(a, left=True)) bkey = client._crypt.encode(convkey(b, right=True)) client._serv.range_search(akey, bkey) count += 1 update_revealed(client._serv._root, revealed, client, rct) update_bigimage(count, img, allkeys, revealed) if count in num_queries: sqim = make_sqimage(min(image_dims), allkeys, revealed) aim = img.crop((0, 0, image_dims[0], count)) aim = aim.resize(image_dims, Image.NEAREST) print("\nGenerated images for count", count) if imfile: sqim.save(imfroot + '-sqr-' + str(count) + '.' + imfext) aim.save(imfroot + '-all-' + str(count) + ',' + imfext) else: sqim.show() aim.show() print("Performed {} random range queries".format(count))