Last active
August 29, 2015 14:02
-
-
Save BillyParadise/291448b7ade1e664c85d to your computer and use it in GitHub Desktop.
hash comparing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest' | |
rolls = rand(1..1) #small for testing! | |
raw = "" | |
rolls.times do | |
raw = raw + "A,B,C," | |
end | |
raw = raw[0...-1] | |
eggs = raw.split(",").shuffle!.shuffle!.shuffle! | |
omlette = eggs.join | |
hashbrown = Digest::SHA256.hexdigest(omlette) | |
tomorrow = Time.now.strftime("%d/%m/%Y") | |
rolls = rolls *3 | |
spew = File.open("sample.txt", "w") | |
spew.print "Preroll for " + tomorrow + "\n" | |
spew.print "Today's Rolls: " + rolls.to_s + "\n" | |
spew.puts omlette | |
spew.puts hashbrown | |
spew.close |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest' | |
puts "Testing the file: sample.txt" | |
file = File.open("sample.txt", "r") | |
fileday = file.readline | |
filerolls= file.readline | |
omlette = file.readline | |
puts "Supplied Rolls:" | |
puts omlette | |
hashbrown = file.readline | |
puts "Supplied Hash:" | |
puts hashbrown | |
puts "Calculated Hash:" | |
wtf = Digest::SHA256.hexdigest(omlette).chomp | |
puts wtf | |
if wtf.equal? hashbrown | |
puts "MATCH" | |
else | |
puts "NO MATCH" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment