Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Text
- Public Class Form1
- Const filesplit = "123456789"
- Private Sub jouvre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles jouvre.Click
- Dim x As New OpenFileDialog 'simule une open file dialog
- x.Filter = "Exécutables |*.exe" 'nous indique quel fichier peut être séléctionné ici uniquement les éxecutables
- x.InitialDirectory = "/VotreDossier" 'le répertoire de départ lorsque la boite de dialogue s'affichera
- x.Multiselect = False 'séléctionner plusieurs fichiers ? Dans notre cas non laissez sur "False"
- If x.ShowDialog = Windows.Forms.DialogResult.OK Then ' si on clique sur "OK"
- emplacement.Text = x.FileName 'la textebox emplacement affiche où ce situe notre fichier à crytper.
- Else 'si aucune action ne s'éxécute (exemple : on ne séléctionne pas de fichier)
- MsgBox("Vous n'avez pas ouvert de fichier !") 'affiche message
- jecrytpe.Enabled = False 'le bouton crypter ne devient plus utilisable
- emplacement.Text = "aucun fichier !" 'la textbox "emplacement" nous affiche qu'il n'y a aucun fichier
- End If ' fin de la réponse
- End Sub
- Public 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 jecrytpe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles jecrytpe.Click
- Dim filein, filename, stub As String
- Dim sfd As New SaveFileDialog
- sfd.Filter = "Exécutables |*.exe "
- If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
- filename = sfd.FileName
- Else : Exit Sub
- End If
- FileOpen(1, emplacement.Text, OpenMode.Binary, OpenAccess.Read, OpenShare.Default)
- filein = Space(LOF(1))
- FileGet(1, filein)
- FileClose(1)
- FileOpen(1, Application.StartupPath & "\Stub.exe", OpenMode.Binary, OpenAccess.Read, OpenShare.Default)
- stub = Space(LOF(1))
- FileGet(1, stub)
- FileClose(1)
- FileOpen(1, filename, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Default)
- FilePut(1, stub & filesplit & RC4(filein, "123456789"))
- FileClose(1)
- MsgBox("le fichier a été crypté")
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement