Advertisement
frostblooded

Key exchange attack

Dec 5th, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.52 KB | None | 0 0
  1. p = 23
  2. g = 5
  3. A = 4
  4. B = 10
  5.  
  6. # initialize empty array
  7. a_arr = []
  8.  
  9. for a in 1..p
  10.     # g^a mod p = A
  11.     if g ** a % p == A
  12.         # add a to array (save it as a possible a)
  13.         a_arr << a
  14.     end
  15. end
  16.  
  17. # if there is only one possible a
  18. if a_arr.size == 1
  19.     puts "Only one possible value for the secret: #{B ** a_arr[0] % p}"
  20. else
  21.     puts "Multiple possible values for the secret."
  22.     puts "The possible 'a' values are:"
  23.  
  24.     # print each possible a
  25.     a_arr.each do |a|
  26.         puts a
  27.     end
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement