Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[VB.NET] RC4 Encryption Module
#1
Hi everyone, this is an example of RC4 Encryption by Oddworth. Enjoy


Source Code:

On top of source code add our imortant:
Code:
Imports System.Text

Then anywhere else except in Form1, Button1 or any kind of Sub post function:
Code:
Public Shared Function rc4(ByVal message As String, ByVal password As String) As String

        Dim i As Integer = 0
        Dim j As Integer = 0
        Dim cipher As New StringBuilder
        Dim returnCipher As String = String.Empty

        Dim sbox As Integer() = New Integer(256) {}
        Dim key As Integer() = New Integer(256) {}

        Dim intLength As Integer = password.Length

        Dim a As Integer = 0
        While a <= 255

            Dim ctmp As Char = (password.Substring((a Mod intLength), 1).ToCharArray()(0))

            key(a) = Microsoft.VisualBasic.Strings.Asc(ctmp)
            sbox(a) = a
            System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
        End While

        Dim x As Integer = 0

        Dim b As Integer = 0
        While b <= 255
            x = (x + sbox(b) + key(b)) Mod 256
            Dim tempSwap As Integer = sbox(b)
            sbox(b) = sbox(x)
            sbox(x) = tempSwap
            System.Math.Max(System.Threading.Interlocked.Increment(b), b - 1)
        End While

        a = 1

        While a <= message.Length

            Dim itmp As Integer = 0

            i = (i + 1) Mod 256
            j = (j + sbox(i)) Mod 256
            itmp = sbox(i)
            sbox(i) = sbox(j)
            sbox(j) = itmp

            Dim k As Integer = sbox((sbox(i) + sbox(j)) Mod 256)

            Dim ctmp As Char = message.Substring(a - 1, 1).ToCharArray()(0)

            itmp = Asc(ctmp)

            Dim cipherby As Integer = itmp Xor k

            cipher.Append(Chr(cipherby))
            System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
        End While

        returnCipher = cipher.ToString
        cipher.Length = 0

        Return returnCipher

    End Function

How to use source:
Code:
rc4("Text","password")
Reply
#2
Thanks for this.
Reply
#3
Awesome tut,Thanks
[Image: 20r9vh4.jpg]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Source] TripleDES String Encryption / Decryption euverve 2 3,342 05-13-2011, 10:35 AM
Last Post: Imports System.Net
  [Source] Encrypt/Decrypt a string using Data Encryption Standard (DES) algorithm euverve 0 1,998 05-12-2011, 08:43 PM
Last Post: euverve
  [Help] [VB.NET 2008] Textbox Contents Encryption. Example 4 4,001 02-23-2011, 01:16 AM
Last Post: Example
  [C#] Simple RC2 Encryption/Decryption [Intermediate] Mike 3 3,569 12-21-2010, 11:38 PM
Last Post: ZxPwn420
  encryption function Digital-Punk 7 1,639 08-13-2010, 11:20 AM
Last Post: .Nielz

Forum Jump:


Users browsing this thread: 1 Guest(s)