Code:
Imports System.Text
Imports System.Security.Cryptography
Imports System
Imports System****
Imports System.Xml
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ofd As New OpenFileDialog
ofd.Filter = "*.* All Files|*.*"
ofd.FilterIndex = 1
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
TextBox1.Text = ofd.FileName
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sfd As New SaveFileDialog
sfd.Filter = "*.txt|*.txt"
sfd.SupportMultiDottedExtensions = True
If sfd.ShowDialog() = Windows.Forms.DialogResult.OK Then
Else
sfd.ShowDialog()
End If
Dim notepad As String = Convert.ToBase64String(IO.File.ReadAllBytes(TextBox1.Text))
IO.File.AppendAllText(sfd.FileName, notepad)
End Sub
Public Function AES_Encrypt(ByVal input As String, ByVal pass As String) As String
Dim AES As New System.Security.Cryptography.RijndaelManaged
Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim encrypted As String = ""
Try
Dim hash(31) As Byte
Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
Array.Copy(temp, 0, hash, 0, 16)
Array.Copy(temp, 0, hash, 15, 16)
AES.Key = hash
AES.Mode = Security.Cryptography.CipherMode.ECB
Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor
Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)
encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
Return encrypted
Catch ex As Exception
End Try
End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim ofd As New OpenFileDialog
ofd.Filter = "*.* All Files|*.*"
ofd.FilterIndex = 1
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
End If
Dim sfd As New SaveFileDialog
sfd.Filter = "*.txt|*.txt"
sfd.SupportMultiDottedExtensions = True
If sfd.ShowDialog() = Windows.Forms.DialogResult.OK Then
Else
sfd.ShowDialog()
End If
Dim notepad As String = AES_Encrypt(IO.File.ReadAllText(ofd.FileName), TextBox2.Text)
IO.File.AppendAllText(sfd.FileName, notepad)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim ofd As New OpenFileDialog
ofd.Filter = "*.* All Files|*.*"
ofd.FilterIndex = 1
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
End If
Dim sfd As New SaveFileDialog
sfd.Filter = "*.txt|*.txt"
sfd.SupportMultiDottedExtensions = True
If sfd.ShowDialog() = Windows.Forms.DialogResult.OK Then
Else
sfd.ShowDialog()
End If
Dim notepad As String = CustomXOR_Encrypt(IO.File.ReadAllText(ofd.FileName), TextBox3.Text)
IO.File.AppendAllText(sfd.FileName, notepad)
End Sub
Public Function CustomXOR_Encrypt(ByVal Input As String, ByVal pass As String) As String
Dim out As New System.Text.StringBuilder
Dim Hash As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim XorHash As Byte() = Hash.ComputeHash(System.Text.Encoding.ASCII.GetBytes(pass))
Dim u As Integer
For i As Integer = 0 To Input.Length - 1
Dim tmp As String = Hex(Asc(Input(i)) Xor XorHash(u))
If tmp.Length = 1 Then tmp = "0" & tmp
out.Append(tmp)
If u = pass.Length - 1 Then u = 0 Else u = u + 1
Next
Return out.ToString
End Function
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 Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim ofd As New OpenFileDialog
ofd.Filter = "*.* All Files|*.*"
ofd.FilterIndex = 1
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
End If
Dim sfd As New SaveFileDialog
sfd.Filter = "*.txt|*.txt"
sfd.SupportMultiDottedExtensions = True
If sfd.ShowDialog() = Windows.Forms.DialogResult.OK Then
Else
sfd.ShowDialog()
End If
Dim notepad As String = rc4(IO.File.ReadAllText(ofd.FileName), TextBox4.Text)
IO.File.AppendAllText(sfd.FileName, notepad)
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim ofd As New OpenFileDialog
ofd.Filter = "*.* All Files|*.*"
ofd.FilterIndex = 1
If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
End If
Dim sfd As New SaveFileDialog
sfd.Filter = "*.txt|*.txt"
sfd.SupportMultiDottedExtensions = True
If sfd.ShowDialog() = Windows.Forms.DialogResult.OK Then
Else
sfd.ShowDialog()
End If
Dim notepad As String = PolyZero(IO.File.ReadAllText(ofd.FileName), TextBox5.Text)
IO.File.AppendAllText(sfd.FileName, notepad)
End Sub
Private key() As Byte = {}
Private IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}
Private Const EncryptionKey As String = "abcdefgh"
'Public Function Decrypt(ByVal stringToDecrypt As String) As String
' Try
' Dim inputByteArray(stringToDecrypt.Length) As Byte
' key = System.Text.Encoding.UTF8.GetBytes(Left(EncryptionKey, 8))
' Dim des As New DESCryptoServiceProvider
' inputByteArray = Convert.FromBase64String(stringToDecrypt)
' Dim ms As New MemoryStream
' Dim cs As New CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write)
' cs.Write(inputByteArray, 0, inputByteArray.Length)
' cs.FlushFinalBlock()
' Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8
' Return encoding.GetString(ms.ToArray())
' Catch ex As Exception
' 'oops - add your exception logic
' End Try
'End Function
'Public Function Encrypt(ByVal stringToEncrypt As String) As String
' Try
' key = System.Text.Encoding.UTF8.GetBytes(Left(EncryptionKey, 8))
' Dim des As New DESCryptoServiceProvider
' Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes(stringToEncrypt)
' Dim ms As New MemoryStream
' Dim cs As New CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write)
' cs.Write(inputByteArray, 0, inputByteArray.Length)
' cs.FlushFinalBlock()
' Return Convert.ToBase64String(ms.ToArray())
' Catch ex As Exception
' 'oops - add your exception logic
' End Try
'End Function
Public Function PolyZero(ByVal data As String, ByVal password As String) As String
Dim rand As New Random
Dim pass2 As Integer = rand.[Next](2, 999)
Dim retStr As String = String.Empty
Dim dataChars As Char() = data.ToCharArray
For i As Integer = 0 To dataChars.Length - 1
If i = dataChars.Length - 1 Then
retStr &= ((AscW(dataChars(i)) + GP(password)) + pass2)
Else
retStr &= ((AscW(dataChars(i)) + GP(password)) + pass2) & ","
End If
Next
retStr &= "," & pass2
Return retStr
End Function
Private Function GP(ByVal p As String) As Integer
Dim z As Char() = p.ToCharArray
Dim retVal As Integer = 0
For Each t As Char In z
retVal += AscW(t)
Next
Return retVal
End Function
End Class