Public Class Form1
Dim letters() As String = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "/", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "+", "=", ",", ".", "<", ">", "?", "`", "~", "'", "\", "|"}
Dim key() As Integer = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86}
Private Sub Browse_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
OpenFileDialog1.Filter = "Text files (*.txt)|*.txt"
OpenFileDialog1.Title = "select a file"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.Text = OpenFileDialog1.FileName
End If
End Sub
Private Sub Encrypt_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RandomizeArray(key)
RandomizeArray(key)
RandomizeArray(key)
Dialog1.ShowDialog()
If Dialog1.DialogResult = Windows.Forms.DialogResult.OK Then
encryption(TextBox1.Text, TextBox2.Text)
End If
End Sub
Private Sub RandomizeArray(ByVal items() As Integer)
Dim max_index As Integer = items.Length - 1
Dim rnd As New Random
For i As Integer = 0 To max_index - 1
' Pick an item for position i.
Dim j As Integer = rnd.Next(i, max_index + 1)
' Swap them.
Dim temp As Integer = items(i)
items(i) = items(j)
items(j) = temp
Next i
End Sub
Private Sub encryption(ByVal source As String, ByVal destination As String)
If System.IO.File.Exists(destination) = True Then
System.IO.File.Delete(destination)
End If
If System.IO.File.Exists(source) = True Then
Dim objReader As New System.IO.StreamReader(source)
Dim objwriter As New System.IO.StreamWriter(destination, True)
Dim contents As String
Dim strchar As String = ""
contents = objReader.ReadLine + vbNewLine
While objReader.Peek() <> -1
contents = contents + objReader.ReadLine + vbNewLine
End While
For a = 0 To key.Length - 1
objwriter.Write(key(a))
objwriter.Write(",")
Next
objwriter.WriteLine()
For i = 1 To Len(contents)
strchar = Mid(contents, i, 1)
'Do whatever you want with the character
Dim location As Integer
If strchar.Trim <> "" Then
location = Array.IndexOf(letters, strchar)
location = Array.IndexOf(key, location)
If location = -1 Then
objwriter.Write(strchar)
Else
objwriter.Write(letters(location))
End If
Else
objwriter.Write(strchar)
End If
Next i
objwriter.Close()
MsgBox("file encrypted")
Else
MsgBox("File Does Not Exist")
End If
End Sub
Private Sub get_key(ByVal source As String)
Dim objreader As New System.IO.StreamReader(source)
Dim contents As String
Dim key_2() As String
Dim a As Integer = 0
contents = objreader.ReadLine()
key_2 = Split(contents, ",")
While a < key.Length
key(a) = Convert.ToInt32(key_2(a))
a += 1
End While
End Sub
Private Sub decrypt_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dialog1.ShowDialog()
If DialogResult.OK Then
get_key(TextBox1.Text)
decryption(TextBox1.Text, TextBox2.Text)
End If
End Sub
Private Sub decryption(ByVal source As String, ByVal destination As String)
If System.IO.File.Exists(destination) = True Then
System.IO.File.Delete(destination)
End If
If System.IO.File.Exists(source) = True Then
Dim objReader As New System.IO.StreamReader(source)
Dim objwriter As New System.IO.StreamWriter(destination, True)
Dim contents As String
Dim strchar As String = ""
contents = objReader.ReadLine
contents = ""
While objReader.Peek() <> -1
contents = contents + objReader.ReadLine + vbNewLine
End While
For i = 1 To Len(contents)
strchar = Mid(contents, i, 1)
'Do whatever you want with the character
Dim location As Integer
If strchar.Trim <> "" Then
location = Array.IndexOf(letters, strchar)
location = Array.IndexOf(key, location)
If location = -1 Then
objwriter.Write(strchar)
Else
objwriter.Write(letters(location))
End If
Else
objwriter.Write(strchar)
End If
Next i
objwriter.Close()
MsgBox("File Decrypted")
Else
MsgBox("File Does Not Exist")
End If
End Sub
End Class
if i take test.txt which contains
hi hello what up people message cant read this can you
it comes out in test_file.txt as
85,76,25,66,42,46,55,74,56,69,50,49,8,9,22,23,14,45,83,3,35,39,11,64,34,24,15,40,27,17,65,41,19,78,37,70,52,30,48,62,51,29,33,54,59,84,86,81,43,28,12,31,82,63,58,21,73,47,53,38,2,6,0,72,10,20,32,16,61,7,5,18,68,75,1,71,79,44,67,26,13,4,77,80,57,36,60, &m &?wwq o&/7 #1 1?q1w? O?((/Z? Y/>7 4?/t 7&m( Y/> zq#
after decryting it comes out in decrypt_test.txt as
jO jLoo% qjD$ 5< <L%<oL kL++D^L |D~$ FLD7 $jO+ |D~ c%5
can someone help me fix the decrytion

Add Reply




MultiQuote
| 


