Results 1 to 2 of 2

Thread: Packet Compression

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517

    Packet Compression

    OK. I figured out how to compress strings! No one here knew howto, so I think it might be useful to look at this.

    Heres an ip address...

    127.234.111.133 (32 byte string)
    êo… (8 bytes)

    Both are the same IP address. Both are in string format.

    the later is converted with this code, which can easily be converted back a minute later.

    This isnt encryption by any means.

    Its the exact way your computer stores information.


    VB Code:
    1. Public Function MakeDWORD(Data As Long) As String
    2.     Dim tmp As String, a As String, b As String, c As String, d As String
    3.     tmp = Right("00000000" & Hex(Data), 8)
    4.     a = Mid(tmp, 1, 2)
    5.     b = Mid(tmp, 3, 2)
    6.     c = Mid(tmp, 5, 2)
    7.     d = Mid(tmp, 7, 2)
    8.     MakeDWORD = Chr(Val("&H" & d))
    9.     MakeDWORD = MakeDWORD & Chr(Val("&H" & c))
    10.     MakeDWORD = MakeDWORD & Chr(Val("&H" & b))
    11.     MakeDWORD = MakeDWORD & Chr(Val("&H" & a))
    12. End Function
    13.  
    14. Public Function MakeWORD(Data As Integer) As String
    15.     Dim tmp As String, a As String, b As String
    16.     tmp = Right("0000" & Hex(Data), 4)
    17.     a = Mid(tmp, 1, 2)
    18.     b = Mid(tmp, 3, 2)
    19.     MakeWORD = Chr(Val("&H" & b))
    20.     MakeWORD = MakeWORD & Chr(Val("&H" & a))
    21. End Function
    22.  
    23. Public Function MakeBYTE(Data As Byte) As String
    24.     Dim tmp As String
    25.     MakeBYTE = Chr(Val("&H" & Right("00" & Hex(Data), 2)))
    26. End Function
    27.  
    28. Public Function ToNumeric(ByVal hSource As Variant) As String
    29.     Select Case Len(hSource)
    30.         Case 1
    31.             ToNumeric = Right("00" & Hex(Asc(hSource)), 2)
    32.         Case 2
    33.             one = Mid(hSource, 1, 1)
    34.             two = Mid(hSource, 2, 1)
    35.             ToNumeric = Right("00" & Hex(Asc(two)), 2)
    36.             ToNumeric = ToNumeric & Right("00" & Hex(Asc(one)), 2)
    37.         Case 4
    38.             one = Mid(hSource, 1, 1)
    39.             two = Mid(hSource, 2, 1)
    40.             three = Mid(hSource, 3, 1)
    41.             four = Mid(hSource, 4, 1)
    42.             ToNumeric = Right("00" & Hex(Asc(four)), 2)
    43.             ToNumeric = ToNumeric & Right("00" & Hex(Asc(three)), 2)
    44.             ToNumeric = ToNumeric & Right("00" & Hex(Asc(two)), 2)
    45.             ToNumeric = ToNumeric & Right("00" & Hex(Asc(one)), 2)
    46.     End Select
    47.     ToNumeric = Val("&H" & ToNumeric)
    48. End Function

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    You make it too hard...
    Code:
    Dim Octets
    Octets = Split(IP, ".")
    Dim ret As String
    ret = ret & chr(cint(octets(0)))
    ret = ret & chr(cint(octets(1)))
    ret = ret & chr(cint(octets(2)))
    ret = ret & chr(cint(octets(3)))
    Code:
    Dim ret as String
    ret = cstr(asc(mid(cmpd_ip, 1, 1)))
    ret = ret & "."
    ret = ret & cstr(asc(mid(cmpd_ip, 2, 1)))
    ret = ret & "."
    ret = ret & cstr(asc(mid(cmpd_ip, 3, 1)))
    ret = ret & "."
    ret = ret & cstr(asc(mid(cmpd_ip, 4, 1)))
    Should work...

    Z.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width