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

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  [Reto] Barrido de Bits.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Reto] Barrido de Bits.  (Leído 4,197 veces)
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
[Reto] Barrido de Bits.
« en: 10 Junio 2011, 04:02 am »

.
Crear una función que mueva los bit's (Por si se aparece Karkrack, Cobein o similares NO ASM-Inline) a la izquierda o derecha.

(Los Números binarios se leen de izquierda a derecha, quien no tenga idea use la calculadora de windows o investigue en google como determinar el valor en Base 10).

Los ejemplos son considerando {1 Byte = 8 Bits, con el byte de signo.} la función deberá trabajar con (4 Bytes = 32 bit's = Long)

Ejemplo 1:

Se ingresa el numero  45  de desplazan 2 bit's a la izquierda el resultado es 180
es decir en binario:
00101101  {Desplazando 2 bit's Resultado--->} 10110100

Ejemplo 2:

Se ingresa el numero (-128) se desplazan 5 bit's a la izquierda el resultado es: 0
es decir en binario:
10000000 {Desplazando 5 bit's Resultado--->} 00000000

Ejemplo 3:

Se ingresa el numero 1 se desplazan 5 bit's a la izquierda el resultado es: 32
es decir en binario:
00000001 {Desplazando 5 bit's Resultado--->} 00100000

Ejemplo 4:

Se ingresa el numero 1 se desplazan 5 bit's a la derecha el resultado es: 0
es decir en binario:
00000001 {Desplazando 5 bit's Resultado--->} 00000000

Ejemplo 5:

Se ingresa el numero (-2) se desplazan 5 bit's a la derecha el resultado es: -1
es decir en binario:
11111110 {Desplazando 5 bit's Resultado--->} 11111111

Ejemplo 6:

Se ingresa el numero (-1) se desplazan 5 bit's a la derecha el resultado es: -1
es decir en binario:
11111111 {Desplazando 5 bit's Resultado--->} 11111111

Formato de la funcion:

Código
  1.  
  2. Public Function Bits_d(ByVal lVal As Long, Optional lDesplazamiento As Integer) As Long
  3. '   //  lVal                Indica el valor ingresado (Base 10).
  4. '   //  lDesplazamiento     Indica la longitud de bit's a dezplazar.
  5. '   //  Bits_d              Retorna el resultado Final (Base 10)
  6.    ...
  7. End Function
  8.  
  9.  


Edito:


Codigo para probar los resultados:

Código
  1.  
  2. Private Sub Form_Load()
  3. Dim lres        As Long
  4.    lres = DebugAndRet(Bits_d(267614144, (-1)))
  5.    lres = DebugAndRet(Bits_d(lres, (-6)))
  6.    lres = DebugAndRet(Bits_d(lres, 2))
  7.    lres = DebugAndRet(Bits_d(lres, 2))
  8.    lres = DebugAndRet(Bits_d(lres, 2))
  9.    lres = DebugAndRet(Bits_d(lres, 2))
  10.    lres = DebugAndRet(Bits_d(lres, (-2)))
  11.    lres = DebugAndRet(Bits_d(lres, (-24)))
  12. End Sub
  13.  
  14. Private Function DebugAndRet(ByVal lVal As Long) As Long
  15.    Debug.Print lVal
  16.    DebugAndRet = lVal
  17. End Function
  18.  
  19.  

Resultados en el Debug:

Código:

 535228288
-105127936
-26281984
-6570496
-1642624
-410656
-1642624
-2147483648


Resultados en Binario:
Pruebas con Test Manual...

Código:

00001111111100110111011111000000  <-- {267614144}  <--- De este binario se parte...
00011111111001101110111110000000  <-- {-01}
11111001101110111110000000000000  <-- {-06}
11111110011011101111100000000000  <-- {+02}
11111111100110111011111000000000  <-- {+02}
11111111111001101110111110000000  <-- {+02}
11111111111110011011101111100000  <-- {+02}
11111111111001101110111110000000  <-- {-02}
10000000000000000000000000000000  <-- {-24} <-- {-2147483648}


Dulces Lunas!¡.


« Última modificación: 10 Junio 2011, 21:55 pm por BlackZeroX▓▓▒▒░░ » En línea

The Dark Shadow is my passion.
raul338


Desconectado Desconectado

Mensajes: 2.633


La sonrisa es la mejor forma de afrontar las cosas


Ver Perfil WWW
Re: [Reto] Barrido de Bits.
« Respuesta #1 en: 10 Junio 2011, 04:50 am »

Interesante reto, pero la firma salio mal (o al menos desde Opera Mobile lo estoy viendo mal)

Lastima no tengo  a vb en el celular :xD


En línea

ignorantev1.1


Desconectado Desconectado

Mensajes: 617


/\ Así acabo cuando quiero programar...


Ver Perfil WWW
Re: [Reto] Barrido de Bits.
« Respuesta #2 en: 10 Junio 2011, 20:46 pm »

Código
  1. Function SHL(ByVal tStr As Long, ByVal count As Integer) As Long
  2.    Dim Bc As Integer
  3.    Dim Rc As Integer
  4.  
  5.    Bc = Int(count / 4)
  6.    Rc = count Mod 4
  7.    SHL = tStr
  8.  
  9.    For i = 1 To Bc
  10.        SHL = SHL * 16
  11.    Next
  12.  
  13.    For i = 1 To Rc
  14.        SHL = SHL * 2
  15.    Next
  16. End Function
  17.  
  18. Function SHR(ByVal tStr As String, ByVal count As Integer) As String
  19.    Dim Bc As Integer
  20.    Dim Rc As Integer
  21.  
  22.    Bc = Fix(count / 4)
  23.    Rc = count Mod 4
  24.    SHR = tStr
  25.  
  26.    For i = 1 To Bc
  27.        SHR = Fix(SHR / 16)
  28.    Next
  29.  
  30.    For i = 1 To Rc
  31.        SHR = Fix(SHR / 2)
  32.    Next
  33. End Function
  34.  
  35. Function DectoBin(ByVal tStr As String) As String
  36.    Dim cp As Variant
  37.    Dim rval As Double
  38.    tStr = Trim$(tStr)
  39.    DectoBin = ""
  40.  
  41.    rval = Val(tStr)
  42.  
  43.    While rval > 0
  44.        If Mid(tStr, Len(tStr), 1) = "1" Or Mid(tStr, Len(tStr), 1) = "3" Or Mid(tStr, Len(tStr), 1) = "5" Or Mid(tStr, Len(tStr), 1) = "7" Or Mid(tStr, Len(tStr), 1) = "9" Then
  45.            DectoBin = "1" & DectoBin
  46.            rval = rval - 1
  47.        Else
  48.            DectoBin = "0" & DectoBin
  49.        End If
  50.        rval = Fix(rval / 2)
  51.        tStr = Str$(rval)
  52.    Wend
  53.    If DectoBin = "" Then DectoBin = 0
  54. End Function
  55.  
  56. Function BintoDec(ByVal tStr As String) As String
  57.    Dim cp As Double
  58.  
  59.    BintoDec = 0
  60.    cp = 1
  61.  
  62.    For i = Len(tStr) To 1 Step -1
  63.        If i < Len(tStr) Then cp = cp * 2
  64.        BintoDec = BintoDec + Mid(tStr, i, 1) * cp
  65.    Next
  66. End Function
  67.  

Jeje pues estas funciones las hice hace tiempo cuando cree mi primer keygen para el Need For Speed Undergroud, ya que me fui explorando el programa en el OllyDbg y habiendo funciones que no entendia en si para que servian (SHL y SHR) solamente las copie, y los parametros son String y no aceptan negativos(creo)... salud!
En línea

cobein


Desconectado Desconectado

Mensajes: 759



Ver Perfil WWW
Re: [Reto] Barrido de Bits.
« Respuesta #3 en: 11 Junio 2011, 01:34 am »

Edit: ops era con longs xD

Código:
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)

Private Function ShiftL(ByVal bVal As Byte, ByVal lNumOfBits As Long) As Byte
    Dim lRet As Long
    lRet = bVal * (2 ^ lNumOfBits)
    CopyMemory ShiftL, lRet, 1
End Function
 
Private Function ShiftR(ByVal bVal As Byte, ByVal lNumOfBits As Long) As Byte
    ShiftR = bVal \ (2 ^ lNumOfBits)
End Function
« Última modificación: 11 Junio 2011, 01:35 am por cobein » En línea

http://www.advancevb.com.ar
Más Argentino que el morcipan
Aguante el Uvita tinto, Tigre, Ford y seba123neo
Karcrack es un capo.
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: [Reto] Barrido de Bits.
« Respuesta #4 en: 11 Junio 2011, 03:20 am »

.
Aquí dejo mi función antes de que Cobein la haga x¨P.

Código
  1.  
  2. Private Function Bits_d(ByVal lVal As Long, ByVal lD As Integer) As Long
  3. '   //  lVal    Indica el valor al cual se le dezplazaran los Bit's.
  4. '   //  lD      Indica hacia donde se dezplazan los bits, si son menores a 0 a la izquierda de lo contrario si son mayores a 0 a la derecha.
  5. '   //  Bits_d  Retorna el Valor final con los Bits desplazados.
  6.    If (lD > &H0) And (lD < &H20) Then
  7.        Do
  8.            lVal = SwapBitR(lVal)
  9.            lD = (lD - 1)
  10.        Loop Until (lD = &H0)
  11.    ElseIf (lD < &H0) And (lD > (&HFFFFFFE1)) Then
  12.        Do
  13.            lVal = SwapBitL(lVal)
  14.            lD = (lD + 1)
  15.        Loop Until (lD = &H0)
  16.    ElseIf (lD > &H1F) Then
  17.        If ((lVal And &H80000000) = &H80000000) Then
  18.            lVal = &HFFFFFFFF
  19.        Else
  20.            lVal = &H0
  21.        End If
  22.    ElseIf (lD < &HFFFFFFE1) Then
  23.        lVal = &H0
  24.    End If
  25.    Bits_d = lVal
  26. End Function
  27.  
  28. Public Function SwapBitL(ByVal lVal As Long) As Long
  29.    SwapBitL = (lVal And &H7FFFFFFF)
  30.    If ((SwapBitL And &H40000000) = &H40000000) Then
  31.        SwapBitL = (SwapBitL And &H7FFFFFFF)        'SwapBitL = ((SwapBitL Xor &H40000000) And &H7FFFFFFF)
  32.        SwapBitL = ((SwapBitL + SwapBitL) Or &H80000000)
  33.    Else
  34.        SwapBitL = (SwapBitL + SwapBitL)
  35.    End If
  36. End Function
  37.  
  38. Public Function SwapBitR(ByVal lVal As Long) As Long
  39.    If Not ((lVal And &HFFFFFFFF) = &HFFFFFFFF) Then
  40.        SwapBitR = (lVal \ &H2)
  41.    Else
  42.        SwapBitR = lVal
  43.    End If
  44. End Function
  45.  
  46.  


Código
  1.  
  2. Private Function ShiftL(ByVal bVal As Byte, ByVal lNumOfBits As Long) As Byte
  3.    ShiftL = (bVal * (2 ^ lNumOfBits)) And &HFF ' //  El copymemory se puede sustituir por una mascara...
  4. End Function
  5.  
  6.  

Temibles Lunas!¡.
« Última modificación: 11 Junio 2011, 18:51 pm por BlackZeroX▓▓▒▒░░ » En línea

The Dark Shadow is my passion.
Karcrack


Desconectado Desconectado

Mensajes: 2.416


Se siente observado ¬¬'


Ver Perfil
Re: [Reto] Barrido de Bits.
« Respuesta #5 en: 11 Junio 2011, 16:14 pm »

Código
  1. Public Static Function ShiftLeft05(ByVal Value As Long, ByVal ShiftCount As Long) As Long
  2. ' by Jost Schwider, jost@schwider.de, 20010928
  3.  Dim Pow2(0 To 31) As Long
  4.  Dim i As Long
  5.  Dim mask As Long
  6.  
  7.  Select Case ShiftCount
  8.  Case 1 To 31
  9.  
  10.    'Ggf. Initialisieren:
  11.    If i = 0 Then
  12.      Pow2(0) = 1
  13.      For i = 1 To 30
  14.        Pow2(i) = 2 * Pow2(i - 1)
  15.      Next i
  16.    End If
  17.  
  18.    'Los gehts:
  19.    mask = Pow2(31 - ShiftCount)
  20.    If Value And mask Then
  21.      ShiftLeft05 = (Value And (mask - 1)) * Pow2(ShiftCount) Or &H80000000
  22.    Else
  23.      ShiftLeft05 = (Value And (mask - 1)) * Pow2(ShiftCount)
  24.    End If
  25.  
  26.  Case 0
  27.  
  28.    ShiftLeft05 = Value
  29.  
  30.  End Select
  31. End Function
Código:
http://xbeat.net/vbspeed/c_ShiftLeft.htm#ShiftLeft05
Código
  1. Public Function ShiftRight08(ByVal Value As Long, ByVal ShiftCount As Long) As Long
  2. ' by Jost Schwider, jost@schwider.de, 20011010
  3.  Select Case ShiftCount
  4.  Case 0&:  ShiftRight08 = Value
  5.  Case 1&:  ShiftRight08 = (Value And &HFFFFFFFE) \ &H2&
  6.  Case 2&:  ShiftRight08 = (Value And &HFFFFFFFC) \ &H4&
  7.  Case 3&:  ShiftRight08 = (Value And &HFFFFFFF8) \ &H8&
  8.  Case 4&:  ShiftRight08 = (Value And &HFFFFFFF0) \ &H10&
  9.  Case 5&:  ShiftRight08 = (Value And &HFFFFFFE0) \ &H20&
  10.  Case 6&:  ShiftRight08 = (Value And &HFFFFFFC0) \ &H40&
  11.  Case 7&:  ShiftRight08 = (Value And &HFFFFFF80) \ &H80&
  12.  Case 8&:  ShiftRight08 = (Value And &HFFFFFF00) \ &H100&
  13.  Case 9&:  ShiftRight08 = (Value And &HFFFFFE00) \ &H200&
  14.  Case 10&: ShiftRight08 = (Value And &HFFFFFC00) \ &H400&
  15.  Case 11&: ShiftRight08 = (Value And &HFFFFF800) \ &H800&
  16.  Case 12&: ShiftRight08 = (Value And &HFFFFF000) \ &H1000&
  17.  Case 13&: ShiftRight08 = (Value And &HFFFFE000) \ &H2000&
  18.  Case 14&: ShiftRight08 = (Value And &HFFFFC000) \ &H4000&
  19.  Case 15&: ShiftRight08 = (Value And &HFFFF8000) \ &H8000&
  20.  Case 16&: ShiftRight08 = (Value And &HFFFF0000) \ &H10000
  21.  Case 17&: ShiftRight08 = (Value And &HFFFE0000) \ &H20000
  22.  Case 18&: ShiftRight08 = (Value And &HFFFC0000) \ &H40000
  23.  Case 19&: ShiftRight08 = (Value And &HFFF80000) \ &H80000
  24.  Case 20&: ShiftRight08 = (Value And &HFFF00000) \ &H100000
  25.  Case 21&: ShiftRight08 = (Value And &HFFE00000) \ &H200000
  26.  Case 22&: ShiftRight08 = (Value And &HFFC00000) \ &H400000
  27.  Case 23&: ShiftRight08 = (Value And &HFF800000) \ &H800000
  28.  Case 24&: ShiftRight08 = (Value And &HFF000000) \ &H1000000
  29.  Case 25&: ShiftRight08 = (Value And &HFE000000) \ &H2000000
  30.  Case 26&: ShiftRight08 = (Value And &HFC000000) \ &H4000000
  31.  Case 27&: ShiftRight08 = (Value And &HF8000000) \ &H8000000
  32.  Case 28&: ShiftRight08 = (Value And &HF0000000) \ &H10000000
  33.  Case 29&: ShiftRight08 = (Value And &HE0000000) \ &H20000000
  34.  Case 30&: ShiftRight08 = (Value And &HC0000000) \ &H40000000
  35.  Case 31&: ShiftRight08 = CBool(Value And &H80000000)
  36.  End Select
  37.  
Código:
http://xbeat.net/vbspeed/c_ShiftRight.htm#ShiftRight08
En línea

Tokes

Desconectado Desconectado

Mensajes: 140


Ver Perfil
Re: [Reto] Barrido de Bits.
« Respuesta #6 en: 11 Junio 2011, 16:39 pm »

Saludos a todos. Aquí dejo mi código:

Código:
Private Function Bits_d_tks(ByVal d As Long, ByVal n As Long) As Long
    If n And &H80000000 Then
        n = -n
        While n > 0
            d = desp_1pos_izq(d)
            n = n - 1
        Wend
    Else
        While n > 0
            d = desp_1pos_der(d)
            n = n - 1
        Wend
    End If
    Bits_d_tks = d
End Function

Private Function desp_1pos_izq(ByVal num As Long) As Long
Dim i As Long, b As Long

    b = 1
    For i = 0 To 29
        If num And b Then
            b = b * 2
            desp_1pos_izq = desp_1pos_izq Or b
        Else
            b = b * 2
        End If
    Next
    
    If num And &H40000000 Then
        desp_1pos_izq = desp_1pos_izq Or &H80000000
    End If
End Function

Private Function desp_1pos_der(ByVal num As Long) As Long
    If num <> &HFFFFFFFF And num <> 0 Then
        num = num \ 2
    End If
    desp_1pos_der = num
End Function
« Última modificación: 11 Junio 2011, 18:29 pm por Tokes » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
ayuda con un comparador de 16 bits y otro d 4 bits en complemento a2
Electrónica
basileia 0 3,845 Último mensaje 22 Abril 2006, 18:38 pm
por basileia
Barrido de Busqueda de Documentos en Direcotiros
Java
cyberserver 4 3,750 Último mensaje 5 Diciembre 2009, 09:25 am
por cyberserver
Programa barrido direcciones IP con puertos abiertos
Seguridad
javier234- 6 7,656 Último mensaje 23 Diciembre 2010, 17:24 pm
por Arcano.
komo escanear una red sin barrido ping tradicional
Hacking
WebRipper 2 5,141 Último mensaje 7 Junio 2011, 19:00 pm
por el-brujo
El escaner no termina el barrido
GNU/Linux
unusuario 5 2,343 Último mensaje 4 Enero 2016, 22:40 pm
por unusuario
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines