【发布时间】:2015-04-03 18:47:05
【问题描述】:
下面是我的vb6代码
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 子库如何在 vb.net 中使用它
现在这是我的 vb.net 代码
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
这是VarPtr的代码
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
我参考了Equivalent of CopyMemory in .NET
但我仍然没有得到这个
请人帮忙!!!
【问题讨论】:
-
抱歉,我看不到问题(说“它不起作用”不是问题)。
-
CopyMem(VarPtr(dataX) + 1, dataX, 3) ' 问题出在这里它只是进入无穷大或挂断没有错误什么
-
请把它放在问题中。 PS。
Array.Copy和byte数组有什么问题?聚苯乙烯。您似乎正在尝试编写自己的密码学:“任何人都可以编写他们无法破解的算法;这并没有说明其他人是否可以破解它”。 -
它基本上是内存复制,我不知道如何在 vb.net 中实现相同(它是河豚密码)
标签: vb.net visual-studio-2010 vb6 copymemory