RE: .Net Coding Challenge #2 - Untouch - 04-18-2011
My signature tells you black and yellow. Also red, depends on the shades though.
Edit: just noticed how off topic this is going, I shall stop now.
RE: .Net Coding Challenge #2 - Fragma - 04-18-2011
Mines not very good lol... The code is a disgrace but who cares...
Here it is:
Screenshot:
Download Link:
http://www.mediafire.com/?l7fcwllktky1wmc
Source Code:
Code: Imports System.Security.Cryptography
Imports System.IO
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Gets raw MD5 hash of file
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim lol As FileStream = New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md5.ComputeHash(lol)
lol.Close()
Dim md52 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim lol2 As FileStream = New FileStream(TextBox2.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md52.ComputeHash(lol2)
lol2.Close()
'Appends & formats the hash
Dim hsh As Byte() = md5.Hash
Dim buf As StringBuilder = New StringBuilder
Dim hshByt As Byte
For Each hshByt In hsh
buf.Append(String.Format("{0:X2}", hshByt))
Next
Dim hsh2 As Byte() = md52.Hash
Dim buf2 As StringBuilder = New StringBuilder
Dim hshByt2 As Byte
For Each hshByt2 In hsh2
buf2.Append(String.Format("{0:X2}", hshByt2))
Next
'Displays final MD5 Checksum
TextBox3.Text = buf.ToString()
TextBox4.Text = buf2.ToString()
'Displays comparison status
If TextBox3.Text = TextBox4.Text Then
Label4.ForeColor = Color.Red
Label4.Text = "Files Are Identical"
Else
Label4.ForeColor = Color.Green
Label4.Text = "Files Are Unidentical"
End If
End Sub
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim ofd As OpenFileDialog = New OpenFileDialog()
ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
ofd.RestoreDirectory = True
ofd.InitialDirectory = "C:\"
ofd.FilterIndex = 2
If ofd.ShowDialog = DialogResult.OK Then
TextBox2.Text = ofd.FileName.ToString()
End If
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Try
'Gets raw MD5 hash of file
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim lol As FileStream = New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md5.ComputeHash(lol)
lol.Close()
Dim md52 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim lol2 As FileStream = New FileStream(TextBox2.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md52.ComputeHash(lol2)
lol2.Close()
'Appends & formats the hash
Dim hsh As Byte() = md5.Hash
Dim buf As StringBuilder = New StringBuilder
Dim hshByt As Byte
For Each hshByt In hsh
buf.Append(String.Format("{0:X2}", hshByt))
Next
Dim hsh2 As Byte() = md52.Hash
Dim buf2 As StringBuilder = New StringBuilder
Dim hshByt2 As Byte
For Each hshByt2 In hsh2
buf2.Append(String.Format("{0:X2}", hshByt2))
Next
'Displays final MD5 Checksum
TextBox3.Text = buf.ToString()
TextBox4.Text = buf2.ToString()
'Displays comparison status
If TextBox3.Text = TextBox4.Text Then
Label4.ForeColor = Color.OrangeRed
Label4.Text = "Files Are Identical"
Else
Label4.ForeColor = Color.LightGreen
Label4.Text = "Files Are Unidentical"
End If
Catch Ex As Exception
MessageBox.Show("Please select 2 files to compare")
End Try
End Sub
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
'Allows user to choose file
Dim ofd As OpenFileDialog = New OpenFileDialog()
ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
ofd.RestoreDirectory = True
ofd.InitialDirectory = "C:\"
ofd.FilterIndex = 2
If ofd.ShowDialog = DialogResult.OK Then
TextBox1.Text = ofd.FileName.ToString()
End If
End Sub
Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
Dim ofd As OpenFileDialog = New OpenFileDialog()
ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
ofd.RestoreDirectory = True
ofd.InitialDirectory = "C:\"
ofd.FilterIndex = 2
If ofd.ShowDialog = DialogResult.OK Then
TextBox2.Text = ofd.FileName.ToString()
End If
End Sub
End Class
RE: .Net Coding Challenge #2 - Resistance - 04-18-2011
(04-18-2011, 11:11 AM)Fragma Wrote: Mines not very good lol... The code is a disgrace but who cares...
Here it is:
Screenshot:
Download Link:
http://www.mediafire.com/?l7fcwllktky1wmc
Source Code:
Code: Imports System.Security.Cryptography
Imports System.IO
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Gets raw MD5 hash of file
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim lol As FileStream = New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md5.ComputeHash(lol)
lol.Close()
Dim md52 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim lol2 As FileStream = New FileStream(TextBox2.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md52.ComputeHash(lol2)
lol2.Close()
'Appends & formats the hash
Dim hsh As Byte() = md5.Hash
Dim buf As StringBuilder = New StringBuilder
Dim hshByt As Byte
For Each hshByt In hsh
buf.Append(String.Format("{0:X2}", hshByt))
Next
Dim hsh2 As Byte() = md52.Hash
Dim buf2 As StringBuilder = New StringBuilder
Dim hshByt2 As Byte
For Each hshByt2 In hsh2
buf2.Append(String.Format("{0:X2}", hshByt2))
Next
'Displays final MD5 Checksum
TextBox3.Text = buf.ToString()
TextBox4.Text = buf2.ToString()
'Displays comparison status
If TextBox3.Text = TextBox4.Text Then
Label4.ForeColor = Color.Red
Label4.Text = "Files Are Identical"
Else
Label4.ForeColor = Color.Green
Label4.Text = "Files Are Unidentical"
End If
End Sub
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim ofd As OpenFileDialog = New OpenFileDialog()
ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
ofd.RestoreDirectory = True
ofd.InitialDirectory = "C:\"
ofd.FilterIndex = 2
If ofd.ShowDialog = DialogResult.OK Then
TextBox2.Text = ofd.FileName.ToString()
End If
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Try
'Gets raw MD5 hash of file
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim lol As FileStream = New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md5.ComputeHash(lol)
lol.Close()
Dim md52 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim lol2 As FileStream = New FileStream(TextBox2.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md52.ComputeHash(lol2)
lol2.Close()
'Appends & formats the hash
Dim hsh As Byte() = md5.Hash
Dim buf As StringBuilder = New StringBuilder
Dim hshByt As Byte
For Each hshByt In hsh
buf.Append(String.Format("{0:X2}", hshByt))
Next
Dim hsh2 As Byte() = md52.Hash
Dim buf2 As StringBuilder = New StringBuilder
Dim hshByt2 As Byte
For Each hshByt2 In hsh2
buf2.Append(String.Format("{0:X2}", hshByt2))
Next
'Displays final MD5 Checksum
TextBox3.Text = buf.ToString()
TextBox4.Text = buf2.ToString()
'Displays comparison status
If TextBox3.Text = TextBox4.Text Then
Label4.ForeColor = Color.OrangeRed
Label4.Text = "Files Are Identical"
Else
Label4.ForeColor = Color.LightGreen
Label4.Text = "Files Are Unidentical"
End If
Catch Ex As Exception
MessageBox.Show("Please select 2 files to compare")
End Try
End Sub
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
'Allows user to choose file
Dim ofd As OpenFileDialog = New OpenFileDialog()
ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
ofd.RestoreDirectory = True
ofd.InitialDirectory = "C:\"
ofd.FilterIndex = 2
If ofd.ShowDialog = DialogResult.OK Then
TextBox1.Text = ofd.FileName.ToString()
End If
End Sub
Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
Dim ofd As OpenFileDialog = New OpenFileDialog()
ofd.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
ofd.RestoreDirectory = True
ofd.InitialDirectory = "C:\"
ofd.FilterIndex = 2
If ofd.ShowDialog = DialogResult.OK Then
TextBox2.Text = ofd.FileName.ToString()
End If
End Sub
End Class
I love that GUI! Did you make it in photoshop?
RE: .Net Coding Challenge #2 - Fragma - 04-18-2011
(04-18-2011, 11:24 AM)The High Roller Wrote: I love that GUI! Did you make it in photoshop?
Made the buttons in Photoshop yeh.
RE: .Net Coding Challenge #2 - Resistance - 04-18-2011
(04-18-2011, 11:32 AM)Fragma Wrote: Made the buttons in Photoshop yeh.
Are those pictureboxes or flat buttons?...
RE: .Net Coding Challenge #2 - AceInfinity - 04-18-2011
(04-18-2011, 08:59 AM)Fragma Wrote: This is a lot easier than the last challenge.
I actually think that the PigLatin one was a lot easier, If you know your string arrays and defining functions it wasn't too bad. That way the quickest way of doing it or you could take out the function and do everything yourself. You have to let the code do the work for you.
My Entry
Code: Imports System.IO
Imports System.Security.Cryptography
Imports System.Text
Public Class Form1
'TextBox Drag and drop event
Private Sub TextBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragDrop
'Allow drag and drop for textbox1
Me.AllowDrop = True
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
'Define the output of the drag and drop file directory to MyFiles()
Dim MyFiles() As String
Dim i As Integer
'Drag and drop directory to string as MyFiles
MyFiles = e.Data.GetData(DataFormats.FileDrop)
'Output to Textbox1
TextBox1.Text = MyFiles(i)
'Defining the MD5 Hash
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim f As FileStream = New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
f = New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md5.ComputeHash(f)
Dim ObjFSO As Object = CreateObject("Scripting.FileSystemObject")
Dim objFile = ObjFSO.GetFile(TextBox1.Text)
Dim hash As Byte() = md5.Hash
Dim buff As StringBuilder = New StringBuilder
Dim hashByte As Byte
For Each hashByte In hash
buff.Append(String.Format("{0:X1}", hashByte))
Next
'Resulting MD5 hash as string goes to Label for File1
File1_Label.Text = buff.ToString()
End If
End Sub
Private Sub TextBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox1.DragEnter
'Just the visual effect for dragging and hovering over the textbox area with the copy symbol
e.Effect = DragDropEffects.Copy
End Sub
'TextBox Drag and drop event
Private Sub TextBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop
'Allow drag and drop for textbox1
Me.AllowDrop = True
'File drag and drop data
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
'Define the output of the drag and drop file directory to MyFiles()
Dim MyFiles() As String
Dim i As Integer
'MyFiles as a string equals the value for the drag and drop file data
MyFiles = e.Data.GetData(DataFormats.FileDrop)
'Then put the string value into Textbox2
TextBox2.Text = MyFiles(i)
'Same thing as above
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim f As FileStream = New FileStream(TextBox2.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
f = New FileStream(TextBox2.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md5.ComputeHash(f)
Dim ObjFSO As Object = CreateObject("Scripting.FileSystemObject")
Dim objFile = ObjFSO.GetFile(TextBox2.Text)
Dim hash As Byte() = md5.Hash
Dim buff As StringBuilder = New StringBuilder
Dim hashByte As Byte
For Each hashByte In hash
buff.Append(String.Format("{0:X1}", hashByte))
Next
'Put MD5 hash to the label for File2, I named things differently so the data value of the label is File2_label instead of label#
File2_Label.Text = buff.ToString()
End If
End Sub
Private Sub TextBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter
'Effect for drag and hover over text box, DragEnter, just means entering the drag area while 'holding' onto a file with the mouse
e.Effect = DragDropEffects.Copy
End Sub
'This is the alternative to dragging and dropping a file, opening into an openfile dialog instead. Basically
'the same code, but with the event as a button
'Click instead
Private Sub File_1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles File_1.Click
OpenFileDialog1.Filter = "All Files|*.*|Exe Files|*.exe|Image Files|*.jpg; *.png; *.gif|Audio Files|*.mp3; *.wav|Video Files|*.mp4; *.avi; *.wmv; *.mov"
OpenFileDialog1.ShowDialog()
TextBox1.Text = OpenFileDialog1.FileName
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim f As FileStream = New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
f = New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md5.ComputeHash(f)
Dim ObjFSO As Object = CreateObject("Scripting.FileSystemObject")
Dim objFile = ObjFSO.GetFile(TextBox1.Text)
Dim hash As Byte() = md5.Hash
Dim buff As StringBuilder = New StringBuilder
Dim hashByte As Byte
For Each hashByte In hash
buff.Append(String.Format("{0:X1}", hashByte))
Next
File1_Label.Text = buff.ToString()
End Sub
Private Sub File_2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles File_2.Click
OpenFileDialog2.Filter = "All Files|*.*|Exe Files|*.exe|Image Files|*.jpg; *.png; *.gif|Audio Files|*.mp3; *.wav|Video Files|*.mp4; *.avi; *.wmv; *.mov"
OpenFileDialog2.ShowDialog()
TextBox2.Text = OpenFileDialog2.FileName
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim f As FileStream = New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
f = New FileStream(TextBox2.Text, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md5.ComputeHash(f)
Dim ObjFSO As Object = CreateObject("Scripting.FileSystemObject")
Dim objFile = ObjFSO.GetFile(TextBox1.Text)
Dim hash As Byte() = md5.Hash
Dim buff As StringBuilder = New StringBuilder
Dim hashByte As Byte
For Each hashByte In hash
buff.Append(String.Format("{0:X1}", hashByte))
Next
File2_Label.Text = buff.ToString()
End Sub
'Comparing the MD5 for the file data of both file1 and file2
Private Sub Compare_Button_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Compare_Button.Click
'This makes sure that you have an input directory for File1 otherwise it will not execute the rest of the code and will show
'a message instead
If TextBox1.Text = "" Then
MsgBox("The file comparison could not be returned because you haven't specified any files yet.", MsgBoxStyle.Critical, "Error")
Exit Sub
End If
'Same thing goes for Textbox2 if you want to compare two files
If TextBox2.Text = "" Then
MsgBox("The file comparison could not be returned because you haven't specified a second file yet.", MsgBoxStyle.Critical, "Error")
Exit Sub
End If
'Here is where i've added the option to tell the convert button that you are comparing the data from the first and second textboxes
'As MD5 Values
If RadioButton1.Checked = True Then
Dim File1 As String
File1 = File1_Label.Text
Dim File2 As String
File2 = File2_Label.Text
'If label1 = label2 then the MD5 Hashes match, the labels should already have the values of the MD5 in them, so all I needed to do was to compare the string values of each
If File1 = File2 Then
'It's a match
MsgBox("The file comparison confirmed that the MD5 Hashes match.", MsgBoxStyle.Information, "Information")
Else
'Hashes do not match
MsgBox("The file comparison confirmed that the MD5 Hashes do not match.", MsgBoxStyle.Critical, "Error")
End If
'This is where I will compare the data for the MD5 of File 1, and compare it to the string value for the MD5 hash entered in
'the manual MD5 comparision textbox
ElseIf RadioButton2.Checked = True Then
'If nothing is entered, show an error message and don't execute any of the rest of the code
If Manual_Input.TextLength = 0 Then
MsgBox("Please enter in a MD5 hash to compare.", MsgBoxStyle.Critical, "Error")
Exit Sub
End If
'If string value entered in MD5 textbox matches MD5 for the value of File1 MD5, which should be entered into the label, then show message
'that defines them as a match or not
If Manual_Input.Text = File1_Label.Text Then
'If text string = label text string then they are a match
MsgBox("File 1 MD5 hash string value matches the MD5 you specified.", MsgBoxStyle.Information, "Information")
'If not, they aren't matching MD5 hashes
ElseIf Not Manual_Input.Text = File1_Label.Text Then
MsgBox("File 1 MD5 hash string value does not match the MD5 you specified.", MsgBoxStyle.Critical, "Error")
End If
End If
End Sub
'The simple exit application code for the "X" button in the top right
Private Sub CloseApp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseApp.Click
End
End Sub
'Clears all of the input values for the text strings and MD5 string values in the labels
Private Sub Clear_All_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear_All.Click
'If Radiobutton1 is ticked, then I made it so that it doesn't clear that little message from the MD5 hash textbox while it's enabled = false
If RadioButton1.Checked Then
If TextBox2.Enabled = False Then
TextBox1.Text = ""
File1_Label.Text = ""
File2_Label.Text = ""
Exit Sub
End If
'Clear rest of the data and replace with nothing
TextBox1.Text = ""
TextBox2.Text = ""
File1_Label.Text = ""
File2_Label.Text = ""
'Here I just did the opposite, cleared the MD5 textbox value, and kept the Textbox2 string value while it's enabled = false
ElseIf RadioButton2.Checked Then
TextBox1.Text = ""
File1_Label.Text = ""
File2_Label.Text = ""
Manual_Input.Text = ""
End If
End Sub
'My little help code that displays the help message box
Private Sub Help_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Help.Click
MsgBox("This program will compare two different files to determine whether the MD5 Hashe string value of each are the same. To begin, you must use the buttons beside each textbox to select two files to compare or drag the files into the textboxes manually. The Hashes will be displayed below each textbox for the corresponding file. You may also enter in an MD5 Hash manually if you want to compare a file to a specific MD5 Hash string.", MsgBoxStyle.Information, "MD5 Hash Check v2.0 - Help")
End Sub
'The great supportforums link at the bottom, click event takes you to the forum from your default browser
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
System.Diagnostics.Process.Start("http://www.supportforums.net")
End Sub
'Topmost command if you want to see the form at all times while your working and comparing MD5 Hashes and files
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
'if it's ticked, then keep above all other windows
If CheckBox1.Checked Then
Me.TopMost = True
'If it's not ticked then don't keep it above all other windows
ElseIf CheckBox1.Checked = False Then
Me.TopMost = False
End If
End Sub
'If radiobutton is checked change all the settings for the option in order to keep only the first and second textboxes available along with the convert button
Private Sub RadioButton1_Checked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked Then
If TextBox1.Text = "" Then
TextBox2.Text = " Please select a file for File 1 first"
Manual_Input.Text = "Enter your MD5 Hash here"
Manual_Input.Enabled = False
File_2.Enabled = False
TextBox2.Enabled = False
ElseIf Not TextBox1.Text = "" Then
TextBox2.Text = ""
Manual_Input.Text = "Enter your MD5 Hash here"
Manual_Input.Enabled = False
File_2.Enabled = True
TextBox2.Enabled = True
End If
End If
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked Then
If TextBox1.Text = "" Then
TextBox2.Text = " Please select a file for File 1 first"
File_2.Enabled = False
TextBox2.Enabled = False
End If
End If
End Sub
'For this, disable textbox2 and file2 button, and keep everything else active... Textbox1 area, and the MD5 hash textbox at the bottom
Private Sub RadioButton2_Checked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked Then
Manual_Input.Text = ""
Manual_Input.Enabled = True
TextBox2.Text = " Please use File 1 Button to compare Instead"
TextBox2.Enabled = False
File_2.Enabled = False
End If
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked Then
Manual_Input.Text = ""
Manual_Input.Enabled = True
TextBox2.Text = " Please use File 1 Button to compare Instead"
TextBox2.Enabled = False
File_2.Enabled = False
End If
End Sub
'Copy MD5 hash string value from File 1 label to clipboard and display successful message
Private Sub Copy1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Copy1.Click
MsgBox("File 1 MD5 hash string has been copied to the clipboard successfully!", MsgBoxStyle.Information, "Information")
Clipboard.SetText(File1_Label.Text)
Dim CopyText As String = Clipboard.GetText
End Sub
'Copy MD5 hash string value from File 2 label to clipboard and display successful message
Private Sub Copy2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Copy2.Click
MsgBox("File 2 MD5 hash string has been copied to the clipboard successfully!", MsgBoxStyle.Information, "Information")
Clipboard.SetText(File2_Label.Text)
Dim CopyText As String = Clipboard.GetText
End Sub
'If value is entered into the first textbox (a directory to a file) then activate textbox2 to enter a directory for that file
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If Not TextBox1.Text = "" Then
TextBox2.Enabled = True
TextBox2.Text = ""
File_2.Enabled = True
End If
End Sub
'The rest of the code just determines whether or not it's worth showing the copy button whenever there is a value to copy for the MD5 hash as a string
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
If TextBox2.Text = "" Then
Copy2.Visible = False
ElseIf Not TextBox1.Text = "" Then
Copy2.Visible = True
End If
End Sub
Private Sub File1_Label_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles File1_Label.TextChanged
If File1_Label.Text = "" Then
Copy1.Visible = False
ElseIf Not File1_Label.Text = "" Then
Copy1.Visible = True
End If
End Sub
Private Sub File2_Label_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles File2_Label.TextChanged
If File2_Label.Text = "" Then
Copy2.Visible = False
ElseIf Not File2_Label.Text = "" Then
Copy2.Visible = True
End If
End Sub
'Clears just the text area for the MD5 hash textbox, (faster then highlighting with mouse, and entering a different MD5 hash)
Private Sub Clear_Manual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear_Manual.Click
If Manual_Input.Enabled = True Then
Manual_Input.Text = ""
End If
End Sub
End Class
Messy code, i'll admit, but I did lots of editing to this, I'll go back and tidy things up a bit more by combining a few things. I have a couple repeats that could be shortened with less code, but it's working, so now it's just the steps to tidy things up
Download:
http://www.mediafire.com/?b0gkaav7jchzaad
Program in Action displaying everything:
RE: .Net Coding Challenge #2 - Modestep - 04-18-2011
The code:
Code: Imports System.IO
Imports System.Security.Cryptography
Imports System.Text
Public Class Form1
Private Sub FButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton1.Click
If OpenFileDialog1.ShowDialog(Me) = 1 Then
txtFile1.Text = OpenFileDialog1.FileName
Label3.Text = GetFileSize(txtFile1.Text).ToString & "kb"
End If
End Sub
Private Function GetFileSize(ByVal MyFilePath As String) As Long
Dim MyFile As New FileInfo(MyFilePath)
Dim FileSize As Long = MyFile.Length
Return FileSize
End Function
Private Sub FButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton2.Click
If OpenFileDialog2.ShowDialog(Me) = 1 Then
txtFile2.Text = OpenFileDialog2.FileName
Label4.Text = GetFileSize(txtFile2.Text).ToString & "kb"
End If
End Sub
Private Sub FButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton3.Click
Me.Close()
End Sub
Private Sub FButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FButton4.Click
Dim pipi As String = CalculateMD5(txtFile1.Text)
Dim kaka As String = CalculateMD5(txtFile2.Text)
If pipi = kaka Then
MessageBox.Show("The 2 files are the same", "Yes!!")
Else
MessageBox.Show("Those are 2 different files", "Oh noes :(")
End If
End Sub
Private Function CalculateMD5(ByVal strFilepath As String) As String
Dim File() As Byte = System.IO.File.ReadAllBytes(strFilepath)
Dim Md5 As New MD5CryptoServiceProvider()
Dim byteHash() As Byte = Md5.ComputeHash(File)
Return ByteArrayToString(byteHash)
End Function
Private Function ByteArrayToString(ByVal arrInput() As Byte) As String
Dim sb As New System.Text.StringBuilder(arrInput.Length * 2)
For i As Integer = 0 To arrInput.Length - 1
sb.Append(arrInput(i).ToString("X2"))
Next
Return sb.ToString().ToLower
End Function
End Class
The download link: http://7019.a.hostable.me/CheckMD5.exe
And an image:
RE: .Net Coding Challenge #2 - Fragma - 04-18-2011
Yours is similar to mine Infinity. Although where you have "{0:X1}", you should change it to "{0:X2}".
This will mean that bytes with a value of 0 to F won't be missing their leading zero.
An example...
Here I have used my program, and your program, to find the MD5 hash of an image file.
Your program gave: 8AE1AB2A5D297E76458417FA1DD0
Whereas mine (using "{0:X2}") gave: 08AE1AB2A5D2097E0764058417FA1DD0
By the way guys.. Can I host the next challenge?
RE: .Net Coding Challenge #2 - Modestep - 04-18-2011
(04-18-2011, 12:54 PM)Fragma Wrote: Yours is similar to mine Infinity. Although where you have "{0:X1}", you should change it to "{0:X2}".
This will mean that bytes with a value of 0 to F won't be missing their leading zero.
An example...
Here I have used my program, and your program, to find the MD5 hash of an image file.
Your program gave: 8AE1AB2A5D297E76458417FA1DD0
Whereas mine (using "{0:X2}") gave: 08AE1AB2A5D2097E0764058417FA1DD0
By the way guys.. Can I host the next challenge? A bit off topic but i had a great idea for the next contest but i forgot it --'
RE: .Net Coding Challenge #2 - Resistance - 04-18-2011
I have created a new .Net Coding Challenge! Check out #3.
|