VB 11 Simple Applications: Encryption
Just an Example of a simple encryption you can make with your friends.
If you would like to skip this, and would like to just download the source code click Here
Public Class Form1
Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click
If OpenFileDialog1.ShowDialog = vbOK Then
Dim x() As Byte = IO.File.ReadAllBytes(OpenFileDialog1.FileName)
ProgressBarControl1.EditValue = 0
ProgressBarControl1.Properties.Step = 1
ProgressBarControl1.Properties.Maximum = x.Length - 1
Scramble(x)
If SaveFileDialog1.ShowDialog() = vbOK Then
IO.File.WriteAllBytes(SaveFileDialog1.FileName, x)
End If
End If
End Sub
Public Sub Scramble(ByRef File() As Byte)
' we need to scramble to the amount length
Dim nFile(File.Length - 1) As Byte
Dim x As Long = 0
Dim y As Long = File.Length - 1
For i = 1 To File.Length
If i Mod 2 Then
nFile(i - 1) = File(y)
y -= 1
Else
nFile(i - 1) = File(x)
x += 1
End If
ProgressBarControl1.PerformStep()
ProgressBarControl1.Update()
Next
File = nFile
End Sub
Public Sub DeScramble(ByRef file() As Byte)
' we need to scramble to the amount length
Dim nFile(file.Length - 1) As Byte
Dim x As Long = 0
Dim y As Long = file.Length - 1
For i = 1 To file.Length
If i Mod 2 Then
nFile(y) = file(i - 1)
y -= 1
Else
nFile(x) = file(i - 1)
x += 1
End If
ProgressBarControl1.PerformStep()
ProgressBarControl1.Update()
Next
file = nFile
End Sub
Private Sub SimpleButton2_Click(sender As Object, e As EventArgs) Handles SimpleButton2.Click
If OpenFileDialog1.ShowDialog = vbOK Then
Dim x() As Byte = IO.File.ReadAllBytes(OpenFileDialog1.FileName)
ProgressBarControl1.EditValue = 0
ProgressBarControl1.Properties.Step = 1
ProgressBarControl1.Properties.Maximum = x.Length - 1
DeScramble(x)
If SaveFileDialog1.ShowDialog() = vbOK Then
IO.File.WriteAllBytes(SaveFileDialog1.FileName, x)
End If
End If
End Sub
End Class
If you would like to skip this, and would like to just download the source code click Here
Public Class Form1
Private Sub SimpleButton1_Click(sender As Object, e As EventArgs) Handles SimpleButton1.Click
If OpenFileDialog1.ShowDialog = vbOK Then
Dim x() As Byte = IO.File.ReadAllBytes(OpenFileDialog1.FileName)
ProgressBarControl1.EditValue = 0
ProgressBarControl1.Properties.Step = 1
ProgressBarControl1.Properties.Maximum = x.Length - 1
Scramble(x)
If SaveFileDialog1.ShowDialog() = vbOK Then
IO.File.WriteAllBytes(SaveFileDialog1.FileName, x)
End If
End If
End Sub
Public Sub Scramble(ByRef File() As Byte)
' we need to scramble to the amount length
Dim nFile(File.Length - 1) As Byte
Dim x As Long = 0
Dim y As Long = File.Length - 1
For i = 1 To File.Length
If i Mod 2 Then
nFile(i - 1) = File(y)
y -= 1
Else
nFile(i - 1) = File(x)
x += 1
End If
ProgressBarControl1.PerformStep()
ProgressBarControl1.Update()
Next
File = nFile
End Sub
Public Sub DeScramble(ByRef file() As Byte)
' we need to scramble to the amount length
Dim nFile(file.Length - 1) As Byte
Dim x As Long = 0
Dim y As Long = file.Length - 1
For i = 1 To file.Length
If i Mod 2 Then
nFile(y) = file(i - 1)
y -= 1
Else
nFile(x) = file(i - 1)
x += 1
End If
ProgressBarControl1.PerformStep()
ProgressBarControl1.Update()
Next
file = nFile
End Sub
Private Sub SimpleButton2_Click(sender As Object, e As EventArgs) Handles SimpleButton2.Click
If OpenFileDialog1.ShowDialog = vbOK Then
Dim x() As Byte = IO.File.ReadAllBytes(OpenFileDialog1.FileName)
ProgressBarControl1.EditValue = 0
ProgressBarControl1.Properties.Step = 1
ProgressBarControl1.Properties.Maximum = x.Length - 1
DeScramble(x)
If SaveFileDialog1.ShowDialog() = vbOK Then
IO.File.WriteAllBytes(SaveFileDialog1.FileName, x)
End If
End If
End Sub
End Class
No comments:
Post a Comment