Skip to content
Snippets Groups Projects
Commit 91942358 authored by François Sarradin's avatar François Sarradin
Browse files

add SHA-1 question

parent 7aa7d1dd
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
require 'set'
require 'prime'
require 'digest/sha1'
module ExtremeStartup
class Question
......@@ -627,6 +628,43 @@ module ExtremeStartup
end
end
class Sha1Question < GetQuestion
def initialize(player, word=nil)
if word
@word = word
else
size = rand(5) + 5
@word = generate_string(size)
end
end
def as_text
"what is the SHA-1 hash of #{@word}"
end
private
def correct_answer
Digest::SHA1.hexdigest @word
end
def generate_string(size)
random_chars[0..size].reduce(:+)
end
def random_chars
randoms = Set.new
loop do
is_upper = rand(2)
if is_upper == 1
c = 'A'.ord
else
c = 'a'.ord
end
randoms << (c + rand(26)).chr
return randoms.to_a if randoms.size >= 10
end
end
end
class QuestionFactory
attr_reader :round
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment