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

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


  Mostrar Mensajes
Páginas: 1 ... 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [22] 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ... 74
211  Programación / Programación Visual Basic / Re: Alguien lo puede hacer mas rapido? en: 19 Agosto 2010, 19:48 pm
Código:
http://www.xbeat.net/vbspeed/cod_InStrMarzo.htm
La funcion InStr01 debe ser la mas rapida en caso de que uses vbTextCompare, si no quieres trabajar con cadenas podras alterarla para que funcione con ByteArrays ;)

El truco de esta funcion esta en sus Arrays trucados :laugh:

si he visto el enlace inclusive saque algunos tips, trabaja practicamente igual solo que este pasa una cadena como puntero y lo pasa a un array (no entendi bien eso) pero en fin da lo mismo porque yo estoy trabajando directamente con byte array.
bueno creo que es lo maximo que se pude llegar con vb, no estoy seguro ejcutandolo con ASM o declarando las apis en .tlv

Saludos.
212  Programación / Programación Visual Basic / Re: Alguien lo puede hacer mas rapido? en: 19 Agosto 2010, 03:06 am
Gracias BlackZeroX por coloaborar, esta bien reducido pero es mucho mas lenta y si pasamos archivos grandes daria error (esto ultimo no importa mucho se puede solucionar)

un bucle de 101 lamadas testeado con GetTickCount

BlackZeroX  2437
LeandroA     782

Saludos.
213  Programación / Programación Visual Basic / Re: [RETO] ¿Fácil? Buscando los números de Lychrel en: 19 Agosto 2010, 00:47 am
creo que por el momento la unica que funciona bien es la de Novlucker las demas no esta trabajando correctamente

solo tengo mis dudas con la de Novlucker  con los numeros del 1 al 9 ya que dan numeros simples y no se cumple la condición de capicua

la de raul338  tambien anda bien con el mismo problea que el de Novlucker   y tambien pero hay un problema con el 11 ya que da como resultado 11 cuando deberia ser 22


@BlackZeroX

 0 = blucle infinito
la funcion deve devolver true si no se logra el capicua en los determinados ciclos
tambien el problema del 1 al 10 pero peor, muestra erronos

@Tokes no estas devolviendo "numeroFinal" correctamente.



214  Programación / Programación Visual Basic / Alguien lo puede hacer mas rapido? en: 19 Agosto 2010, 00:03 am
Buenas esto no es un reto, solo me intriga saber si se pude crear/mejorar una funcion mas rapida que esta que hice para buscar una palabra en un archivo, la funcion trabaja con bytes y no con string, como ejemplo puse que busque una palabra existente dentro del "Explorer.exe" y un bucle de 100 vueltas para exijirle un poco a la función. Tambien comente una palabra inexistente para probar.
no discrimina por mayusculas o minusculas "deve encontrarla de cualquier forma".

Código
  1. Option Explicit
  2. Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
  3.  
  4. Private Declare Function CharUpperBuffA& Lib "user32" (lpsz As Any, ByVal cchLength&)
  5. Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  6. Private Declare Function ReadFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, ByRef lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
  7. Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
  8. Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  9. Private Declare Function GetFileSize Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpFileSizeHigh As Long) As Long
  10. Private Declare Function SetFilePointer Lib "kernel32.dll" (ByVal hFile As Long, ByVal lDistanceToMove As Long, ByRef lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
  11.  
  12. Private Type LARGE_INTEGER
  13.    lowpart As Long
  14.    highpart As Long
  15. End Type
  16.  
  17.  
  18. Private Const GENERIC_READ          As Long = &H80000000
  19. Private Const FILE_SHARE_READ       As Long = &H1
  20. Private Const OPEN_EXISTING         As Long = 3
  21. Private Const INVALID_HANDLE_VALUE  As Long = -1
  22. Private Const FILE_BEGIN            As Long = 0
  23.  
  24. Private aUChars(255) As Byte
  25.  
  26. Private Function LargeIntToCurrency(Low As Long, High As Long) As Currency
  27.    Dim LI As LARGE_INTEGER
  28.    LI.lowpart = Low: LI.highpart = High
  29.    CopyMemory LargeIntToCurrency, LI, LenB(LI)
  30.    LargeIntToCurrency = LargeIntToCurrency * 10000
  31. End Function
  32.  
  33. Private Function CurrencyToLargeInt(ByVal Curr As Currency) As LARGE_INTEGER
  34.    Curr = Curr / 10000
  35.    CopyMemory CurrencyToLargeInt, Curr, LenB(Curr)
  36. End Function
  37.  
  38.  
  39. Private Function FindWordInFile(ByVal sPath As String, ByVal sWord As String, Optional ByVal bUnicode As Boolean) As Boolean
  40.    Dim bArray() As Byte
  41.    Dim lRet As Long
  42.    Dim hFile As Long
  43.    Dim sFind() As Byte
  44.    Dim s As String
  45.    Dim t As Long
  46.    Dim i As Long
  47.    Dim FileSize As Currency
  48.    Dim tLI As LARGE_INTEGER
  49.    Dim LenBuffer As Long
  50.    Dim CurPos As Currency
  51.  
  52.    sWord = UCase(sWord)
  53.    If bUnicode Then sWord = StrConv(sWord, vbUnicode)
  54.    sFind = StrConv(sWord, vbFromUnicode)
  55.  
  56.    hFile = CreateFile(sPath, GENERIC_READ, FILE_SHARE_READ, ByVal 0&, OPEN_EXISTING, 0, 0)
  57.  
  58.    If hFile <> INVALID_HANDLE_VALUE Then
  59.  
  60.  
  61.        tLI.lowpart = GetFileSize(hFile, tLI.highpart)
  62.  
  63.        LenBuffer = &H2800 ' 10 KB
  64.  
  65.        FileSize = LargeIntToCurrency(tLI.lowpart, tLI.highpart)
  66.  
  67.        If FileSize < UBound(sFind) Then GoTo OutSearch
  68.  
  69.        If LenBuffer > FileSize Then LenBuffer = FileSize
  70.  
  71.        ReDim bArray(LenBuffer - 1)
  72.  
  73.        Do
  74.            ReadFile hFile, bArray(0), UBound(bArray) + 1, lRet, 0&
  75.  
  76.            If lRet = 0 Then Exit Do
  77.  
  78.            CurPos = CurPos + lRet
  79.  
  80.            If lRet < LenBuffer Then
  81.                ReDim Preserve bArray(lRet)
  82.            End If
  83.  
  84.            If InBytes(bArray, sFind) <> -1 Then
  85.                FindWordInFile = True
  86.                Exit Do
  87.            End If
  88.  
  89.            If CurPos = FileSize Then Exit Do
  90.  
  91.            tLI = CurrencyToLargeInt(CurPos - UBound(sFind) + 1)
  92.  
  93.            SetFilePointer hFile, tLI.lowpart, tLI.highpart, FILE_BEGIN
  94.  
  95.        Loop
  96.  
  97. OutSearch:
  98.  
  99.        CloseHandle hFile
  100.  
  101.    End If
  102. End Function
  103.  
  104.  
  105.  
  106. Public Function InBytes(ByRef bvSource() As Byte, ByRef bvMatch() As Byte) As Long
  107.  
  108.    Dim i       As Long
  109.    Dim j       As Long
  110.    Dim lChr    As Byte
  111.    Dim LenMach As Long
  112.  
  113.    LenMach = UBound(bvMatch)
  114.  
  115.    lChr = bvMatch(0)
  116.  
  117.    If LenMach > 0 Then
  118.  
  119.        For i = 0 To UBound(bvSource) - LenMach
  120.  
  121.            If (lChr = aUChars(bvSource(i))) Then
  122.  
  123.                j = LenMach - 1
  124.  
  125.                Do
  126.                    If bvMatch(j) <> aUChars(bvSource(i + j)) Then GoTo NotEqual
  127.                    j = j - 1
  128.                Loop While j
  129.  
  130.                InBytes = i
  131.  
  132.                Exit Function
  133.  
  134.            End If
  135. NotEqual:
  136.  
  137.        Next
  138.  
  139.    Else
  140.        For i = 0 To UBound(bvSource)
  141.            If (lChr = aUChars(bvSource(i))) Then
  142.                InBytes = i
  143.                Exit Function
  144.            End If
  145.        Next
  146.    End If
  147.  
  148.    InBytes = -1
  149. End Function
  150.  
  151. Private Sub Form_Initialize()
  152.    Dim i As Long
  153.  
  154.    For i = 0 To 255: aUChars(i) = i: Next
  155.    CharUpperBuffA aUChars(0), 256
  156.  
  157. End Sub
  158.  
  159. Private Sub Form_Load()
  160.    Dim t As Long, i As Long, Ret As Boolean
  161.    t = GetTickCount
  162.    For i = 0 To 100 'Este bucle es solo para exijirle un poco mas a la funcion
  163.        Ret = FindWordInFile(Environ("windir") & "\explorer.exe", "Mostrar en el escritorio", True)
  164.        'Ret = FindWordInFile(Environ("windir") & "\explorer.exe", "esta palabra no existe")
  165.    Next
  166.  
  167.    MsgBox GetTickCount - t
  168.    Me.Caption = Ret
  169.  
  170. End Sub
  171.  

PD: Complilarlo
215  Programación / Programación Visual Basic / Re: [RETO] Comprobar si un numero es Oblongo/Pronico en: 18 Agosto 2010, 01:21 am
che funciona?, no me muestra nada
Código:
Option Explicit
Dim clsIsOblongo As cIsOblongo


Private Sub Form_Load()
    Dim i   As Long
    Dim n   As Long

    Set clsIsOblongo = New cIsOblongo

    For i = 0 To 100
        If clsIsOblongo.IsOblongo(i, n) Then
            Debug.Print n, i
        End If
       
    Next i

End Sub
216  Programación / Programación Visual Basic / Re: [RETO] Comprobar si un numero es Oblongo/Pronico en: 17 Agosto 2010, 21:56 pm
[OffTopic]
estuve queriendo probar las diferencias de velocidades entre el IF, SELECT CASE, IF inline etc.
la cuestion es que vi que las funciones que se llaman primero tiene cierta ventaja con respecto a las otras, esto mismo pasa cuando queremos comparar las funciones que estamos haciendo. Es correcto esto que digo?¿?¿

esto es lo que hice
si alteran el orden de las llamadas hay ciertos cambios.

Código
  1. Option Explicit
  2.  
  3. Private CTiming As CTiming
  4.  
  5.  
  6. Private Sub Form_Load()
  7.    Dim i As Long, j As Long
  8.    Dim ValTest As Long
  9.  
  10.    Set CTiming = New CTiming
  11.  
  12.    Me.AutoRedraw = True
  13.  
  14.    Me.Print "Test de velocidad" & vbCrLf
  15.  
  16.    ValTest = 5000000
  17.  
  18.    CTiming.Reset
  19.  
  20.    For i = 0 To ValTest
  21.        For j = 1 To 4
  22.            Prueba1 j
  23.        Next
  24.    Next
  25.  
  26.    Me.Print "Prueba1 " & CTiming.sElapsed
  27.  
  28.    CTiming.Reset
  29.  
  30.    For i = 0 To ValTest
  31.        For j = 1 To 4
  32.            Prueba2 j
  33.        Next
  34.    Next
  35.  
  36.    Me.Print "Prueba2 " & CTiming.sElapsed
  37.  
  38.    CTiming.Reset
  39.  
  40.    For i = 0 To ValTest
  41.        For j = 1 To 4
  42.            Prueba3 j
  43.        Next
  44.    Next
  45.  
  46.    Me.Print "Prueba3 " & CTiming.sElapsed
  47.  
  48.    CTiming.Reset
  49.  
  50.    For i = 0 To ValTest
  51.        For j = 1 To 4
  52.            Prueba4 j
  53.        Next
  54.    Next
  55.  
  56.    Me.Print "Prueba4 " & CTiming.sElapsed
  57.  
  58.    CTiming.Reset
  59.  
  60.    For i = 0 To ValTest
  61.        For j = 1 To 4
  62.            Prueba5 j
  63.        Next
  64.    Next
  65.  
  66.    Me.Print "Prueba5 " & CTiming.sElapsed
  67.  
  68.    CTiming.Reset
  69.  
  70.    For i = 0 To ValTest
  71.        For j = 1 To 4
  72.            Prueba6 j
  73.        Next
  74.    Next
  75.  
  76.    Me.Print "Prueba6 " & CTiming.sElapsed
  77.  
  78.    CTiming.Reset
  79.  
  80.    For i = 0 To ValTest
  81.        For j = 1 To 4
  82.            Prueba7 j
  83.        Next
  84.    Next
  85.  
  86.    Me.Print "Prueba7 " & CTiming.sElapsed
  87.  
  88. End Sub
  89.  
  90.  
  91.  
  92. Private Function Prueba1(ByVal num As Long) As Long
  93.    Select Case num
  94.        Case 1
  95.            Prueba1 = 1
  96.        Case 2
  97.            Prueba1 = 2
  98.        Case 3
  99.            Prueba1 = 3
  100.        Case Else
  101.            Prueba1 = -1
  102.    End Select
  103. End Function
  104.  
  105.  
  106. Private Function Prueba2(ByVal num As Long) As Long
  107.    If num = 1 Then Prueba2 = 1 Else If num = 2 Then Prueba2 = 2 Else If num = 3 Then Prueba2 = 3 Else Prueba2 = -1
  108. End Function
  109.  
  110.  
  111. Private Function Prueba3(ByVal num As Long) As Long
  112.  
  113.    If num = 1 Then
  114.        Prueba3 = 1
  115.        Exit Function
  116.    End If
  117.  
  118.    If num = 2 Then
  119.        Prueba3 = 2
  120.        Exit Function
  121.    End If
  122.  
  123.    If num = 3 Then
  124.        Prueba3 = 3
  125.        Exit Function
  126.    End If
  127.  
  128.    Prueba3 = -1
  129.  
  130. End Function
  131.  
  132. Private Function Prueba4(ByVal num As Long) As Long
  133.  
  134.    If num = 1 Then
  135.        Prueba4 = 1
  136.    Else
  137.        If num = 2 Then
  138.            Prueba4 = 2
  139.        Else
  140.            If num = 3 Then
  141.                Prueba4 = 3
  142.            Else
  143.                Prueba4 = -1
  144.            End If
  145.        End If
  146.    End If
  147.  
  148. End Function
  149.  
  150. Private Function Prueba5(ByVal num As Long) As Long
  151.  
  152.    If num = 1 Then
  153.            Prueba5 = 1
  154.        ElseIf num = 2 Then
  155.                Prueba5 = 2
  156.            ElseIf num = 3 Then
  157.                    Prueba5 = 3
  158.                Else
  159.                    Prueba5 = -1
  160.                End If
  161.  
  162.  
  163. End Function
  164.  
  165.  
  166. Private Function Prueba6(ByVal num As Long) As Long
  167.    Prueba6 = IIf(num = 1, 1, IIf(num = 2, 2, IIf(num = 3, 3, -1)))
  168. End Function
  169.  
  170. Private Function Prueba7(ByVal num As Long) As Long
  171.    If num = 1 Then Prueba7 = 1: Exit Function
  172.    If num = 2 Then Prueba7 = 2: Exit Function
  173.    If num = 3 Then Prueba7 = 3: Exit Function
  174.    Prueba7 = -1
  175. End Function
  176.  
217  Programación / Programación Visual Basic / Re: [RETO] Comprobar si un numero es Oblongo/Pronico en: 17 Agosto 2010, 20:48 pm
lmax = Sqr(lNumb) = al numero

carajo cuando lo probe no me daba poreso restaba uno y ahora veo que si funciona.  :-\

me gusto esta (nval And &H80000000) para los negativos.

218  Programación / Programación Visual Basic / Re: [RETO] Comprobar si un numero es Oblongo/Pronico en: 17 Agosto 2010, 06:11 am
jaja eso me pasa por copiar  ;D
219  Programación / Programación Visual Basic / Re: [RETO] Comprobar si un numero es odioso en: 17 Agosto 2010, 05:49 am
Si, estuve comprobando y Cobein+Karcrack solo se va un par de milisegundos de LeandroA( aka Gilad >:D :xD)+Tokes

Ya tenemos vencedores :P !! (?)

yo pongo esta pero me siento un ladron  >:(

jajaja y si yo lo dije, de todas formas esOdiosoTokLean se lleva la copa jejej
220  Programación / Programación Visual Basic / Re: [RETO] Comprobar si un numero es Oblongo/Pronico en: 17 Agosto 2010, 05:24 am
Hola me matan las matematicas @~#~#

bueno pongo dos funciones una a lo bruto y la otra mejor es en base a la de tokes pero mas rapida.

Código
  1. Private Function IsOblongoLeo(ByVal lNumb As Long, ByRef n As Long) As Boolean
  2.    Dim R As Long
  3.    Dim lSum As Long
  4.  
  5.    If (lNumb And 1) Then Exit Function
  6.  
  7.    lSum = lNumb + 1
  8.  
  9.    R = lSum ^ 0.48
  10.    If lNumb = R * (R + 1) Then
  11.        IsOblongoLeo = True
  12.        n = R
  13.    Else
  14.        R = lSum ^ 0.49
  15.        If lNumb = R * (R + 1) Then
  16.            IsOblongoLeo = True
  17.            n = R
  18.        Else
  19.            R = lSum ^ 0.495
  20.            If lNumb = R * (R + 1) Then
  21.                IsOblongoLeo = True
  22.                n = R
  23.            Else
  24.                R = lSum ^ 0.498
  25.                If lNumb = R * (R + 1) Then
  26.                    IsOblongoLeo = True
  27.                    n = R
  28.                Else
  29.                    R = lSum ^ 0.499
  30.                    If lNumb = R * (R + 1) Then
  31.                        IsOblongoLeo = True
  32.                        n = R
  33.                    Else
  34.                        If (lNumb = 0) Or (lNumb = 2) Then n = lNumb \ 2: IsOblongoLeo = True: Exit Function
  35.                        If (lNumb = 6) Then n = 2: IsOblongoLeo = True
  36.                    End If
  37.                End If
  38.            End If
  39.        End If
  40.    End If
  41. End Function
  42.  

y esta mucho mas rapida

Código
  1. Private Function IsOblongoLeo2(ByVal lNumb As Long, ByRef n As Long) As Boolean
  2.  
  3.    Dim lmax As Long, i As Long
  4.  
  5.    If (lNumb And 1) Then Exit Function
  6.    If lNumb = 0 Then n = 0: IsOblongoLeo2 = True: Exit Function
  7.  
  8.    lmax = Sqr(lNumb)
  9.  
  10.    For i = lmax - 1 To lmax
  11.        If lNumb = i * (i + 1) Then
  12.            IsOblongoLeo2 = True
  13.            n = i
  14.            Exit Function
  15.        End If
  16.    Next
  17. End Function
  18.  

Páginas: 1 ... 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [22] 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ... 74
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines