RC4 TextFile Encrypter!

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
9 posts Page 1 of 1
Contributors
User avatar
pip
VIP - Donator
VIP - Donator
Posts: 156
Joined: Tue Jul 12, 2011 3:13 am

RC4 TextFile Encrypter!
pip
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:
Code: Select all
Imports System.IO
Imports System.Text
The whole code from start to end after import copy and paste!
Code: Select all
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
Credits:
An old friend of mine for helping me: 90%
Me: 10%

cooll;
<a href="http://www.points2shop.com/s/xbox_point ... 5082"><img src="http://points2shop.com/images/promotion ... ricoxg.gif" border="0"/></a>
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Re: RC4 TextFile Encrypter!
Dummy1912
so is the password gonna be saved in the same file as the orginal file or will there be a separate file with the password.
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
pip
VIP - Donator
VIP - Donator
Posts: 156
Joined: Tue Jul 12, 2011 3:13 am

Re: RC4 TextFile Encrypter!
pip
Seperate thats why the save file dialog is there :D
<a href="http://www.points2shop.com/s/xbox_point ... 5082"><img src="http://points2shop.com/images/promotion ... ricoxg.gif" border="0"/></a>
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Re: RC4 TextFile Encrypter!
Dummy1912
pip wrote:
Seperate thats why the save file dialog is there :D

so what will happen if someone delete that file.
can you still access your rc4 file without it

or do i understand it a little wrong?
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
pip
VIP - Donator
VIP - Donator
Posts: 156
Joined: Tue Jul 12, 2011 3:13 am

Re: RC4 TextFile Encrypter!
pip
its whatever yo utype password or text it encrypts in file it really is back up but encrypted
<a href="http://www.points2shop.com/s/xbox_point ... 5082"><img src="http://points2shop.com/images/promotion ... ricoxg.gif" border="0"/></a>
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Re: RC4 TextFile Encrypter!
Dummy1912
o cool :)

thanks pip :D
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
clanc789
Coding Guru
Coding Guru
Posts: 786
Joined: Tue Nov 02, 2010 4:45 pm

Re: RC4 TextFile Encrypter!
clanc789
+rep for this <3! I searched for this a long long time!!!
Practice makes perfect!

VIP since: 6-10-2011
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

Re: RC4 TextFile Encrypter!
hungryhounduk
Hey Pip
What i would really like is to be able to DECrypt the Encrypted file back to it's original state.... It would make a great little addition to an app i am working on, where you could send someone a encrypted file and as long as they have the Decrypter app and Password to the Encrypted file, they could then turn the file back to it's original state..

Just a Thought

Chris
Image
User avatar
pip
VIP - Donator
VIP - Donator
Posts: 156
Joined: Tue Jul 12, 2011 3:13 am

Re: RC4 TextFile Encrypter!
pip
#hungryhounduk A bit lazy to try, but here is a supposed idea this code that creates it:
Code: Select all
 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
You need to take this : FilePut(1, rc4(filereadin, TextBox2.Text)) and whatever hash or encrypted thing try to make a function that reverses the encryption and just make it do this:
Code: Select all
FilePut(1, rc4(filereadin, EncryptedTextBox2.Text))
so prob some stuff to select were file is and a textbox for entering the pass like one of shims apps, and maybe another string.
<a href="http://www.points2shop.com/s/xbox_point ... 5082"><img src="http://points2shop.com/images/promotion ... ricoxg.gif" border="0"/></a>
9 posts Page 1 of 1
Return to “Tutorials”