Time-based one-time password algorithm: Difference between revisions

→‎{{header|Tcl}}: -- Fix code so that padding of leading and ending zeros is correct
m (Thundergnat moved page Time-based One-time Password Algorithm to Time-based one-time password algorithm: Follow normal task title capitalization policy)
(→‎{{header|Tcl}}: -- Fix code so that padding of leading and ending zeros is correct)
Line 669:
namespace eval ::totp {
package require sha1
 
oo::class create totp {
variable Secret
Line 698:
hotp $Secret $bytes
}
 
}
 
proc hotp {secret bytes {length 6}} {
set hmac [sha1::hmac -bin $secret $bytes]
set ofs [string index $hmac end]
Line 708:
set chunk [string range $hmac $ofs $ofs+4]
binary scan $chunk I code
return [format %0${length}.${length}d [expr {($code & 0x7fffffff) % 100000010 ** $length}]]
}
 
}
namespace export *
}