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:
VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = "Bit_Vec" Attribute VB_Creatable = True Attribute VB_Exposed = True Option Explicit DefInt A-Z Const CLASS_NAME = "Bit_Vec" Const CLASS_VERSION = "100" Const vbErrSubscriptOutOfRange = 9 Const BITS_PER_ELEMENT = 8 Private mBits() As Byte Private mNumElements As Long Private Sub Class_Initialize() End Sub Private Sub Class_Terminate() Erase mBits End Sub Public Property Let NumElements(NewValue As Long) mNumElements = NewValue ReDim Preserve mBits(mNumElements \ BITS_PER_ELEMENT) End Property Public Property Get NumElements() As Long NumElements = mNumElements End Property '------------------------------------------------------ '-- METHODS '------------------------------------------------------ Public Sub ClearAll() Dim i As Long '-- Set bit values in BITS_PER_ELEMENT chunks for speed For i = LBound(mBits) To UBound(mBits) mBits(i) = &H0 Next i End Sub Public Sub ClearBit(Index As Long) '-- Set Bit(Index) value to 0 Dim ArrayIdx As Long Dim Bit As Long Call ValidateIndex(Index) ArrayIdx = Index \ BITS_PER_ELEMENT Bit = Index Mod BITS_PER_ELEMENT 'Debug.Print "Clearing ArrayIdx:"; ArrayIdx, " Bit:"; Bit mBits(ArrayIdx) = mBits(ArrayIdx) And (Not (2 ^ Bit)) End Sub Public Function GetBit(Index As Long) As Integer '-- Returns 0 or 1 Call ValidateIndex(Index) If IsBitSet(Index) Then GetBit = 1 Else GetBit = 0 End If End Function Public Function IsBitSet(Index As Long) As Boolean Dim ArrayIdx As Long Dim Bit As Long Call ValidateIndex(Index) ArrayIdx = Index \ BITS_PER_ELEMENT Bit = Index Mod BITS_PER_ELEMENT 'Debug.Print "Testing ArrayIdx:"; ArrayIdx, " Bit:"; Bit If mBits(ArrayIdx) And 2 ^ Bit Then IsBitSet = True Else IsBitSet = False End If End Function Public Sub SetAll() Dim i As Long '-- Set bit values in BITS_PER_ELEMENT chunks for speed For i = LBound(mBits) To UBound(mBits) mBits(i) = &HFF Next i End Sub Public Sub SetBit(Index As Long) '-- Set Bit(Index) value to 1 Dim ArrayIdx As Long Dim Bit As Long Call ValidateIndex(Index) ArrayIdx = Index \ BITS_PER_ELEMENT Bit = Index Mod BITS_PER_ELEMENT 'Debug.Print "Setting ArrayIdx:"; ArrayIdx, " Bit:"; Bit mBits(ArrayIdx) = mBits(ArrayIdx) Or 2 ^ Bit End Sub Public Sub ToggleBit(Index As Long) '-- Toggle the value of Bit(Index) Call ValidateIndex(Index) If IsBitSet(Index) Then Call ClearBit(Index) Else Call SetBit(Index) End If End Sub Private Sub ValidateIndex(Index As Long) '-- Our bounds checking code is aware that this is ' a 0 based array of bits. If (Index < 0) Or (Index > (mNumElements - 1)) Then RaiseError vbErrSubscriptOutOfRange End If End Sub '------------------------------------------------------ '-- ERRORS '------------------------------------------------------ ' .GetErrorDesc Private Function GetErrorDesc(ErrCode As Long) As String Dim Desc As String Select Case ErrCode Case vbErrSubscriptOutOfRange Desc = "Subscript out of Range" Case Else Desc = "Unknown error" End Select GetErrorDesc = Desc End Function ' .RaiseError Private Sub RaiseError(ErrCode As Long) Err.Raise Number:=vbObjectError + ErrCode, _ Source:=CLASS_NAME & " " & CLASS_VERSION, _ Description:=GetErrorDesc(ErrCode) 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:
Private Sub cmdTest1_Click() Dim BitSet1 As BitVector Dim BitSet As New BitVector Dim HashArray() As String Dim ac As String Dim ParsedNumArray() As String Dim i1, jtemp, j1 As Integer BitSet.NumElements = 64 HashArray() = Split("LHKf24(),..FWSqw1,783vcSWr,NSW%FGS3,S834VS$!", ",") ParsedNumArray() = Split("58#54#58#42#50#", "#") For i1 = 0 To 4 Set BitSet1 = BitShift(HashArray(i1)) j1 = Val(ParsedNumArray(i1)) For l1 = 0 To j1 Set BitSet1 = BitFlag(BitSet1) Next For x = 0 To 63 BitSet.SetBit (CLng(x)) Xor BitSet1.GetBit(CLng(x)) Next Next i1 ac = Characterize(BitSet, 8) End Sub Private Function BitShift(ac As String) As BitVector Dim i1 As Integer Dim k1 As Integer Dim l1 As Integer Dim TempBitSet1 As BitVector Set TempBitSet1 = New BitVector i1 = Len(ac) * 8 TempBitSet1.NumElements = i1 For j1 = 0 To i1 k1 = j1 & 7 l1 = j1 \ 8 If l1 <> 8 Then If (Asc(Mid(ac, l1 + 1, 1)) And &HFF And 128 - k1) <> 0 Then TempBitSet1.SetBit (j1) Next j1 Set BitShift = TempBitSet1 End Function Private Function BitFlag(BitSet As BitVector) As BitVector Dim BitSet1 As BitVector Dim Flag As Boolean Dim i1 As Integer Set BitSet1 = New BitVector BitSet1.NumElements = 64 Flag = False For i1 = 0 To 63 If Flag <> BitSet.GetBit(CLng(i1)) Then BitSet1.SetBit (CLng(i1)) Flag = BitSet.GetBit(CLng(i1)) Next i1 Set BitFlag = BitSet1 End Function Private Function Characterize(BitSet As BitVector, i1 As Integer) As String Dim ji, k1, l1, i2 As Integer Dim ac As String j1 = i1 * 8 ac = String(i1, 0) For k1 = 0 To j1 - 1 l1 = k1 And 7 i2 = k1 \ 8 If BitSet.get(k1) Then Mid$(ac, i2 + 1, 1) = Chr(Asc(Mid$(ac, i2 + 1, 1)) Or 128 - l1) End If Next k1 Characterize = ac 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
