예제 #1
0
def shuffle(x, config=None, value_type=sgf2n, reverse=False):
    """ Simulate secure shuffling with Waksman network for 2 players.


    Returns the network switching config so it may be re-used later.  """
    n = len(x)
    if n & (n - 1) != 0:
        raise CompilerError('shuffle requires n a power of 2')
    if config is None:
        config = permutation.configure_waksman(permutation.random_perm(n))
        for i, c in enumerate(config):
            config[i] = [value_type(b) for b in c]
    permutation.waksman(x, config, reverse=reverse)
    permutation.waksman(x, config, reverse=reverse)

    return config
예제 #2
0
def shuffle(x, config=None, value_type=sgf2n, reverse=False):
    """ Simulate secure shuffling with Waksman network for 2 players.


    Returns the network switching config so it may be re-used later.  """
    n = len(x)
    if n & (n-1) != 0:
        raise CompilerError('shuffle requires n a power of 2')
    if config is None:
        config = permutation.configure_waksman(permutation.random_perm(n))
        for i,c in enumerate(config):
            config[i] = [value_type(b) for b in c]
    permutation.waksman(x, config, reverse=reverse)
    permutation.waksman(x, config, reverse=reverse)

    return config