示例#1
0
def distribution_to_TeX(p):
    """Formats distribution for use in TeX file.

    Args:
      p: A dictionary with entries for 'distr', 'sigma', 'a', 'D'

    Returns:
      LaTeX string.
    """

    distr, sigma, a, distr_name = p['distr'], p['sigma'], p['a'], p['D']

    n = max(distr.iterkeys()) + 1  # range is [0..n)
    b = bits_needed_to_sample(distr)
    ret = "${}$ & {} & {:.2f} & ".format(distr_name, b + 1, sigma**2)

    for i in sorted(distr.iterkeys()):
        if i >= 0:
            p = int(round(distr[i] * 2**b))
            if i == 0:
                p *= 2
            ret += r"\!\!{}\!\!&".format(p)

    for i in xrange(max(distr.iterkeys()), 6):
        ret += "&"

    divergence = renyi(distr, nonnegative_half(dgauss(sigma)), a)
    ret += " {:.1f} & {:.7f}".format(a, divergence)
    return ret + r" \\"
示例#2
0
    def print_intermediate_result(opt_d, qlog, n, w, sigma, bandwidth,
                                  heuristic_pr_failure, actual_pr_failure,
                                  costs_gauss, costs_opt):

        print distr_to_str(nonnegative_half(opt_d))
        print "q = 2**{}, n = {}, w = {}, sigma^2 = {:.2f}:".format(
            qlog, n, w, sigma**2),
        print "bandwidth = {:.2f} KB,".format(bandwidth / (8. * 1000)),

        print(
            "heuristic Pr of failure = {:.1f}, "
            "actual Pr of failure = {:.1f},".format(
                log(heuristic_pr_failure, 2), log(actual_pr_failure, 2))),

        formatted_costs = ", ".join("{:.1f}".format(c) for c in costs_gauss
                                    if not isinf(c))
        print "security = [{}],".format(formatted_costs),

        if reduce_to_LWE or not binomials_only:
            formatted_costs_opt = ", ".join("{:.1f}".format(c)
                                            for c in costs_opt if not isinf(c))
            print "security after reduction = [{}],".format(
                formatted_costs_opt),

        if binomials_only:
            bits = int(round(4 * sigma**2)) + 1
        else:
            bits = bits_needed_to_sample(opt_d)
        print "distribution on [{}, {}], {} bits to sample".format(
            min(opt_d.iterkeys()), max(opt_d.iterkeys()), bits)

        print "Parameters for print_tables.py: 'sigma': sqrt({:.2f}), 'n': {}, 'q': {}, 'B': {}, 'bits': {}, 'base': {:.0f}".format(
            sigma**2, n, qlog, w, bits, min(costs_gauss))
示例#3
0
def distribution_to_tex(p):
    """Formats distribution for use in TeX file.

  Args:
    p: A dictionary with entries for 'distr', 'sigma', 'a', 'name'

  Returns:
    LaTeX string.
  """

    distr, sigma, a, distr_name = p['distr'], p['sigma'], p['a'], p['name']

    dg = dgauss(sigma)

    b = bits_needed_to_sample(distr)
    ret = '{} & {:.3f} &'.format(distr_name, sigma)

    for i in sorted(distr.iterkeys()):
        if i >= 0:
            p = int(round(distr[i] * 2**b))
            if i == 0:
                p *= 2
            ret += r'\!\!{}\!\!&'.format(p)

    for i in range(max(distr.iterkeys()), 12):
        ret += '&'

    divergence = renyi(distr, nonnegative_half(dg), a)
    ret += r' {:.1f} & ${:.2f}\times 10^{{-4}}$'.format(a, divergence * 10**4)
    return ret + r' \\'
示例#4
0
    def print_intermediate_result(opt_d, qlog, n, w, m_bar, n_bar, sigma,
                                  bandwidth, heuristic_pr_failure,
                                  actual_pr_failure, costs_gauss, costs_opt):
        """A printer helper.
    """
        print(distr_to_str(nonnegative_half(opt_d)))
        print(
            'q = 2**{}, n = {}, w = {}, mbar x nbar = {} x {}, sigma = {:.3f}:'
            .format(qlog, n, w, m_bar, n_bar, sigma),
            end='')
        print('bandwidth = {:.2f} kB,'.format(bandwidth / (8. * 1000))),

        print(
            'heuristic Pr of failure = {:.1f}, '
            'actual Pr of failure = {:.1f},'.format(
                log(heuristic_pr_failure) / log(2),  # can be 0
                log(actual_pr_failure) / log(2)),  # can be 0
            end='')

        formatted_costs = ', '.join('{:.1f}'.format(c) for c in costs_gauss
                                    if not isinf(c))
        print('security = [{}],'.format(formatted_costs), end='')

        formatted_costs_opt = ', '.join('{:.1f}'.format(c) for c in costs_opt
                                        if not isinf(c))
        print('security after reduction = [{}],'.format(formatted_costs_opt),
              end='')

        bits = bits_needed_to_sample(opt_d)
        print('distribution on [{}, {}], {} bits to sample'.format(
            min(opt_d.iterkeys()), max(opt_d.iterkeys()), bits))

        print("Parameters for print_tables_pke.py: 'sigma': {:.3f}, 'n': {}, "
              "'m_bar':{}, 'n_bar':{}, 'q': {}, 'B': {}, 'key_len': {}, "
              "'rand_bits': {}, 'sec_base': {:.0f}".format(
                  sigma, n, m_bar, n_bar, qlog, w, agree_bits, bits,
                  min(costs_gauss)))