Module: GuardCommands::Guard_ClassMethods

Defined in:
lib/Guard.rb

Instance Method Summary collapse

Instance Method Details

#fa(shared_secret, time_difference = 0) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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