Code: Streaming RC4 implementation in VB.NET 
Author Message
 Code: Streaming RC4 implementation in VB.NET

I posted this to Planet Source Code and thought some of you might be
interested in looking at it.

Of course, if anyone feels inspired to visit
http://www.*-*-*.com/
for my code, I would greatly appreciate it.  I plan on winning that contest,
one of these months!  :)  Fans of sample projects can find a ZIP file there
containing a very simple implementation example.

The nice thing about the class, I think, is that since it works byte-by-byte
instead of at a string level it can be used for really big files.

Thanks to all the VB.NET designers, too, for finally giving us assignment
operators (+=, *=, etc) and "return (x)"!  The framework is slightly
intimidating at first, but VB7 really is feeling more and more like a
bigger, better home.

--- Begin Code ---

Option Explicit On
Option Strict Off

Public Class clsRC4
  Dim arrState(255) As Short
  Dim arrKey(255) As Short

  Public Sub Init(ByVal strKey As String)
    Dim temp As Short
    Dim i, j As Short

    j = 0

    For i = 0 To 255
      j = j + 1
      If j > Len(strKey) Then j = 1
      arrKey(i) = Asc(Mid(strKey, j, 1))
    Next i

    For i = 0 To 255
      arrState(i) = i
    Next i

    j = 0

    For i = 0 To 255
      j = (j + arrState(i) + arrKey(i)) Mod 256

      temp = arrState(i)
      arrState(i) = arrState(j)
      arrState(j) = temp
    Next i
  End Sub

  Public Function Crypt(ByVal bytSource As Byte) As Byte
    Dim temp As Short
    Dim i, j, k As Short

    i = (i + 1) Mod 256
    j = (j + arrState(i)) Mod 256

    temp = arrState(i)
    arrState(i) = arrState(j)
    arrState(j) = temp

    k = arrState((arrState(i) + arrState(j)) Mod 256)

    Return (bytSource Xor k)
  End Function
End Class

--- End Code ---



Sun, 30 Jan 2005 09:35:54 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Code: Streaming RC4 implementation in VB.NET

2. vb.net code transform to asp.net code?

3. Anonymous Pipe Implementation using VB.Net ?

4. Lack of support for explicit interface implementation in VB.Net

5. Using SharpZipLib To Get a Zipped Stream (VB.Net)

6. VB.NET Socket stream reliability

7. DX9 - Playing a streaming sound from a memory stream (not file stream)

8. VB code to handle 3270 Data Streams

9. RC4 encryption componant for VB

10. Passing Form Fields to VB.NET Custom Business Object in an ASP.NET Code Behind Page

11. Sorting fiels in Crystal .NET by code VB .NET

12. Native .Net serial port implementation

 

 
Powered by phpBB® Forum Software