module GuardCommands::Guard_ClassMethods

Public Instance Methods

fa(shared_secret,time_difference = 0) click to toggle source
# File lib/Guard.rb, line 38
def fa(shared_secret,time_difference = 0)
      raise "No shared_secret given" if shared_secret == nil # cause upon initialization @secret = nil
      timestamp = Time.new.to_i + time_difference
      math = timestamp.to_i / 30
      math = math.to_i
      time_buffer =[math].pack('Q>')

      hmac = OpenSSL::HMAC.digest('sha1', Base64.decode64(shared_secret), time_buffer)

      start = hmac[19].ord & 0xf
      last = start + 4
      pre = hmac[start..last]
      fullcode = pre.unpack('I>')[0] & 0x7fffffff

      chars = '23456789BCDFGHJKMNPQRTVWXY'
      code= ''
      for looper in 0..4 do
            copy = fullcode #divmod
            i = copy % chars.length #divmod
            fullcode = copy / chars.length #divmod
            code = code + chars[i]
      end
      return code

end