Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.22 KB | None | 0 0
  1. require_relative 'hash_computer'
  2.  
  3.  
  4. @hasz_computer = HashComputer.new
  5.  
  6. def floyd(prefix, initial)
  7.   puts "starting floyd with prefix: #{prefix} and initial #{initial}"
  8.   x0 = initial
  9.   m0 = nil
  10.   m1 = nil
  11.   turtle = @hasz_computer.computeHash(x0, prefix)
  12.   hare = @hasz_computer.computeHash(turtle, prefix)
  13.  
  14.   while turtle != hare
  15.     turtle = @hasz_computer.computeHash(turtle, prefix)
  16.     hare = @hasz_computer.computeHash(@hasz_computer.computeHash(hare, prefix), prefix)
  17.   end
  18.  
  19.   pre_period_length = 0
  20.   turtle = x0
  21.   while turtle != hare
  22.     m0     = turtle
  23.     turtle = @hasz_computer.computeHash(turtle, prefix)
  24.     hare   = @hasz_computer.computeHash(hare, prefix)
  25.     pre_period_length += 1
  26.   end
  27.  
  28.   if pre_period_length == 0
  29.       puts "Failed to find a collision: x0 was in a cycle!"
  30.       return
  31.   end
  32.  
  33.   period_length = 1
  34.   hare = @hasz_computer.computeHash(turtle, prefix)
  35.   while turtle != hare
  36.     m1   = hare
  37.     hare = @hasz_computer.computeHash(hare, prefix)
  38.     period_length += 1
  39.   end
  40.  
  41.   puts "#{m0} ; #{m1} = #{@hasz_computer.computeHash(m0, prefix)}"
  42. end
  43.  
  44. ["1", "2", "3", "4", "5", "6", "7", "8"].each do |x|
  45.   Thread.new {
  46.     floyd("pydyra", x)
  47.   }
  48. end
  49.  
  50. while true
  51.  
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement