Exemplo n.º 1
0
#!/usr/bin/python3

import math
from math import ceil
import matplotlib.pyplot as plt
from colors import *
from padme import *
import matplotlib
import utils as utils

utils.prepare_for_latex()


def getNextPowerOfTwo(x):
    exp = math.ceil(math.log(x, 2))
    return math.pow(2, exp)


xVals = []
padMeEffectiveSizes = []
pow2EffectiveSizes = []

L = 10
end = 1000 * 1000

while L < end:
    a = 100 * float(getPadme(L) - L) / L
    b = 100 * float(getNextPowerOfTwo(L) - L) / L

    #print(L, a, b)
Exemplo n.º 2
0
def createFigDatasetAnonymityCDF(i, input_file):
    plt.figure(i)
    utils.prepare_for_latex()
    Ls = []  # the raw L's values
    Bs = []

    ## Parse the input file, fills Ls, Ls_count, Ls_hist
    with open(input_file, "r") as f:
        for line in f:
            L = int(line.strip())
            if L == 0 or L == 1:
                continue
            Ls.append(L)

    Bs = [getPadme(L) for L in Ls]
    Ps = [math.pow(2, math.ceil(math.log(L, 2))) for L in Ls]
    Qs = [L + (L % 256) for L in Ls]
    Qs2 = [L + (L % (512 * 8)) for L in Ls]

    legends = []

    data = computeDensity(Ls)
    p = 100. * np.arange(len(data)) / (len(data) - 1)
    plt.plot(data,
             p,
             color=unpadded_color,
             linestyle=unpadded_style,
             linewidth=curve_width)
    legends.append('Unpadded')

    #data = computeDensity(Qs)
    #p = 100. * np.arange(len(data)) / (len(data) - 1)
    #plt.plot(data, p, color=blockcipher_color, linestyle=blockcipher_style, linewidth=curve_width)
    #legends.append('Block cipher (256b)')

    data = computeDensity(Qs2)
    p = 100. * np.arange(len(data)) / (len(data) - 1)
    plt.plot(data,
             p,
             color=blockcipher_color,
             linestyle=blockcipher_style,
             linewidth=curve_width)
    legends.append('Tor cell (512B)')

    data = computeDensity(Bs)
    p = 100. * np.arange(len(data)) / (len(data) - 1)
    plt.plot(data,
             p,
             color=padme_color,
             linestyle=padme_style,
             linewidth=curve_width)
    legends.append('Padmé')

    data = computeDensity(Ps)
    p = 100. * np.arange(len(data)) / (len(data) - 1)
    plt.plot(data,
             p,
             color=nextpow2_color,
             linestyle=nextpow2_style,
             linewidth=curve_width)
    legends.append('Next power of 2')

    #plt.title('CDF of anonymity in the dataset '+input_file)
    plt.title('')

    plt.ylabel('Percentile')
    plt.xlabel('Anonymity set size')
    plt.legend(legends, loc='lower right')

    plt.xscale('log')
    #plt.yscale('log')

    plt.grid(color=grid_color, linestyle=grid_style, linewidth=grid_width)
    plt.tight_layout()
    dataset = input_file.replace('./', '').replace('.sizes', '')
    plt.savefig('fig4-' + str(i) + '-' + dataset + '-anonymity-cdf.eps')
Exemplo n.º 3
0
def plot(j, input_file):
    plt.figure(j)
    utils.prepare_for_latex()

    Ls = []  # the raw L's values
    Ls_count = {
    }  # a dictionary [packet size] -> [number of packets with this size]

    with open(input_file, "r") as f:
        for line in f:
            L = int(line.strip())
            if L == 0 or L == 1:
                continue
            Ls.append(L)
            if str(L) not in Ls_count:
                Ls_count[str(L)] = 0
            Ls_count[str(L)] += 1

    Bs = [getPadme(L) for L in Ls]
    Ps = [int(math.pow(2, math.ceil(math.log(L, 2)))) for L in Ls]

    Bs_count = {}
    Ps_count = {}

    for B in Bs:
        if str(B) not in Bs_count:
            Bs_count[str(B)] = 0
        Bs_count[str(B)] += 1
    for P in Ps:
        if str(P) not in Ps_count:
            Ps_count[str(P)] = 0
        Ps_count[str(P)] += 1

    Ls_buckets = bucketize(Ls_count)
    Bs_buckets = bucketize(Bs_count)
    Ps_buckets = bucketize(Ps_count)

    minLsKey = min([int(x) for x in [*Ls_buckets.keys()]])
    minBsKey = min([int(x) for x in [*Bs_buckets.keys()]])
    minPsKey = min([int(x) for x in [*Ps_buckets.keys()]])
    minKey = min(minLsKey, min(minBsKey, minPsKey))

    maxLsKey = max([int(x) for x in [*Ls_buckets.keys()]])
    maxBsKey = max([int(x) for x in [*Bs_buckets.keys()]])
    maxPsKey = max([int(x) for x in [*Ps_buckets.keys()]])
    maxKey = max(maxLsKey, max(maxBsKey, maxPsKey))

    Ls_percentageUniquePackets = extractCurves(Ls_buckets, minKey, maxKey)
    Bs_percentageUniquePackets = extractCurves(Bs_buckets, minKey, maxKey)
    Ps_percentageUniquePackets = extractCurves(Ps_buckets, minKey, maxKey)

    legends = []

    xValues = []
    i = minLsKey
    while i <= maxKey:
        xValues.append(math.pow(2, i))
        i += 1

    plt.plot(xValues,
             Ls_percentageUniquePackets,
             color=unpadded_color,
             linestyle=unpadded_style,
             linewidth=curve_width)
    legends.append('Unpadded')

    plt.plot(xValues,
             Bs_percentageUniquePackets,
             color=padme_color,
             linestyle=padme_style,
             linewidth=curve_width)
    legends.append('Padmé')

    plt.plot(xValues,
             Ps_percentageUniquePackets,
             color=nextpow2_color,
             linestyle=nextpow2_style,
             linewidth=curve_width)
    legends.append('Pow2')

    #plt.title('Anonymity set w.r.t size, '+input_file)
    plt.xlabel('File sizes [bits]')
    plt.ylabel('Percentage of unique objects [\\%]')
    plt.legend(legends, loc='upper left')

    plt.xscale('log', basex=10)
    #plt.yscale('log')

    plt.grid(color=grid_color, linestyle=grid_style, linewidth=grid_width)
    plt.tight_layout()
    dataset = input_file.replace('./', '').replace('.sizes', '')
    plt.savefig('fig5-' + str(j) + '-' + dataset +
                '-sizes-vs-anon-percentage.eps')
Exemplo n.º 4
0
        tags = build_tags(args)
        save_tags(tags, args.json)

    elif args.action == 'parse':

        if args.json:
            tags = load_tags(args.json)
        else:
            tags = build_tags(args)

        sents = get_corpus(args.lexicon, 'unparsed', args.num_sents)
        parses = parse_sents(tags, sents, args.words)
        pretty_print(sents, parses)

    elif args.action == 'analyze':

        test_data = [(filename, load_tags(filename)) for filename in args.test]
        truth_tags = load_tags(args.truth)
        parsed_sents = get_corpus(args.lexicon, 'parsed', args.num_sents)
        unparsed_sents = get_corpus(args.lexicon, 'unparsed', args.num_sents)

        (fields, truth_results,
         test_results) = analyze(parsed_sents, unparsed_sents, truth_tags,
                                 test_data, args.words)

        prepare_for_latex(args.truh, truth_results, test_results)

    else:
        ValueError(f'unrecognized command "{args.action}" (get)')
        exit(1)