Page 1 of 2 12 LastLast
Results 1 to 40 of 51

Thread: Port Java to Vb6

  1. #1

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    Port Java to Vb6

    Greetings... I'm in the process of converting an encryption algorithm from Java to VB. but first I'd like to better grasp the concepts behind the Java routines.

    from what I can see, the java routines take in a string such as

    #58#54#58#42#50#

    and returns the string

    ~b#9#XZ?›aÅXÞ

    JAVA:
    Code:
    private void s(String s1)
        {
    private final String b_java_lang_String_array1d_fld[] = { "LHKf24()", "..FWSqw1", "783vcSWr", "NSW%FGS3", "S834VS$!"};
          
    
      StringTokenizer stringtokenizer = new StringTokenizer(s1 + "#", "#");
            BitSet bitset = new BitSet(64);
            for(int i1 = 0; i1 < 5; i1++)
            {
                BitSet bitset1 = a(b_java_lang_String_array1d_fld[i1].toCharArray());
                int j1 = Integer.parseInt(stringtokenizer.nextToken());
                for(int l1 = 0; l1 < j1; l1++)
                    bitset1 = a(bitset1);
    
                bitset.xor(bitset1);
            }
    
            char ac[] = a(bitset, 8);
            for(int k1 = 0; k1 < 8; k1++)
                if(ac[k1] == 0 || ac[k1] == '\n' || ac[k1] == '\r')
                    ac[k1] = (char)(ac[k1] | 0x80);
    
            try
            {
                a_java_io_DataOutputStream_fld.writeBytes("~b#9#");
                for(int i2 = 0; i2 < ac.length; i2++)
                    a_java_io_DataOutputStream_fld.write((byte)(ac[i2] & 0xff));
    
                a_java_io_DataOutputStream_fld.writeBytes("\n");
            }
            catch(Exception exception)
            {
                a(1);
            }
        }
    
    private BitSet a(BitSet bitset)
        {
            BitSet bitset1 = new BitSet(64);
            boolean flag = false;
            for(int i1 = 0; i1 < 64; i1++)
            {
                if(flag != bitset.get(i1))
                    bitset1.set(i1);
                flag = bitset.get(i1);
            }
    
            return bitset1;
        }
    
    private BitSet a(char ac[])
        {
            int i1 = ac.length * 8;
            BitSet bitset = new BitSet(i1);
            for(int j1 = 0; j1 < i1; j1++)
            {
                int k1 = j1 & 7;
                int l1 = j1 >> 3;
                if((ac[l1] & 0xff & 1 << 7 - k1) != 0)
                    bitset.set(j1);
            }
    
            return bitset;
        }
    
    private char[] a(BitSet bitset, int i1)
        {
            int j1 = i1 * 8;
            char ac[] = new char[i1];
            for(int k1 = 0; k1 < j1; k1++)
            {
                int l1 = k1 & 7;
                int i2 = k1 >> 3;
                if(bitset.get(k1))
                    ac[i2] = (char)(ac[i2] | 1 << 7 - l1);
            }
    
            return ac;
        }


    I would like to produce the same effects in VB, but I'm having trouble grasping the concepts behind how it encrypts/decrypts the strings.


    is this some form of bitset conversion? or mere string/character shift conversion?


    another string passed through the function is

    #58#32#59#48#26#

    which returns

    ~b#20#àž-Un†„
    any ideas on this concept would be greatly appreciated.
    Last edited by TokersBall_CDXX; Feb 1st, 2004 at 03:28 PM.
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  2. #2
    Addicted Member Illiad's Avatar
    Join Date
    Mar 2003
    Location
    Chicago
    Posts
    196
    What are you using to comple your java. My TextPad gives me an error.
    Quis Custodiet Ipsos Custodes?

    You don't have to be faster than the bear, you just have to be faster than the slowest person running from the bear.

  3. #3

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    I use the compiler from Java.Sun

    SDK 4

    it's an applet of course
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  4. #4

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    this is prolly what's causing the error

    private final String b_java_lang_String_array1d_fld[] = { "LHKf24()", "..FWSqw1", "783vcSWr", "NSW%FGS3", "S834VS$!"};

    I pulled it out of main
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  5. #5
    Addicted Member Illiad's Avatar
    Join Date
    Mar 2003
    Location
    Chicago
    Posts
    196
    hmmm...im as stumped as you are
    Quis Custodiet Ipsos Custodes?

    You don't have to be faster than the bear, you just have to be faster than the slowest person running from the bear.

  6. #6
    Addicted Member Illiad's Avatar
    Join Date
    Mar 2003
    Location
    Chicago
    Posts
    196
    Do you need the same method of encryption in VB or do you just want to know how to do a deep encrytion in VB?
    Quis Custodiet Ipsos Custodes?

    You don't have to be faster than the bear, you just have to be faster than the slowest person running from the bear.

  7. #7

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    hmm

    I am familular with many methods of encryption in vb
    how ever I've been trying to convert this to particular method into vb and it has had me stumped for months
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  8. #8
    Addicted Member Illiad's Avatar
    Join Date
    Mar 2003
    Location
    Chicago
    Posts
    196
    I'll look over it tomorrow, my eyes are getting heavy. Maby a nights sleep will open my mind...I'll keep working on it though.
    Quis Custodiet Ipsos Custodes?

    You don't have to be faster than the bear, you just have to be faster than the slowest person running from the bear.

  9. #9

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    bump

    bumpidy bump bump
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  10. #10

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    bump

    anyone?
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  11. #11
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    The code you posted seems to be only the encryption method.
    Also it encrypts strings only in that format ie: #num#num#num#num#num#...
    The code can be converted, with a little more code in vb than in Java, but, yes, it is possible. Your gonna have to re-create the BitSet class in VB, the rest is about the same. For the StringTokenizer class in Java, you can use the equivalent of Split in VB.
    I don't see where this function is being used:
    private BitSet a(char ac[]).... ??

    And I don't understand this part of the code:
    catch(Exception exception)
    {
    a(1);
    }

    There is no "a" function that takes an integer, and why would you call it if it does not use the retun value ?

  12. #12

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    can you

    elaborate?
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  13. #13
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Elaborate what ? everything ? i'm not gonna do it...
    Tell me what you don't understand from what I wrote, and I'll try to elaborate...

  14. #14

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    what kind of encryption method is this?

    and is it possible to recreate the Bitset class in VB6 (not .NET)
    if so do you know of any documention on the Bitset class that demonstrates it's lower level functionality?
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  15. #15
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    "what kind of encryption method is this?"
    No idea, i've never seen an encryption like this... but as I mentioned before, it encrypts ONLY string in that format #num#num...

    "is it possible to recreate the Bitset class in VB6 (not .NET)"
    Yes, it is possible

    "...do you know of any documention ...."
    No, i personally don't... but I'm sure you can find something in google.com

    It is not that difficult to figure out what the BitSet class does... from the name you can see that it has to do with Bits, from it's use you can see that it's implementing an XOR function, a Get function, and a copy contructor. If you look more carefully how is each one used you can see what they return, and also you can figure out how it works...

  16. #16

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571
    thanx
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  17. #17

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    Question

    would this function be the start on my venture through the lands of bits and bytes?

    VB Code:
    1. Public Function BitSet(Number As Long, ByVal Bit As Long) As Long
    2.    If Bit = 31 Then
    3.      Number = &H80000000 Or Number
    4.    Else
    5.      Number = (2 ^ Bit) Or Number
    6.    End If
    7.  
    8.    BitSet = Number
    9.  End Function
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  18. #18
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Use AND not OR...
    What you want is to get the bit at that position, so if you do somehing like:

    01110011101010111 OR
    00000000010000000
    ---------------------------
    01110011111010111

    but you want something like this:

    01110011101010111 AND
    00000000010000000
    ---------------------------
    00000000000000000

    In this case the bit at that position is 0, so the whole thing will be 0

    Get it ?

  19. #19
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    But you have to make a class, not a function...

    Do you know how to make a class ?, do you know what's the difference ?

  20. #20

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    hmm

    well I've been trying to come up with a way to mimic the bitset class in JAVA, this is as close as I can get but I'm still sketchy in certain areas.


    VB Code:
    1. VERSION 1.0 CLASS
    2. BEGIN
    3.   MultiUse = -1  'True
    4. END
    5. Attribute VB_Name = "Bit_Vec"
    6. Attribute VB_Creatable = True
    7. Attribute VB_Exposed = True
    8.  
    9. Option Explicit
    10. DefInt A-Z
    11.  
    12. Const CLASS_NAME = "Bit_Vec"
    13. Const CLASS_VERSION = "100"
    14.  
    15.  
    16.  
    17.  
    18.  
    19. Const vbErrSubscriptOutOfRange = 9
    20.  
    21. Const BITS_PER_ELEMENT = 8
    22.  
    23.  
    24. Private mBits()      As Byte
    25. Private mNumElements As Long
    26.  
    27.  
    28. Private Sub Class_Initialize()
    29.  
    30. End Sub
    31.  
    32.  
    33. Private Sub Class_Terminate()
    34.    
    35.     Erase mBits
    36.  
    37. End Sub
    38.  
    39.  
    40.  
    41. Public Property Let NumElements(NewValue As Long)
    42.    
    43.    
    44.    
    45.     mNumElements = NewValue
    46.     ReDim Preserve mBits(mNumElements \ BITS_PER_ELEMENT)
    47.    
    48. End Property
    49.  
    50.  
    51. Public Property Get NumElements() As Long
    52.    
    53.     NumElements = mNumElements
    54.  
    55. End Property
    56.  
    57.  
    58. '------------------------------------------------------
    59. '-- METHODS
    60. '------------------------------------------------------
    61.  
    62. Public Sub ClearAll()
    63.     Dim i As Long
    64.    
    65.     '-- Set bit values in BITS_PER_ELEMENT chunks for speed
    66.     For i = LBound(mBits) To UBound(mBits)
    67.         mBits(i) = &H0
    68.     Next i
    69.    
    70. End Sub
    71.  
    72. Public Sub ClearBit(Index As Long)
    73. '-- Set Bit(Index) value to 0
    74.     Dim ArrayIdx As Long
    75.     Dim Bit      As Long
    76.    
    77.     Call ValidateIndex(Index)
    78.    
    79.     ArrayIdx = Index \ BITS_PER_ELEMENT
    80.     Bit = Index Mod BITS_PER_ELEMENT
    81.     'Debug.Print "Clearing ArrayIdx:"; ArrayIdx, " Bit:"; Bit
    82.     mBits(ArrayIdx) = mBits(ArrayIdx) And (Not (2 ^ Bit))
    83.    
    84. End Sub
    85.  
    86.  
    87. Public Function GetBit(Index As Long) As Integer
    88. '-- Returns 0 or 1
    89.    
    90.     Call ValidateIndex(Index)
    91.    
    92.     If IsBitSet(Index) Then
    93.         GetBit = 1
    94.     Else
    95.         GetBit = 0
    96.     End If
    97.    
    98. End Function
    99.  
    100.  
    101. Public Function IsBitSet(Index As Long) As Boolean
    102.     Dim ArrayIdx As Long
    103.     Dim Bit      As Long
    104.    
    105.     Call ValidateIndex(Index)
    106.    
    107.     ArrayIdx = Index \ BITS_PER_ELEMENT
    108.     Bit = Index Mod BITS_PER_ELEMENT
    109.     'Debug.Print "Testing ArrayIdx:"; ArrayIdx, " Bit:"; Bit
    110.     If mBits(ArrayIdx) And 2 ^ Bit Then
    111.         IsBitSet = True
    112.     Else
    113.         IsBitSet = False
    114.     End If
    115.  
    116. End Function
    117.  
    118.  
    119. Public Sub SetAll()
    120.     Dim i As Long
    121.    
    122.     '-- Set bit values in BITS_PER_ELEMENT chunks for speed
    123.     For i = LBound(mBits) To UBound(mBits)
    124.         mBits(i) = &HFF
    125.     Next i
    126.    
    127. End Sub
    128.  
    129.  
    130. Public Sub SetBit(Index As Long)
    131. '-- Set Bit(Index) value to 1
    132.     Dim ArrayIdx As Long
    133.     Dim Bit      As Long
    134.    
    135.     Call ValidateIndex(Index)
    136.    
    137.     ArrayIdx = Index \ BITS_PER_ELEMENT
    138.     Bit = Index Mod BITS_PER_ELEMENT
    139.     'Debug.Print "Setting ArrayIdx:"; ArrayIdx, " Bit:"; Bit
    140.     mBits(ArrayIdx) = mBits(ArrayIdx) Or 2 ^ Bit
    141.  
    142. End Sub
    143.  
    144.  
    145. Public Sub ToggleBit(Index As Long)
    146. '-- Toggle the value of Bit(Index)
    147.    
    148.     Call ValidateIndex(Index)
    149.    
    150.     If IsBitSet(Index) Then
    151.         Call ClearBit(Index)
    152.     Else
    153.         Call SetBit(Index)
    154.     End If
    155.    
    156. End Sub
    157.  
    158.  
    159.  
    160.  
    161. Private Sub ValidateIndex(Index As Long)
    162.    
    163.     '-- Our bounds checking code is aware that this is
    164.     '   a 0 based array of bits.
    165.     If (Index < 0) Or (Index > (mNumElements - 1)) Then
    166.         RaiseError vbErrSubscriptOutOfRange
    167.     End If
    168.  
    169. End Sub
    170.  
    171.  
    172. '------------------------------------------------------
    173. '-- ERRORS
    174. '------------------------------------------------------
    175.  
    176. ' .GetErrorDesc
    177. Private Function GetErrorDesc(ErrCode As Long) As String
    178.     Dim Desc As String
    179.    
    180.     Select Case ErrCode
    181.         Case vbErrSubscriptOutOfRange
    182.             Desc = "Subscript out of Range"
    183.         Case Else
    184.             Desc = "Unknown error"
    185.     End Select
    186.    
    187.     GetErrorDesc = Desc
    188.    
    189. End Function
    190.  
    191.  
    192. ' .RaiseError
    193. Private Sub RaiseError(ErrCode As Long)
    194.        
    195.     Err.Raise Number:=vbObjectError + ErrCode, _
    196.               Source:=CLASS_NAME & " " & CLASS_VERSION, _
    197.               Description:=GetErrorDesc(ErrCode)
    198.  
    199. End Sub

    any major problems you see that I am missing or not thinking of or may have missed??
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  21. #21
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Well, if you make the ValidateIndex sub into a function you can get rid of GetErrorDesc and RaiseError

    do something like:
    VB Code:
    1. Private Function IsValidIndex(Index As Long) As Boolean
    2.     '-- Our bounds checking code is aware that this is
    3.     '   a 0 based array of bits.
    4.     IsValidIndex = Not (Index < 0 Or Index >= mNumElements)
    5. End Function

    Also, I don't see where you set the data into the array, and remember that it comes from a string, so use StrConv function
    I'm talking about this line from java code:
    BitSet bitset1 = a(b_java_lang_String_array1d_fld[i1].toCharArray());

    Also have a way to XOR 2 classes, from java code: bitset.xor(bitset1);

    Everything else looks OK, but i did not actually test anything.

  22. #22
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Actually, nevermind about ValidateIndex thing... took a second look at your code, and i changed my mind, it is better how you did it...

  23. #23

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    hmm

    I'm having trouble setting the data into an array... and I'm finding that the standard XOR function is not being friendly with me.
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  24. #24
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    For the StrConv:
    VB Code:
    1. Dim Buffer() As Byte
    2. Buffer = StrConv("blah", vbFromUnicode)

    For the XOR, post the code so I can see what's wrong

  25. #25

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    hmm

    Code:
    BitSet bitset1 = a(b_java_lang_String_array1d_fld[i1].toCharArray());
    appears to call the function
    Code:
    private BitSet a(char ac[])
        {
            int i1 = ac.length * 8;
            BitSet bitset = new BitSet(i1);
            for(int j1 = 0; j1 < i1; j1++)
            {
                int k1 = j1 & 7;
                int l1 = j1 >> 3;
                if((ac[l1] & 0xff & 1 << 7 - k1) != 0)
                    bitset.set(j1);
            }
    
            return bitset;
        }
    in order to translate the character array (string) into a bitset return

    I've tried recreating this function to no end with no luck

    I'm stuck at

    Code:
     int l1 = j1 >> 3;
                if((ac[l1] & 0xff & 1 << 7 - k1) != 0)
                    bitset.set(j1);

    how does ones tranlate this into vb?
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  26. #26
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    int l1 = j1 >> 3;
    if((ac[l1] & 0xff & 1 << 7 - k1) != 0)
    bitset.set(j1);

    Bit shifting...
    It's basicly division/multiplication of 2 ^ "shift by"

    So... j1 >> 3 would be j1 \ 8
    Note that I used \ not /, because it returns an integer instead of decimal (double)

    if((ac[l1] & 0xff & 1 << 7 - k1) != 0)

    would be translated to:

    If ac(l1) And &HFF And 128 - k1) <> 0 Then
    ....

    0xff -> &HFF or 255
    1 << 7 -> 2 ^ 7 -> 128

  27. #27

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    hmm something like this?

    VB Code:
    1. Private Function BitShift(ac As String)
    2. Dim i1 As Integer
    3. Dim TempBitSet1 As New BitVector
    4.     i1 = Len(ac) * 8
    5.     TempBitSet1.NumElements i1
    6.     For j1 = 0 To i1
    7.         Dim k1 As Integer
    8.         Dim l1 As Integer
    9.         k1 = j1 & 7
    10.         l1 = j1 \ 8
    11.         If ac(l1) And &HFF And 128 - k1 <> 0 Then TempBitSet1.SetBit (j1)
    12.     Next a
    13. BitShift = TempBitSet1
    14. End Function
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  28. #28
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    3 things...
    First, when you return a reference, do not dim with the new keyword in the same line... because at the end of the function the vb environment will destroy the variables (and it's references)
    Second, is partially my mistake too, the if statement is in brackets
    Third, don't Dim inside loops, don't really know why, but it's a good practice to Dim all variables at the beginning of the sub/function

    VB Code:
    1. Private Function BitShift(ac As String) As BitVector
    2. Dim i1 As Integer
    3. Dim k1 As Integer
    4. Dim l1 As Integer
    5. Dim TempBitSet1 As BitVector
    6. Set TempBitSet1 = New BitVector
    7.  
    8.     i1 = Len(ac) * 8
    9.     TempBitSet1.NumElements i1
    10.     For j1 = 0 To i1
    11.         k1 = j1 & 7
    12.         l1 = j1 \ 8
    13.         If (ac(l1) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit (j1)
    14.     Next a
    15.     Set BitShift = TempBitSet1
    16. End Function
    The rest looks ok... again, I did not actually run the code to test it...

  29. #29
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Also... i just noticed... ac is a string...

    VB Code:
    1. Private Function BitShift(ac() As Byte) As BitVector
    2. Dim i1 As Integer
    3. Dim k1 As Integer
    4. Dim l1 As Integer
    5. Dim TempBitSet1 As BitVector
    6. Set TempBitSet1 = New BitVector
    7.  
    8.     i1 = Len(ac) * 8
    9.     TempBitSet1.NumElements i1
    10.     For j1 = 0 To i1
    11.         k1 = j1 & 7
    12.         l1 = j1 \ 8
    13.         If (ac(l1) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit j1
    14.     Next a
    15.     Set BitShift = TempBitSet1
    16. End Function

    or
    VB Code:
    1. Private Function BitShift(ac As String) As BitVector
    2. Dim i1 As Integer
    3. Dim k1 As Integer
    4. Dim l1 As Integer
    5. Dim TempBitSet1 As BitVector
    6. Set TempBitSet1 = New BitVector
    7.  
    8.     i1 = Len(ac) * 8
    9.     TempBitSet1.NumElements i1
    10.     For j1 = 0 To i1
    11.         k1 = j1 & 7
    12.         l1 = j1 \ 8
    13.         If (Asc(Mid(ac, l1 + 1, 1)) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit j1
    14.     Next a
    15.     Set BitShift = TempBitSet1
    16. End Function

  30. #30

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    wow you rock!

    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  31. #31

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    I think

    VB Code:
    1. Dim i1 As Integer
    2. Dim k1 As Integer
    3. Dim l1 As Integer
    4. Dim TempBitSet1 As BitVector
    5. Set TempBitSet1 = New BitVector
    6.  
    7.     i1 = Len(ac) * 8
    8.     TempBitSet1.NumElements = i1
    9.     For j1 = 0 To i1
    10.         k1 = j1 & 7
    11.         l1 = j1 \ 8
    12.         If (Asc(Mid(ac, l1 + 1, 1)) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit (j1)
    13.     Next j1
    14.     Set BitShift = TempBitSet1
    15. End Function


    the k1=j1 & 7 is causing a problem
    it appears to equal 647 at the time of the error flag

    should that be + 7? or is this another operation taking place?
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  32. #32
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    ow... & is And (binary and to be more precice) but in vb it kinda knows when to use the boolean and or binary and
    so
    k1 = j1 & 7

    is

    k1 = j1 And 7

  33. #33

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    hmm

    well in terms of the BitShift function I was able to port it with a great deal of your help, thank you.


    JAVA

    Code:
    private BitSet a(char ac[])
        {
            int i1 = ac.length * 8;
            BitSet bitset = new BitSet(i1);
            for(int j1 = 0; j1 < i1; j1++)
            {
                int k1 = j1 & 7;
                int l1 = j1 >> 3;
                if((ac[l1] & 0xff & 1 << 7 - k1) != 0)
                    bitset.set(j1);
            }
    
            return bitset;
        }
    in VB

    VB Code:
    1. Private Function BitShift(ac As String) As BitVector
    2. Dim i1 As Integer
    3. Dim k1 As Integer
    4. Dim l1 As Integer
    5. Dim TempBitSet1 As BitVector
    6. Set TempBitSet1 = New BitVector
    7.     i1 = Len(ac) * 8
    8.     TempBitSet1.NumElements = i1
    9.     Do While j1 < i1
    10.         k1 = j1 & 7
    11.         l1 = j1 \ 8
    12.         Debug.Print l1
    13.         If l1 < 8 Then If (Asc(Mid(ac, l1 + 1, 1)) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit (j1)
    14.         j1 = j1 + 1
    15.     Loop
    16.     Set BitShift = TempBitSet1
    17. End Function


    how ever I can't quite grasp how I'm going to pass one class to another.. is this possible in vb?

    VB Code:
    1. Private Sub cmdTest1_Click()
    2. Dim BitSet1 As New BitVector
    3.      BitSet1.NumElements = 64
    4.      HashArray() = Split("LHKf24(),..FWSqw1,783vcSWr,NSW%FGS3,S834VS$!", ",")
    5.      BitSet1 = BitShift(HashArray(0))
    6. End Sub

    'Object doesn't support this method.
    Last edited by TokersBall_CDXX; Jan 14th, 2004 at 11:12 PM.
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  34. #34

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571
    anyone?
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  35. #35
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Why do you always create a class like this:
    Dim BitSet1 As New BitVector ?

    When you create a variable of new instance of a class in the same line, the variable is like a static variable, you can't change it, the BitSet1 will always point to the class instance that was created at that moment.
    But... if you create a class like this:

    Dim BitSet1 As BitVector

    You create a reference, and taht means that that reference can point to any instance of a class of that type (BitVector).

    So, for your code to work properly, you have to do something like this:
    VB Code:
    1. Private Sub cmdTest1_Click()
    2.      Dim BitSet1 As BitVector
    3.  
    4.      BitSet1.NumElements = 64
    5.      HashArray() = Split("LHKf24(),..FWSqw1,783vcSWr,NSW%FGS3,S834VS$!", ",")
    6.      Set BitSet1 = BitShift(HashArray(0))
    7. End Sub
    In order of execution, you create a reference to the class in cmdTest
    You call the function BitShift, where it also creates a reference of the same type of class, in the function you create a new instance of the class and you put it in TempBitSet1 reference, then you pass that reference as a return value. When the function is complete, it will NOT distroy the class because it was created as a reference, and also because you return the reference.
    When the BitShift function is complete and returns the reference, the reference gets copyed in the BitSet1 variable using the Set keyword. after that, you can use that reference because the class is still not distroyed, but instead it's location (the reference) was moved from one variable to another... as long as one variable has it's reference, the class is still in the memory, and can be used...

    Get it ?

  36. #36
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    Also, since the BitSet1 variable does not contain a reference to any class, you will get an error at this line:
    BitSet1.NumElements = 64
    VB Code:
    1. Private Sub cmdTest1_Click()
    2.      Dim BitSet1 As BitVector
    3.  
    4.      HashArray() = Split("LHKf24(),..FWSqw1,783vcSWr,NSW%FGS3,S834VS$!", ",")
    5.      Set BitSet1 = BitShift(HashArray(0))
    6. End Sub

  37. #37

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    wow you ROCK!

    okay so far I have this

    VB Code:
    1. Private Sub cmdTest1_Click()
    2. Dim BitSet1 As BitVector
    3. Dim HashArray() As String
    4. Dim ParsedNumArray() As String
    5. Dim i1, jtemp, j1 As Integer
    6.     HashArray() = Split("LHKf24(),..FWSqw1,783vcSWr,NSW%FGS3,S834VS$!", ",")
    7.     ParsedNumArray() = Split("58#54#58#42#50#", "#")
    8.  
    9. For i1 = 0 To 4
    10.     Set BitSet1 = BitShift(HashArray(i1))
    11.     For jtemp = 0 To UBound(ParsedNumArray()) - 1
    12.         j1 = Int(ParsedNumArray(jtemp))
    13.         Set BitSet1 = BitFlag(BitSet1)
    14.     Next jtemp
    15. Next i1
    16.  
    17. End Sub
    18.  
    19. Private Function BitShift(ac As String) As BitVector
    20. Dim i1 As Integer
    21. Dim k1 As Integer
    22. Dim l1 As Integer
    23. Dim TempBitSet1 As BitVector
    24. Set TempBitSet1 = New BitVector
    25.  
    26.     i1 = Len(ac) * 8
    27.     TempBitSet1.NumElements = i1
    28.     For j1 = 0 To i1
    29.         k1 = j1 & 7
    30.         l1 = j1 \ 8
    31.         If l1 <> 8 Then If (Asc(Mid(ac, l1 + 1, 1)) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit (j1)
    32.         Print
    33.     Next j1
    34.     Set BitShift = TempBitSet1
    35. End Function
    36.  
    37. Private Function BitFlag(BitSet As BitVector) As BitVector
    38. Dim BitSet1 As BitVector
    39. Dim Flag As Boolean
    40. Dim i1 As Integer
    41. Set BitSet1 = New BitVector
    42.     BitSet1.NumElements = 64
    43.    
    44.     Flag = False
    45.     For i1 = 0 To 63
    46.         If Flag <> BitSet.GetBit(CLng(i1)) Then BitSet1.SetBit (CLng(i1))
    47.         Flag = BitSet.GetBit(CLng(i1))
    48.     Next i1
    49. Set BitFlag = BitSet1
    50. End Function

    see anything out of place? it's not producing any errors which is good



    on to the next function to port


    Code:
    private char[] a(BitSet bitset, int i1)
        {
            int j1 = i1 * 8;
            char ac[] = new char[i1];
            for(int k1 = 0; k1 < j1; k1++)
            {
                int l1 = k1 & 7;
                int i2 = k1 >> 3;
                if(bitset.get(k1))
                    ac[i2] = (char)(ac[i2] | 1 << 7 - l1);
            }
    
            return ac;
        }
    you mentioned earlier that the >> is a 2^ equation?
    would that mean i2 = k1 >> 2^3 ?

    thanx for your help you rock!
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  38. #38
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    >> ( right shift ), in VB you divide
    << ( left shift ), in VB you multiply

    So
    i2 = k1 >> 3;

    In VB is

    i2 = k1 \ 2^3

    or

    i2 = k1 \ 8

  39. #39

    Thread Starter
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    hmm

    something about this port seems odd
    I screwed it up

    Code:
    private char[] a(BitSet bitset, int i1)
        {
            int j1 = i1 * 8;
            char ac[] = new char[i1];
            for(int k1 = 0; k1 < j1; k1++)
            {
                int l1 = k1 & 7;
                int i2 = k1 >> 3;
                if(bitset.get(k1))
                    ac[i2] = (char)(ac[i2] | 1 << 7 - l1);
            }
    
            return ac;
        }
    VB Code:
    1. Private Function Characterize(BitSet As BitVector, i1 As Integer) As String
    2. Dim ji, k1, l1, i2 As Integer
    3. Dim ac As String
    4.     j1 = i1 * 8
    5.     For k1 = 0 To j1
    6.         l1 = k1 & 7
    7.         i2 = k1 \ 8
    8.         If BitSet.get(k1) Then ac = ac Or 1 * 7 - l1
    9.     Next k1
    10. Characterize = ac
    11. End Function
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  40. #40
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    You need to learn how to deal with strings also....
    VB Code:
    1. Private Function Characterize(BitSet As BitVector, i1 As Integer) As String
    2.     Dim ji, k1, l1, i2 As Integer
    3.     Dim ac As String
    4.  
    5.     ' int j1 = i1 * 8;
    6.     j1 = i1 * 8
    7.  
    8.     ' char ac[] = new char[i1];
    9.     ac = String(i1, 0)
    10.  
    11.     ' for(int k1 = 0; k1 < j1; k1++)
    12.     ' j1 is not included
    13.     For k1 = 0 To j1 - 1
    14.         ' int l1 = k1 & 7;
    15.         ' & in VB is AND, I mentioned that in a previous post also
    16.         l1 = k1 And 7
    17.  
    18.         ' int i2 = k1 >> 3;
    19.         i2 = k1 \ 8
    20.  
    21.         ' if(bitset.get(k1)) ac[i2] = (char)(ac[i2] | 1 << 7 - l1);
    22.         ' ac[i2], is getting a particular character, not the entire string !
    23.         If BitSet.get(k1) Then
    24.             Mid$(ac, i2 + 1, 1) = Chr(Asc(Mid$(ac, i2 + 1, 1)) Or 128 - l1)
    25.             ' The index for Mid function is starting at 1, that's why I did "i2 + 1"
    26.         End If
    27.     Next k1
    28.     Characterize = ac
    29. End Function

    And also, you made the same mistake with this: 1 << 7
    In one of the previous posts I converted a line wich contained 1 << 7, and I wrote 128...

    To make this clear, I'll do it step by step...

    So... 1 << 7
    In vb is:
    1 * 2 ^ 7

    or

    1 * 128

    or

    128
    Last edited by CVMichael; Jan 15th, 2004 at 09:20 PM.

Page 1 of 2 12 LastLast

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