Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.Net Coding Challenge #2
#11
My signature tells you black and yellow. Big Grin Also red, depends on the shades though.

Edit: just noticed how off topic this is going, I shall stop now. Tongue
[Image: burninglove4.png]
Reply
#12
Mines not very good lol... The code is a disgrace but who cares...
Here it is:

Reply
#13
(04-18-2011, 11:11 AM)Fragma Wrote: Mines not very good lol... The code is a disgrace but who cares...
Here it is:


I love that GUI! Did you make it in photoshop?
[Image: t5BWm.png]
Reply
#14
(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.
Reply
#15
(04-18-2011, 11:32 AM)Fragma Wrote: Made the buttons in Photoshop yeh.

Are those pictureboxes or flat buttons?...
[Image: t5BWm.png]
Reply
#16
(04-18-2011, 08:59 AM)Fragma Wrote: This is a lot easier than the last challenge. Tongue

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 Smile

Download:
http://www.mediafire.com/?b0gkaav7jchzaad

Program in Action displaying everything:
[Image: sdfo.png]
Reply
#17
The code:
The download link: http://7019.a.hostable.me/CheckMD5.exe
And an image:
[Image: 1.PNG]
Reply
#18
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? Smile
Reply
#19
(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? Smile
A bit off topic but i had a great idea for the next contest but i forgot it --'
Reply
#20
I have created a new .Net Coding Challenge! Check out #3.
[Image: t5BWm.png]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Code Challenge - Created by Ace AceInfinity 5 1,732 04-24-2012, 10:27 AM
Last Post: AceInfinity
  Help with coding jerrojack 1 897 12-29-2011, 03:27 AM
Last Post: AceInfinity
  Coding-Central.net - Coding, cracking and webmastering. w00pz 5 2,496 09-02-2011, 01:43 PM
Last Post: AceInfinity
  Help Coding A Downloader? Fragma 9 3,540 08-25-2011, 06:10 PM
Last Post: LiveModz
  .Net Coding Challenge #5 iCrack 18 6,054 05-21-2011, 12:49 AM
Last Post: thanasis2028

Forum Jump:


Users browsing this thread: 2 Guest(s)