I have selected some random testing that I have used in this post.
First I generated 10 keys and created a file with all the keys, this file will be the input for the tests. This capture don't show all the file because this is very long.
I apply the monobit test and my 4 files passed, and this means that the secuency in that the 0 and 1 repeat are not predictable:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys, random, math | |
import time | |
from scipy import stats | |
def monobit(lista): | |
sn = 0 | |
for i in range(len(lista)): | |
if int(lista[i]) == 1: | |
sn = sn + 1 | |
else: | |
sn = sn - 1 | |
sobs = math.fabs(sn)/math.sqrt(len(lista)) | |
p_value = math.erfc(sobs/math.sqrt(2)) | |
if(p_value > 0.01): | |
print 'Teste de frecuencia Monobit pasado ' + str(p_value) | |
else: | |
print 'Test de frecuencia Monobit no pasado ' + str(p_value) | |
def main(): | |
f = open("Aqui_no_hay_claves", "r") | |
texto = f.read() | |
monobit(texto) | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rachas(lista): | |
total_pi = 0 | |
for i in range(len(lista)): | |
total_pi = (int(lista[i]) + total_pi)/float(len(lista)) | |
if abs(total_pi - .5) <= (2/math.sqrt(len(lista))): | |
print "no necesitamos correr el test" | |
else: | |
r = 0 | |
v = 0 | |
for i in range(len(lista) - 1): | |
if int(lista[i]) == int(lista[i + 1]): | |
r = 0 | |
else: | |
r = 1 | |
v = v +r | |
l = len(lista) | |
pValue1 = abs(v - (2.0*l*total_pi*(1-total_pi))) | |
pValue2 = 2*sqrt(2*l)*total_pi*(1-total_pi) | |
pValue = erfc(pValue1 / pValue2) | |
if pValue >= 0.01: | |
print "Si son randoms" | |
else: | |
print "No son randoms" | |
return | |
def main(): | |
f = open("Aqui_no_hay_claves", "r") | |
texto = f.read() | |
rachas(texto) | |
main() |
The next test is I made a compress my file, and this is the result:
So, we don't have security keys, because the file is compressed 16%.
In conclusion we can say that my keys are not secure because only passed 1 test of 3.
It would have been useful to combine this into a single program so that you could run tests on any input file to determine whether it's sufficienty random. 6 pts.
ResponderEliminar