Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- import itertools
- import random
- import functools
- import operator
- def polynomial_value(polynomial, x):
- return functools.reduce(operator.xor, [polynomial[monomial] * functools.reduce(operator.mul, [x[i] for i in monomial], 1) for monomial in polynomial], 0)
- def generate_test(r, m):
- random_polynomial = dict((multi_index, round(random.uniform(0, 1))) for l in range(r + 1) for multi_index in itertools.combinations(range(m), l))
- correct_word = [polynomial_value(random_polynomial, x[::-1]) for x in itertools.product(*[[0, 1]] * m)]
- corrupted_word = correct_word[:]
- for _ in range((2 ** (m - r - 1)) - 1):
- corrupted_word[round(random.uniform(0, len(correct_word) - 1))] ^= 1
- return corrupted_word, correct_word
- if __name__ == "__main__":
- print(generate_test(2, 4))
Advertisement
Add Comment
Please, Sign In to add comment