RC4 TextFile Encrypter!
Posted: Fri Nov 11, 2011 3:18 pm
What you need:
1 open file dialog
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 save file dialog
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 text box's:
Textbox 1 needs to be read only!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 buttons:
Button 1 is called select file and goes
by textbox 1
Button 2 is called encrypt file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 label
RC4 Password and goes by textbox 2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Imports:
An old friend of mine for helping me: 90%
Me: 10%
cooll;
1 open file dialog
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 save file dialog
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 text box's:
Textbox 1 needs to be read only!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 buttons:
Button 1 is called select file and goes
by textbox 1
Button 2 is called encrypt file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 label
RC4 Password and goes by textbox 2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Imports:
Code: Select all
The whole code from start to end after import copy and paste!
Imports System.IO
Imports System.Text
Code: Select all
Credits:Public Class Form1
Dim filereadin, fileout As String
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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
TextBox1.Text = OpenFileDialog1.FileName
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = "" Then
MessageBox.Show("Pick A File!", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If TextBox2.Text = "" Then
MessageBox.Show("Pick A Password", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
FileOpen(1, TextBox1.Text, OpenMode.Binary, OpenAccess.Read, OpenShare.Default)
filereadin = Space(LOF(1))
FileGet(1, filereadin)
FileClose(1)
SaveFileDialog1.ShowDialog()
Try
fileout = SaveFileDialog1.FileName
FileOpen(1, fileout, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Default)
FilePut(1, rc4(filereadin, TextBox2.Text))
FileClose(1)
TextBox1.Text = ""
MessageBox.Show(fileout & " Was created!", "Done", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Catch ex As Exception
End Try
End Sub
End Class
An old friend of mine for helping me: 90%
Me: 10%
cooll;