elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado:


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  ayuda a comentar codigo python
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ayuda a comentar codigo python  (Leído 1,919 veces)
bengy


Desconectado Desconectado

Mensajes: 501


mis virtudes y defectos son inseparables


Ver Perfil WWW
ayuda a comentar codigo python
« en: 3 Septiembre 2016, 22:41 pm »

este codigo es de github https://github.com/overxfl0w/Typing-Recognition se trata de identificacion por dinamica de tecleo y me gustaria comentarlo para poder entender mejor, en especial la funcion _nErrors
Código
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import win32api
  5. import win32con
  6. import sys
  7. import time
  8. import pickle
  9.  
  10. def _clear():
  11.    for i in xrange(30): print "\n"
  12.  
  13. def _nErrors(a,b,B,I,S):
  14. V = {}
  15. V[0,0] = 0
  16. for i in xrange(1,len(b)+1): V[0,i] = i
  17. for i in xrange(1,len(a)+1): V[i,0] = i
  18. for i in xrange(1,len(a)+1):
  19. for j in xrange(1,len(b)+1):
  20. V[i,j] = min(V[i-1,j]+B(a,i-1),V[i,j-1]+I(b,j-1),V[i-1,j-1]+S(a,i-1,b,j-1))
  21. return V[len(a),len(b)]
  22.  
  23. def _generateSample():
  24.    _clear()
  25.    print u"Teclea: El veloz 1 murcielago hindu 2 comia feliz cardillo 3 y kiwi 5. La cigueña tocaba el 6 saxofon 1 detras del palenque 9 de paja. - Escrutinio 1337"
  26.    m,sentence,times,l,replace,it,et,p       = 0,[],[],0,{190:46,188:44,189:45,192:241},0,0,0
  27.    gs = u"El veloz 1 murcielago hindu 2 comia feliz cardillo 3 y kiwi 5. La cigueña tocaba el 6 saxofon 1 detras del palenque 9 de paja. - Escrutinio 1337"
  28.    es = ""
  29.    ls = len(gs)
  30.    while True and l!=ls:
  31. for i in xrange(256):
  32.    k = win32api.GetAsyncKeyState(i)
  33.    if k==-32767:
  34. if i==16 or i==160: m=1
  35. elif i>=65 and i<=90:
  36.    if m==1: sentence.append(unichr(i))
  37.    else:    sentence.append(unichr(i+32))
  38.    et = time.clock()
  39.    times.append(et-it)
  40.    m,l,it = 0,l+1,et
  41. else:
  42.    if i==8 and len(sentence)>0 and len(times)>0: sentence = sentence[:-1] ; l = max(l-1,0) ; times = times[:-1]
  43.    else:
  44. if i!=1 and i!=13:
  45.    sentence.append(unichr(i) if i not in replace else unichr(replace[i]))
  46.    et = time.clock()
  47.    times.append(et-it)
  48.    l,it = l+1,et
  49. _clear()
  50. print gs
  51. sys.stdout.write("".join(sentence))
  52. sys.stdout.flush()
  53.    es = "".join(sentence)
  54.    nErrors = _nErrors(gs,es,lambda x,i:1,lambda x,i:1,lambda x,i,y,j: 0 if x[i]==y[j] else 1)
  55.    v = times+[nErrors]
  56.    return v
  57.  
  58. if __name__ == "__main__":
  59.    if len(sys.argv)>1:
  60. v = _generateSample()
  61. with open(sys.argv[1],"wb") as fd: pickle.dump(v,fd)
  62.    else: print "Especifica el nombre del fichero para almacenar el patron"
  63.  
  64.  


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[Python] (Ayuda) Código ofuscado.
Scripting
adrianmendezRap 8 7,665 Último mensaje 21 Abril 2012, 15:16 pm
por adrianmendezRap
Ayuda a desofuscar codigo python
Scripting
CADi 3 5,719 Último mensaje 2 Agosto 2013, 21:35 pm
por 0x5d
Hola !!! me pueden ayudar a comentar un codigo que no entiendo en c++
Programación C/C++
Franck_Javi13 1 2,302 Último mensaje 10 Diciembre 2013, 15:50 pm
por Sputnik_
Problema con comentar bloques en Python 3 (Resuelto)
Scripting
lucas25cba 4 4,143 Último mensaje 28 Octubre 2015, 14:59 pm
por Pablo Videla
Saludos y ayuda con código Python
Scripting
PUAROT 3 2,426 Último mensaje 5 Enero 2016, 12:58 pm
por PUAROT
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines