Results 1 to 6 of 6

Thread: Encryption Problem

  1. #1

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

    Encryption Problem

    I am in the process of porting a java encryption routine into visual basics..
    for the past month now I've had an on-gowing discussion with a user on this forum and he has helped me out a great deal but I think he has givin up on me? perhaps for my lack of understanding I am not sure.

    anyways

    this is the Java Routines
    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;
        }


    so far I have been able to mimic the bitset class in visual basics using the follow class routines

    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


    and with a bit of help from the other user on this forum I have been able to mimic most of the java procedures in such a fashion


    VB Code:
    1. Private Sub cmdTest1_Click()
    2. Dim BitSet1 As BitVector
    3. Dim BitSet As New BitVector
    4. Dim HashArray() As String
    5. Dim ac As String
    6. Dim ParsedNumArray() As String
    7. Dim i1, jtemp, j1 As Integer
    8.     BitSet.NumElements = 64
    9.     HashArray() = Split("LHKf24(),..FWSqw1,783vcSWr,NSW%FGS3,S834VS$!", ",")
    10.     ParsedNumArray() = Split("58#54#58#42#50#", "#")
    11.  
    12. For i1 = 0 To 4
    13.     Set BitSet1 = BitShift(HashArray(i1))
    14.    
    15.         j1 = Val(ParsedNumArray(i1))
    16.        
    17.         For l1 = 0 To j1
    18.             Set BitSet1 = BitFlag(BitSet1)
    19.         Next
    20.         For x = 0 To 63
    21.             BitSet.SetBit (CLng(x)) Xor BitSet1.GetBit(CLng(x))
    22.         Next
    23.        
    24. Next i1
    25.  
    26.  
    27. ac = Characterize(BitSet, 8)
    28.  
    29. End Sub
    30.  
    31. Private Function BitShift(ac As String) As BitVector
    32. Dim i1 As Integer
    33. Dim k1 As Integer
    34. Dim l1 As Integer
    35. Dim TempBitSet1 As BitVector
    36. Set TempBitSet1 = New BitVector
    37.  
    38.     i1 = Len(ac) * 8
    39.     TempBitSet1.NumElements = i1
    40.     For j1 = 0 To i1
    41.         k1 = j1 & 7
    42.         l1 = j1 \ 8
    43.         If l1 <> 8 Then If (Asc(Mid(ac, l1 + 1, 1)) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit (j1)
    44.         Print
    45.     Next j1
    46.     Set BitShift = TempBitSet1
    47. End Function
    48.  
    49. Private Function BitFlag(BitSet As BitVector) As BitVector
    50. Dim BitSet1 As BitVector
    51. Dim Flag As Boolean
    52. Dim i1 As Integer
    53. Set BitSet1 = New BitVector
    54.     BitSet1.NumElements = 64
    55.    
    56.     Flag = False
    57.     For i1 = 0 To 63
    58.         If Flag <> BitSet.GetBit(CLng(i1)) Then BitSet1.SetBit (CLng(i1))
    59.         Flag = BitSet.GetBit(CLng(i1))
    60.     Next i1
    61. Set BitFlag = BitSet1
    62. End Function
    63.  
    64.  
    65.  
    66. Private Function Characterize(BitSet As BitVector, i1 As Integer) As String
    67.     Dim ji, k1, l1, i2 As Integer
    68.     Dim ac As String
    69.     j1 = i1 * 8
    70.     ac = String(i1, 0)
    71.     For k1 = 0 To j1 - 1
    72.         l1 = k1 And 7
    73.         i2 = k1 \ 8
    74.         If BitSet.get(k1) Then  Mid$(ac, i2 + 1, 1) = Chr(Asc(Mid$(ac, i2 + 1, 1)) Or 128 - l1)
    75.         End If
    76.     Next k1
    77.     Characterize = ac
    78. End Function


    the java routines take in a string such as
    "#58#54#58#42#50#"

    and produces the following
    "~b#9#XZ?›aÅXÞ"

    so far my vb routine returns 2 characters. a Null character and a [] block character.

    I've had no luck proceeding any further I do believe my problem is the XOR procedure but I could be wrong...


    any help on this matter would be more than greatly appriciated.

    P.S.
    the previous post on the vb forum is http://www.vbforums.com/showthread.p...0&pagenumber=1

    thanx
    Last edited by TokersBall_CDXX; Jan 31st, 2004 at 06:42 PM.
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    for the past month now
    In that time you could have learned Java properly, which would enable you to convert this thing without help. Converting code from one language to another, especially converting bit manipulation to VB, is very boring, so people don't often help out with it. Sorry.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Yes Corned be is right. Unless someone that posts in this forum knows Visual Basic and Java i doubt you will be able to get any help that is worth anything.

    Instead of writing your own routine why not just use some of the Encryption functionality that is built into VB? I used to write my own encryption code from scratch but what is the point of doing all of the work when i can simple use the classes that are contained in the JCE.

  4. #4

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

    *sighs*

    I've been working with both vb and java for quite some time now... and in most cases I've been able to port nearly everything from java to vb..how ever I am experiencing difficulties with this particular encryption method.

    any one have any idea where I might be screwing up at?
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  5. #5

    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

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    If both Dilenger and me are unable to help, then it is very unlikely that you will get help. Nearly no one else browses this forum, so bumping won't do much good.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

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