grondinm and many others are using Hackety Hack to learn how to code.

Hackety Hack is a free program for Windows, Mac OS X and Linux that can teach you how to make games, applications and more and share those programs with your friends. You can ask other budding programmers questions and follow them to see what code they're working on through the Hackety Hack website.

Sign up Learn More

shoesmd5digest by grondinm

require 'digest/md5'
require 'digest/sha1'

Shoes.app :width => 500, :height => 325, :resizable => false, :title => "Checksum generator & Checker" do
	def create_md5_digest
		puts "Creating the MD5 hash"
	end
	
	background ivory

	stack :margin => 10 do
		flow do
		  inscription "File:"
		  @origen=edit_line :width=>300, :text=>'D:/files'
		  button "Select" do
			@origen.text=ask_open_file()
			@result.text = ""
		  end
		end
		flow do
		inscription "Original checksum:" 
		@origfile=edit_line :width =>320, :text =>'Enter File Checksum to Compare'
		end
		stack do
			flow do
				@md5 = radio :algorithm; para "MD5";
				@md5.style(:background => hotpink)
			end
			flow do
				@sha1 = radio :algorithm; para "SHA1";
			end
		end
		
		button "Generate and Verify checksum" do
			if File.exists?(@origen.text)
				if @sha1.checked?
					@result.text = Digest::SHA1.hexdigest(File.open(@origen.text, "rb") { |f| f.read })
					@result.style(:stroke => green)
                                        @match.text=""
				elsif @md5.checked?
					@result.text = Digest::MD5.hexdigest(File.open(@origen.text, "rb") { |f| f.read })
					@result.style(:stroke => green)
                                        @match.text=""
				else
					@result.text = "Please select a checksum algorithm."
					@result.style(:stroke => red)
				end
			else
				@result.text = "File does not exist."
				@result.style(:stroke => red)
			end
		if @origfile.text == @result.text
		  @match.text="File Matches"
                elsif @origfile.text == "Enter File Checksum to Compare" or @origfile.text == ""
                  @match.text = ""
		else
		  @match.text="File Does not match"
	        end    
		end
		#@result = para "", :margin => [0,20,0,0], :size => 16, :stroke => green, :align => 'center'
                @result = edit_line :margin => [0,20,0,0], :width => 320
         	@match = para ""
	    button "Exit" do
              close()
              end
        end
end