Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p = 23
- g = 5
- A = 4
- B = 10
- # initialize empty array
- a_arr = []
- for a in 1..p
- # g^a mod p = A
- if g ** a % p == A
- # add a to array (save it as a possible a)
- a_arr << a
- end
- end
- # if there is only one possible a
- if a_arr.size == 1
- puts "Only one possible value for the secret: #{B ** a_arr[0] % p}"
- else
- puts "Multiple possible values for the secret."
- puts "The possible 'a' values are:"
- # print each possible a
- a_arr.each do |a|
- puts a
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement