Sha256: 999ca98ec6c448e1da8c81447f4a6fe2451985c3027d102ad061d01f836be0d3
Contents?: true
Size: 745 Bytes
Versions: 1
Compression:
Stored size: 745 Bytes
Contents
require 'sperm/groups/intmod' module Sperm::Groups # Represents (Z/pZ \ {0}, *) - a multiplicative cyclic group of integers # modulo p. # class ZpMul include Zn attr_reader :prime, :generator alias_method :modulo, :prime def initialize(prime, generator) @prime = prime @generator = generator end def order modulo - 1 end def produce_cycle(first, multiplier) fail ArgumentError, 'not an element' unless include?(first) && include?(multiplier) Enumerator.new do |yielder| current = first loop do yielder.yield current current = (current * multiplier) % modulo break if current == first end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sperm-0.1.1 | lib/sperm/groups/multiplicative.rb |