public static OTP generateOTP(byte[] secret, String algo, int digits, long counter)
            throws NoSuchAlgorithmException, InvalidKeyException {
        byte[] hash = getHash(secret, algo, counter);

        // truncate hash to get the HTOP value
        // http://tools.ietf.org/html/rfc4226#section-5.4
        int offset = hash[hash.length - 1] & 0xf;
        int otp = ((hash[offset] & 0x7f) << 24)
                | ((hash[offset + 1] & 0xff) << 16)
                | ((hash[offset + 2] & 0xff) << 8)
                | (hash[offset + 3] & 0xff);

        return new OTP(otp, digits);
    }
@Test
    public void vectorsMatch() throws InvalidKeyException, NoSuchAlgorithmException {
        for (int i = 0; i < VECTORS.length; i++) {
            OTP otp = HOTP.generateOTP(SECRET, "HmacSHA1", 6, i);
            assertEquals(VECTORS[i], otp.toString());
        }
    }