public String generate(long time) {

        // Calculate HOTP counter value based on provided time
        long counter = (time - startTime) / timeStep;
        byte[] hash = getHMAC(Longs.toByteArray(counter));

        // Calculate HOTP value as defined by section 5.2 of RFC 4226:
        // https://tools.ietf.org/html/rfc4226#section-5.2
        int offset = hash[hash.length - 1] & 0xF;
        int binary
                = ((hash[offset]     & 0x7F) << 24)
                | ((hash[offset + 1] & 0xFF) << 16)
                | ((hash[offset + 2] & 0xFF) << 8)
                |  (hash[offset + 3] & 0xFF);

        // Truncate or pad the value accordingly
        return toCode(binary, length);

    }
Generates a TOTP code of the given length using the given absolute
timestamp rather than the current system time.

@param time
    The absolute timestamp to use to generate the TOTP code, in seconds
    since midnight, 1970-01-01, UTC (UNIX epoch).

@return
    The TOTP code which corresponds to the given timestamp, having
    exactly the given length.

@throws IllegalArgumentException
    If the given length is invalid as defined by the TOTP specification.
extensions/guacamole-auth-totp/src/main/java/org/apache/guacamole/totp/TOTPGenerator.java