예제 #1
0
def generate_incr_space(word_size:int):
    """Return a list of all word_size bit binary numbers."""
    space = []
    for i in range(2**word_size):
        a = Binary(i) % word_size
        a = a.split_string()
        space.append(a)
    return space
예제 #2
0
def test_split_string():
    a = '1111000011110000'
    b = Binary(a)

    A = b.split_string(a)
    B = b.split_string(b)
    C = b.split_string()
    D = b.split_string(a, 8)
    with pytest.raises(AssertionError):
        E = b.split_string(a, 3)

    expected_result_1 = (Binary('1111'), Binary('0000'), Binary('1111'),
                         Binary('0000'))

    expected_result_2 = (Binary('11'), Binary('11'), Binary('00'),
                         Binary('00'), Binary('11'), Binary('11'),
                         Binary('00'), Binary('00'))

    assert A == expected_result_1
    assert B == expected_result_1
    assert C == expected_result_1
    assert D == expected_result_2
예제 #3
0
def generate_random_flipped_space(X:Binary, runs=None):
    if runs is None:
        runs == 1000 #2**len(X)
    
    space = [X]
    a = Binary()
    for i in range(runs):
        X = a.combine_string(X)
        
        X.flip_random_bit()
        X = a.split_string(X)
        space.append(X)
    return space
예제 #4
0
def random_flips(function=QR, word_size:int=12):
    X = Binary()#'0000000000000000')
    X.gen_random(word_size)
    X = X.split_string()
    Y = function(X)

    HD_lists = []
    for i in range(100):
        Xs = generate_random_flipped_space(X, runs=100)
        #Ys = QR_on_list(Xs)
        Ys = []
        for X_i in Xs:
            Ys.append(function(X_i))
        

        Y_base = [Y] * len(Ys)
        HDs = HDs_of_lists(Y_base, Ys)
        HD_lists.append(HDs)
    
    return HD_lists
예제 #5
0
def incremental_space(function=QR, word_size:int = 12):
    X = Binary()#'0000000000000000')
    X.gen_random(word_size)
    X = X.split_string()
    Y = function(X)

    Xs = generate_incr_space(word_size)
    #Ys = QR_on_list(Xs)
    Ys = []
    for X in Xs:
        Ys.append(function(X))
    

    Y_base = [Y] * len(Ys)
    HDs = HDs_of_lists(Y_base, Ys)

    multi_line_chart(
        lines=[HDs],
        title='HDs of incremental outputs',
        x_label='bits',
        y_label='Hamming distance and weight'
    )
예제 #6
0
def rotate_all(X, bits=1):
    string = Binary().combine_string(X)
    bin_string = Binary(string)
    bin_string = bin_string // bits
    Y = bin_string.split_string()
    return Y