## 4 replies

Last post Oct 21, 2008 12:06 PM by kal30

Member

35 Points

169 Posts

### convert to vb

I did use a converter but I still would like to know what this code does.  This is Java code.

antranspositions[ k++ ] = ( i << 8 ) | j;

This is the conversion i got.

antranspositions(System.Math.Max(System.Threading.Interlocked.Increment(k), k - 1)) = (i << 8) Or j

I was wondering if anyone can say if this is right.  I am getting an error at this point.

Thank you

Participant

1721 Points

543 Posts

### Re: convert to vb

I would say the line needs to be broken up

k+= 1

if i << 8 then

ant(k) = i<<8

else

ant(k) = j

end if

Hope this helps

DK

Contributor

2132 Points

675 Posts

### Re: convert to vb

Oct 20, 2008 11:24 PM|David Anton|LINK

k++ means that the increment happens later rather than earlier (i.e., it's incremented after the value is taken for the expression), so the correct conversion (via Java to VB & C# Converter) is:

```antranspositions(k) = (i << 8) Or j
k += 1```

David Anton
http://www.tangiblesoftwaresolutions.com
Instant C# - VB to C# Converter
Instant VB - C# to VB Converter

Member

35 Points

169 Posts

### Re: convert to vb

Thank you so much for all your help.  Got it to work.

Member

35 Points

169 Posts

### Re: convert to vb

Please ignore this.  I got this to work.

private static int[] password_getpermutation(String strpasswd) {
int nNUMELEMENTS = 13;
int nCYCLELENGTH = 21;
int[] antranspositions = new int[(nNUMELEMENTS - 1) * (nNUMELEMENTS - 2)];
int nNumtranspositions = permutationGenerator(nNUMELEMENTS, antranspositions);
int[] anCycle = new int[nCYCLELENGTH];

for (int i = 0; i < nCYCLELENGTH; i++) {

npred = 314159269 * npred + 907633409;
anCycle[i] = (int)(npred % nNumtranspositions);
anCycle[i] = anCycle[i] < 0 ? -anCycle[i] : anCycle[i];
if ( anCycle[i] > 60 ) {
anCycle[i] = 60;
}
}

return permutationGenerator_fromCycle(anCycle, nNUMELEMENTS, antranspositions);
}

This is my translation to this.

Private Shared Function password_getPermutation(ByVal strpwd As String) As Integer()

Dim nNUMELEMENTS As Integer = 13

Dim nCYCLELENGTH As Integer = 21

Dim antranspositions() As Integer = {(nNUMELEMENTS - 1) * (nNUMELEMENTS - 2)}

Dim nNumtranspositions As Integer = PermutationGenerator(nNUMELEMENTS, antranspositions)

Dim anCycle() As Integer = {nCYCLELENGTH}

Dim nPred As Double = password_getHashValue(strpwd)

For i As Integer = 0 To nCYCLELENGTH - 1

nPred = 314159269 * nPred + 907633409

anCycle(i) = CType(nPred Mod nNumtranspositions, Double)

IIf(anCycle(i) < 0, -anCycle(i), anCycle(i))

If (anCycle(i) > 60) Then

anCycle(i) = 60

End If

Next

Return permutationGenerator_fromCycle(anCycle, nNUMELEMENTS, antranspositions)

End Function

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I rewrote my PermutationGenerator function with the new syntax.

Private Shared Function permutationGenerator(ByVal nNumElements As Integer, ByVal antranspositions As Integer()) As Integer

Dim k As Integer = 0

For i As Integer = 0 To nNumElements - 1

For j As Integer = i + 1 To nNumElements - 1

If i << 8 Then

antranspositions(k) = (i << 8)

Else

antranspositions(k) = j  ' It errors out here with Index out of range error.  Is antranspositions array wrong?

End If

k += 1

Next

Next

' keep two positions as lo and hi byte!

Dim nNumtranspositions As Integer = k Return nNumtranspositions

End Function

Thank you for all your help.