code: public static int generateTOTP(byte[] key, long time, int digits, String crypto) {
  
          byte[] msg = ByteBuffer.allocate(8).putLong(time).array();
          byte[] hash = hmacSha(crypto, key, msg);
  
          // put selected bytes into result int
          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);
  
          int otp = binary % DIGITS_POWER[digits];
  
          return otp;
      }
docs: This method generates a TOTP value for the given set of parameters.
  
  @param key
  : the shared secret
  @param time
  : a value that reflects a time
  @param digits
  : number of digits to return
  @param crypto
  : the crypto function to use
  
  @return digits