Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6090839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:15:35+00:00 2026-05-23T12:15:35+00:00

I was put in a situation where I had to convert RC4 code from

  • 0

I was put in a situation where I had to convert RC4 code from c# into vb
I tried getting already made codes online but they did not seem to work as the currently c# one that I have.
I am very new to VB so this is very hard for me. Maybe a professional will see the mistake I am making. Both codes give a different encrypted result.

c# code:

public static string RC4(string pStrMessage, string pStrKey)
        {
            char[] lBytAsciiAry;
            int[] lBytKeyAry;
            int lLngIndex;  //
            int lBytJump;
            char lBytTemp;
            int lBytY;
            int lLngT;
            int lLngX;
            int lLngKeyLength;  //
            string encrypt; //The encrypted message

            lLngKeyLength = pStrKey.Length;
            if (lLngKeyLength < 1)
                return string.Empty;

            if (pStrMessage.Length < 1)
                return string.Empty;

            lBytAsciiAry = new char[256];
            lBytKeyAry = new int[256];

            for (lLngIndex = 0; lLngIndex < 256; lLngIndex++)
            {
                lBytKeyAry[lLngIndex] = pStrKey[(lLngIndex % lLngKeyLength)];
            }

            for (lLngIndex = 0; lLngIndex < 256; lLngIndex++)
            {
                lBytAsciiAry[lLngIndex] = Convert.ToChar(lLngIndex);
            }

            lBytJump = 0;
            for (lLngIndex = 0; lLngIndex < 256; lLngIndex++)
            {
                lBytJump = (lBytJump + lBytAsciiAry[lLngIndex] + lBytKeyAry[lLngIndex]) % 256;
                lBytTemp = lBytAsciiAry[lLngIndex];
                lBytAsciiAry[lLngIndex] = lBytAsciiAry[lBytJump];
                lBytAsciiAry[lBytJump] = Convert.ToChar(lBytTemp);
            }

            lLngIndex = 0;
            lBytJump = 0;
            encrypt = "";
            for (lLngX = 0; lLngX < pStrMessage.Length; lLngX++)
            {
                lLngIndex = (lLngIndex + 1) % 256; // wrap index
                lBytJump = (lBytJump + lBytAsciiAry[lLngIndex]) % 256; // wrap J+S()
                lLngT = (lBytAsciiAry[lLngIndex] + lBytAsciiAry[lBytJump]) % 256;
                //swap
                lBytTemp = lBytAsciiAry[lLngIndex];
                lBytAsciiAry[lLngIndex] = lBytAsciiAry[lBytJump];
                lBytAsciiAry[lBytJump] = lBytTemp;

                lBytY = lBytAsciiAry[lLngT];
                //encrypt = encrypt + Chr(Asc(Mid(pStrMessage, lLngX, 1)) Xor lBytY)
                encrypt = encrypt + Convert.ToChar(pStrMessage[lLngX] ^ lBytY);
            }

            return encrypt;
        }

my VB translation of it:

   Public Function RC4(ByVal pStrMessage As String, ByVal pStrKey As String) As String
        Dim lBytAsciiAry(0 To 256) As Char
        Dim lBytKeyAry(0 To 256) As Integer
        Dim lLngIndex As Integer
        Dim lBytJump As Integer
        Dim lBytTemp As Char
        Dim lBytY As Integer
        Dim lLngT As Integer
        Dim lLngX As Integer
        Dim lLngKeyLength As Integer
        Dim encrypt As String

        lLngKeyLength = pStrKey.Length

        If lLngKeyLength < 1 Then
            Return String.Empty
        End If

        If pStrMessage.Length < 1 Then
            Return String.Empty
        End If

        For lLngIndex = 0 To 255
            lBytKeyAry(lLngIndex) = Val(pStrKey((lLngIndex Mod lLngKeyLength)))
        Next

        For lLngIndex = 0 To 255
            lBytAsciiAry(lLngIndex) = Convert.ToChar(lLngIndex)
        Next

        lBytJump = 0
        For lLngIndex = 0 To 255
            lBytJump = (lBytJump + Asc(lBytAsciiAry(lLngIndex)) + lBytKeyAry(lLngIndex)) Mod 256
            lBytTemp = lBytAsciiAry(lLngIndex)
            lBytAsciiAry(lLngIndex) = lBytAsciiAry(lBytJump)
            lBytAsciiAry(lBytJump) = Convert.ToChar(lBytTemp)
        Next

        lLngIndex = 0
        lBytJump = 0
        encrypt = ""

        For lLngX = 0 To pStrMessage.Length - 1
            lLngIndex = (lLngIndex + 1) Mod 256
            lBytJump = (lBytJump + Asc(lBytAsciiAry(lLngIndex))) Mod 256
            lLngT = Asc(lBytAsciiAry(lLngIndex) + lBytAsciiAry(lBytJump)) Mod 256

            lBytTemp = lBytAsciiAry(lLngIndex)
            lBytAsciiAry(lLngIndex) = lBytAsciiAry(lBytJump)
            lBytAsciiAry(lBytJump) = lBytTemp

            lBytY = Asc(lBytAsciiAry(lLngT))
            encrypt = encrypt + Convert.ToChar(Asc(pStrMessage(lLngX)) Xor lBytY)
        Next

        Return encrypt
    End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:15:36+00:00Added an answer on May 23, 2026 at 12:15 pm

    Try using this C# to VB converter to see if you get the desired result http://www.developerfusion.com/tools/convert/csharp-to-vb/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, So I have the following situation. I originally had some code like this:
My current situation is: I have to read a file and put the contents
Put it another way: what code have you written that cannot fail. I'm interested
I have unfortunately wandered into a situation where I need regex using Ruby. Basically
Have been getting pretty bald over this situation! I am using MS VS 2010
I'm trying to learn effective DDD practices as I go, but had a fundamental
So here is the situation-- a quote from my boss: [...] we need to
Recently I had cause to compare Blowfish algorithms. I was comparing outputs from DI
I've seen lots of book and article examples saying to put validation code in
Good day, I've done some research looking for this answer, but haven't had much

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.