Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require_relative 'hash_computer'
- @hasz_computer = HashComputer.new
- def floyd(prefix, initial)
- puts "starting floyd with prefix: #{prefix} and initial #{initial}"
- x0 = initial
- m0 = nil
- m1 = nil
- turtle = @hasz_computer.computeHash(x0, prefix)
- hare = @hasz_computer.computeHash(turtle, prefix)
- while turtle != hare
- turtle = @hasz_computer.computeHash(turtle, prefix)
- hare = @hasz_computer.computeHash(@hasz_computer.computeHash(hare, prefix), prefix)
- end
- pre_period_length = 0
- turtle = x0
- while turtle != hare
- m0 = turtle
- turtle = @hasz_computer.computeHash(turtle, prefix)
- hare = @hasz_computer.computeHash(hare, prefix)
- pre_period_length += 1
- end
- if pre_period_length == 0
- puts "Failed to find a collision: x0 was in a cycle!"
- return
- end
- period_length = 1
- hare = @hasz_computer.computeHash(turtle, prefix)
- while turtle != hare
- m1 = hare
- hare = @hasz_computer.computeHash(hare, prefix)
- period_length += 1
- end
- puts "#{m0} ; #{m1} = #{@hasz_computer.computeHash(m0, prefix)}"
- end
- ["1", "2", "3", "4", "5", "6", "7", "8"].each do |x|
- Thread.new {
- floyd("pydyra", x)
- }
- end
- while true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement