Exemple #1
0
def parse_args(args):
    k = args.k
    n = args.n
    msgStr = args.msg
    gen_matrix = args.m
    error_chance = args.e
    gen_matrix = _resolve_matrix(gen_matrix, k, n)
    msg = parser.vector_to_list(msgStr)
    _validate_error_chance(error_chance)
    return k, n, msg, gen_matrix, error_chance
def validate_vector(vector: str):
    # checks if value fields contained a value
    _validate_not_empty(vector, "Vector must be provided.")
    # checks if vector contains only binary characters
    if not _vector_consist_of_0_and_1(vector):
        raise ValidationError(
            f"Invalid vector value - ({vector}). It must only contain values of 0 and 1"
        )
    # converts vector string to list of binary values
    vector = parser.vector_to_list(vector)
    return vector
def validate_error_vector(error_vector_str: str, encoded_vector: [int]):
    # checks if value field contained a value
    _validate_not_empty(
        error_vector_str,
        f"Invalid error vector value. It must must contain at least one character"
    )
    # checks if error vector contains only binary characters
    if not _vector_consist_of_0_and_1(error_vector_str):
        raise ValidationError(
            f"Invalid error vector value - ({error_vector_str}). It must only contain values of 0 and 1"
        )
    # converts error vector string to list of digits
    error_vector = parser.vector_to_list(error_vector_str)
    # checks if error vector length is the same as encoded vector length
    if len(error_vector) != len(encoded_vector):
        raise ValidationError(
            f"Invalid error vector value - ({error_vector_str}). It must be same length as encoded vector"
        )
    return error_vector
Exemple #4
0
 def test_vector_str_vector_5(self):
     input = [1, 1, 0, 0, 1]
     string = parser.list_to_vector(input)
     output = parser.vector_to_list(string)
     self.assertEqual(input, output)
Exemple #5
0
def text_to_bits(text: str) -> [int]:
    """Converts any text to list of 0 and 1"""
    binary_text = text.encode('utf-8')
    bit_str = ''.join(format(b, '08b') for b in binary_text)
    bit_vector = parser.vector_to_list(bit_str)
    return bit_vector