コード例 #1
0
def should_drop_packet(packet, add_line=True, scale=1.0):
    rand = random()
    dna_data = "".join(string2QUATS(packet))
    drop_chance, data, _ = DNARules.apply_all_rules_with_data(dna_data)
    drop_chance = scale * drop_chance
    if add_line:
        line = ("random_bytes," + ",".join([str(round(x, 4)) for x in data]) +
                "," + str(drop_chance) + "," + str(rand) + "," +
                str(drop_chance > rand))
        lines.append(line)
    # drop packet if rand bigger than the drop_chance for this Packet.
    return drop_chance > rand
コード例 #2
0
def should_drop_packet(packet, add_line=True, scale=1.0):
    if not useDNARules:
        return False
    rand = random()
    drop_chance, data, _ = DNARules.apply_all_rules_with_data(packet)
    drop_chance = scale * drop_chance
    if add_line:
        line = (algo_type[0] + "," + str(hex(packet.getCRC())) + "," +
                ",".join([str(round(x, 4))
                          for x in data]) + "," + str(drop_chance) + "," +
                str(rand) + "," + str(drop_chance > rand))
        lines.append(line)
    return drop_chance > rand
コード例 #3
0
def permute(data, add_line=True):
    dna_data = "".join(string2QUATS(data))
    drop_chance, data, _ = DNARules.apply_all_rules_with_data(dna_data)
    drop_chance = 0.01 * drop_chance
    if add_line:
        line = ("ReedSolomon" + "," + str() + "," +
                ",".join([str(round(x, 4))
                          for x in data]) + "," + str(drop_chance))
        lines.append(line)
    lim_drop_chance = min(drop_chance, 0.9999999)
    number_of_permutations = int(math.ceil(lim_drop_chance * len(dna_data)))
    dna_data = list(dna_data)
    for i in range(number_of_permutations):
        dna_data[i] = flip_base(
            dna_data[i])  # flip the dna-base to an incorrrect one
    data = b""
    for x in list(zip(*[iter(dna_data)] * 4)):
        data += quats_to_bytes("".join(x))
    return data