Array From C # to Visual Basic

0

I have the following algorithm in C #:

public static int Encriptar(string cad) {
        int[,] mul = { {0,1,2,3,4,5,6,7,8,9},
                       {1,2,3,4,0,6,7,8,9,5},
                       {2,3,4,0,1,7,8,9,5,6},
                       {3,4,0,1,2,8,9,5,6,7},
                       {4,0,1,2,3,9,5,6,7,8},
                       {5,9,8,7,6,0,4,3,2,1},
                       {6,5,9,8,7,1,0,4,3,2},
                       {7,6,5,9,8,2,1,0,4,3},
                       {8,7,6,5,9,3,2,1,0,4},
                       {9,8,7,6,5,4,3,2,1,0}
                     };
        int[,] per= {{0,1,2,3,4,5,6,7,8,9},
                    {1,5,7,6,2,8,3,0,9,4},
                    {5,8,0,3,7,9,6,1,4,2},
                    {8,9,1,6,0,4,3,5,2,7},
                    {9,4,5,3,1,2,6,8,7,0},
                    {4,2,8,6,5,7,3,9,0,1},
                    {2,7,9,3,8,0,6,4,1,5},
                    {7,0,4,6,9,1,3,2,5,8}};
        int[] inv={0,4,3,2,1,5,6,7,8,9};
        int check = 0;
        int i = 0;
        string invertido=invertir(cad);
        for (i = 0; i < invertido.Length; i++ )
        {
            check=mul[check,per[((i+1)%8),int.Parse(invertido[i].ToString())]];
        }
        return inv[check];
    }

And I am translating it to Visual Basic:

Function Encriptar(cad As String) As Integer
    Dim mul = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
                   {1, 2, 3, 4, 0, 6, 7, 8, 9, 5},
                   {2, 3, 4, 0, 1, 7, 8, 9, 5, 6},
                   {3, 4, 0, 1, 2, 8, 9, 5, 6, 7},
                   {4, 0, 1, 2, 3, 9, 5, 6, 7, 8},
                   {5, 9, 8, 7, 6, 0, 4, 3, 2, 1},
                   {6, 5, 9, 8, 7, 1, 0, 4, 3, 2},
                   {7, 6, 5, 9, 8, 2, 1, 0, 4, 3},
                   {8, 7, 6, 5, 9, 3, 2, 1, 0, 4},
                   {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}
                 }
    Dim per = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
                {1, 5, 7, 6, 2, 8, 3, 0, 9, 4},
                {5, 8, 0, 3, 7, 9, 6, 1, 4, 2},
                {8, 9, 1, 6, 0, 4, 3, 5, 2, 7},
                {9, 4, 5, 3, 1, 2, 6, 8, 7, 0},
                {4, 2, 8, 6, 5, 7, 3, 9, 0, 1},
                {2, 7, 9, 3, 8, 0, 6, 4, 1, 5},
                {7, 0, 4, 6, 9, 1, 3, 2, 5, 8}}
    Dim inv = {0, 4, 3, 2, 1, 5, 6, 7, 8, 9}
    Dim check = 0
    Dim invertido As String = StrReverse(cad)
    For i As Integer = 0 To invertido.Length
        check = mul(check, per( [[i]+1]%8 , invertido(i).ToString()))
    Next
    Return inv(check)
End Function

The problem is that I'm just learning VB and I have an error in the line

check = mul(check, per( [[i]+1]%8 , invertido(i).ToString()))

Help translate that line please.

It should be noted that the input parameter is a string of only numbers.

    
asked by Shassain 09.03.2018 в 04:09
source

1 answer

2

The way to access the array is incorrect, you also have to convert the inverted sub-chain to Integer .

check = mul(check, per((i+1) Mod 8, Integer.Parse(invertido(i).ToString()) ))
    
answered by 09.03.2018 / 17:18
source