class ROTP::OTP
def generate_otp(input, padded=true)
(**padded)
-
(false)
(Boolean
) -- Output the otp as a 0 padded string
Parameters:
-
input
(Integer
) -- the number used seed the HMAC
def generate_otp(input, padded=true) hmac = OpenSSL::HMAC.digest( OpenSSL::Digest.new(digest), byte_secret, int_to_bytestring(input) ) offset = hmac[-1].ord & 0xf code = (hmac[offset].ord & 0x7f) << 24 | (hmac[offset + 1].ord & 0xff) << 16 | (hmac[offset + 2].ord & 0xff) << 8 | (hmac[offset + 3].ord & 0xff) if padded (code % 10 ** digits).to_s.rjust(digits, '0') else code % 10 ** digits end end