Ejemplo n.º 1
0
def analyse_faux_positif():
    """
    Algorithme de la Question 4.3
    """
    file=open('res.txt','w') #contiendra le résultat
    mots_testes=0
    faux_positifs=0
    liste_mots_aleatoires=[]
    for mot_a_inserer in range (2**10+1):
        liste_mots_aleatoires += [random_word()] #création des 2^10 mots aléatoires
        
    for nombre_fonctions in range (1,9):
        for taille_table in range (10,21):
            bf= bloomfilter.create(taille_table,code_of_string,nombre_fonctions)
            for mot in liste_mots_aleatoires: #insertion de tous les mots de la liste dans le filtre de Bloom
                bloomfilter.add(bf,mot)
            for mot_test in range (2**14): #test de 2^14 autres mots aléatoires
                mot = random_word()
                if mot not in liste_mots_aleatoires:
                    mots_testes+=1
                    if bloomfilter.contains(bf,mot) == True:
                        faux_positifs+=1
            file.write(str(taille_table )+ " " + str(nombre_fonctions) + " " + str(mots_testes) + " " + str(faux_positifs) + " " + str(round((faux_positifs/mots_testes),6))+ "\n") #écriture de la ligne
            mots_testes=0
            faux_positifs=0 #réinitialisation des valeurs
        file.write("\n\n") #séparation avant ajout d'une fonction de hachage
Ejemplo n.º 2
0
def test():
    resultat = ""
    file = open('res.txt', 'w')
    faux_pos = 0
    mot_test = 0
    I = list()

    for i in range(0, 10):
        I.append(random_word())

    for n in range(1, 8):
        for t in range(10, 20):
            resultat = ""
            bf = bloomfilter.create(t, code_of_string, n)
            for i in I:
                bloomfilter.add(bf, i)
            for k in range(1, 2**14):
                U = random_word()
                if not (U in I):
                    mot_test += 1
                    if (bloomfilter.contains(bf, U)):
                        faux_pos += 1
            resultat += str(t) + " " + str(n) + " " + str(k) + " " + str(
                mot_test) + " " + str(faux_pos) + " " + str(
                    faux_pos / k) + "\n"
            file.write(resultat)
        file.write('\n\n')
    file.close()
Ejemplo n.º 3
0
def analyse_faux_positif():
    """
    Algorithme de la Question 4.3
    """
    file = open('res.txt', 'w')
    mots_testes = 0
    faux_positifs = 0
    liste_mots_aleatoires = []
    for mot_a_inserer in range(2**10 + 1):
        liste_mots_aleatoires += [random_word()]

    for n in range(1, 9):
        for t in range(10, 21):
            bf = bloomfilter.create(t, code_of_string, n)
            for mot in liste_mots_aleatoires:  #
                bloomfilter.add(bf, mot)
            for mot_test in range(1, (2**14) + 1):
                mot = random_word()
                if mot not in liste_mots_aleatoires:
                    mots_testes += 1
                    if bloomfilter.contains(bf, mot) == True:
                        faux_positifs += 1
            file.write(
                str(t) + " " + str(n) + " " + str(mots_testes) + " " +
                str(faux_positifs) + " " +
                str(round((faux_positifs / mots_testes), 6)) +
                "\n")  #écriture de la ligne
            mots_testes = 0
            faux_positifs = 0  #réinitialisation des valeurs
        file.write("\n\n")  #séparation avant ajout d'une fonction de hachage
Ejemplo n.º 4
0
def test_filterload():
    bf = bloomfilter.init(10, 5, 99)
    item = b'Hello World'
    bf = bloomfilter.add(bf, item)
    msg = network.gen_msg(b'filterload', network.serialize_filterload(bf), True)
    msg_bytes = network.serialize_msg(msg)
    msg_bytes_hex = msg_bytes.hex()
    expected = '0000000a080000000140'
    print(msg_bytes_hex)
    print(expected)
    print(expected in msg_bytes_hex)
    assert (expected in msg_bytes_hex) is True

    item = b'Goodbye!'
    bf = bloomfilter.add(bf, item)
    msg = network.gen_msg(b'filterload', network.serialize_filterload(bf), True)
    msg_bytes = network.serialize_msg(msg)
    msg_bytes_hex = msg_bytes.hex()
    expected = '4000600a080000010940'
    assert (expected in msg_bytes_hex) is True
Ejemplo n.º 5
0
    bf = bloomfilter.create(4,code_of_string,8)
    w = random_word()
    bloomfilter.add(bf,"timoleon")
    if bloomfilter.contains(bf,"timoleon"):
        print("%s est present" % ("timoleon"))
    if bloomfilter.contains(bf,w):
        print("%s est present" % (w))
    """
    listRandomWords = [random_word() for k in range(2**10)]
    for n in range(1, 9):
        cpTested = 0
        cpPositif = 0
        for t in range(10, 21):
            bf = bloomfilter.create(t, code_of_string, n)
            for i in range(2**10):
                bloomfilter.add(bf, listRandomWords[i])
            for k in range(2**14):
                u = random_word()
                if not (u in listRandomWords):
                    cpTested += 1
                    if bloomfilter.contains(bf, u):
                        cpPositif += 1
            print(t, end=" ")
            print(n, end=" ")
            print(cpTested, end=" ")
            print(cpPositif, end=" ")
            print(cpPositif / cpTested)
            cpTested = 0
            cpPositif = 0
        print("\n")
Ejemplo n.º 6
0
    Returns a word with random letters whose length is between 4 and 7.

    :rtype: string
    """
    letters = [ chr(i) for i in range(ord('a'),ord('z')+1) ] + [ chr(i) for i in range(ord('A'),ord('Z')+1) ]
    length = 4 + random.randint(0,4)
    str = ""
    for i in range(length):
        str = str + random.choice(letters)
    return str

if __name__ == "__main__":
    init_random_tab()
    bf = bloomfilter.create(6,code_of_string,8)
    w = random_word()
    bloomfilter.add(bf,"timoleon")
    if bloomfilter.contains(bf,"timoleon"):
        print("%s est present" % ("timoleon"))
    if bloomfilter.contains(bf,w):
        print("%s est present" % (w))

    stream=open("res.txt","w")
    init_random_tab()
    liste_mots = []
    i = 0
    while(i<2**10):
        w = random_word()
        if w not in liste_mots:
            liste_mots.append(w)
            i += 1
    for n in range(1,9):