// calculate current interval number
long intervalNumber = (CLIENT_TIME_IN_MILLISECONDS + TIME_DIFFERENCE_TO_SERVER) / 30000
// calculate HMAC-SHA1 from secret key and interval number
byte[20] mac = HMAC-SHA1(SECRET_KEY, intervalNumber)
// determine which 4 bytes of the MAC are taken as the current code
// last 4 bit of the MAC points to the starting byte
int startPos = mac[19] & 0x0F
// select the byte at starting position and the following 3 bytes
int selectedInt = mac[startPos .. startPos + 3]
// use the lowest 8 decimal digits from the selected integer as the
// current authenticator code
return selectedInt % 100000000