Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
below is my vb6 code

VB
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)


Public Property Let Key(New_Value As String)

  Dim i As Long
  Dim j As Long
  Dim K As Long
  Dim dataX As Long
  Dim datal As Long
  Dim datar As Long
  Dim Key() As Byte
  Dim KeyLength As Long

  'Do nothing if the key is buffered
  If (m_KeyValue = New_Value) Then Exit Property
  m_KeyValue = New_Value
  
  'Convert the new key into a bytearray
  KeyLength = Len(New_Value)
  Key() = StrConv(New_Value, vbFromUnicode)
  
  'Create key-dependant p-boxes
  j = 0
  For i = 0 To (ROUNDS + 1)
    dataX = 0
    For K = 0 To 3
      Call CopyMem(ByVal VarPtr(dataX) + 1, dataX, 3) 'the problem is here
      dataX = (dataX Or Key(j))
      j = j + 1
      If (j >= KeyLength) Then j = 0
    Next
    m_pBox(i) = m_pBox(i) Xor dataX
  Next
  
End Property



CopyMem sub lib how do i use it in vb.net


now here is my vb.net code for the same

VB
Private Declare Sub CopyMem Lib "KERNEL32" Alias "RtlMoveMemory" (ByVal pDst As Object, ByVal pSrc As Object, ByVal ByteLen As Integer)


    Public WriteOnly Property Key() As String
           Set(ByVal Value As String)

               Dim i As Long
               Dim j As Long
               Dim K As Long
               Dim dataX As Long
               Dim datal As Long
               Dim datar As Long
               Dim Key() As Byte
               Dim KeyLength As Long

               'Do nothing if the key is buffered
               If (m_KeyValue = Value) Then Exit Property
               m_KeyValue = Value

               'Convert the new key into a bytearray
               KeyLength = Len(Value)

               Key = System.Text.Encoding.Unicode.GetBytes(Value)

               'Create key-dependant p-boxes
               j = 0

               For i = 0 To (ROUNDS + 1)
                   dataX = 0
                   For K = 0 To 3


                       CopyMem(VarPtr(dataX) + 1, dataX, 3) ' the problem is here
                       dataX = (dataX Or Key(j))
                       j = j + 1
                       If (j >= KeyLength) Then j = 0

                   Next
                   m_pBox(i) = m_pBox(i) Xor dataX
               Next
    End Property


here is code for
VB
VarPtr



VB
Public Function VarPtr(ByVal e As Object) As Object
        Dim GC As GCHandle = GCHandle.Alloc(e, GCHandleType.Pinned)
        Dim GC2 As Integer = GC.AddrOfPinnedObject.ToInt32
        GC.Free()
        Return GC2
    End Function


i have refered to Equivalent of CopyMemory

but still i am not getting this

please somebody help!!!
Posted
Updated 3-Feb-15 22:45pm
v2
Comments
CHill60 4-Feb-15 4:51am    
Rather than trying to convert the VB6 code verbatim you should determine what that code is trying to achieve and rewrite it in VB.NET using .NET constructs.
Omkaara 4-Feb-15 5:00am    
CopyMem(VarPtr(dataX) + 1, dataX, 3)
its basically memory copying i dont knw how to achieve the same in vb.net
CHill60 4-Feb-15 5:06am    
I'm very familiar with CopyMem and what it does. You need to understand what that VB6 Property code is trying to achieve - I'm guessing something to do with crypography?
Omkaara 4-Feb-15 5:09am    
yes ofcourse its blowfish cipher

1 solution

As per my earlier comment, do not attempt to convert this VB6 code verbatim. Work out what it is trying to do and write it in VB.NET

As we have now established that it is handling the Blowfish Cipher these CodeProject resources should prove useful

Blowfish Encryption Implementation in .NET[^]

Blowfish Encryption Implementation in .Net[^]
 
Share this answer
 
Comments
Omkaara 4-Feb-15 5:42am    
to be very frank i am new to this stuff i am trying to understand it but its all going over head

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900