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

added Perl 6
m (→‎{{header|zkl}}: diddle code)
(added Perl 6)
Line 306:
fmt.Println(code)
}</lang>
 
=={{header|Perl 6}}==
This is a minimal attempt that covers only the "Time-based" part of the requirement.
<lang perl6>#!/usr/bin/env perl6
 
# Reference:
# https://github.com/retupmoca/P6-Digest-HMAC
 
use v6.d;
use Digest::HMAC;
use Digest::SHA;
 
sub totp (Str \secret, DateTime \counter, Int \T0=0, Int \T1=30 --> Str) {
my \key = ( counter - DateTime.new(T0) ).Int div T1;
return hmac-hex(key.Str, secret, &sha1).substr(0,5) # first 6 chars of sha1
}
 
my $message = "show me the monKey";
 
say "Deterministic output at ", DateTime.new(2177452800), " with fixed checks,";
loop (my $t = 2177452800 ; $t < 2177452900 ; $t+= 17 ) { # Y2038 safe
say totp $message, DateTime.new($t);
}
 
say "Current time output at ", DateTime.new(now), " with random checks,";
loop (my $n = 0 ; $n < 6 ; $n++, sleep (13..23).roll ) {
say totp $message, DateTime.new(now);
}
</lang>
{{out}}
<pre>Deterministic output at 2039-01-01T00:00:00Z with fixed checks,
34ca2
acfa3
950fc
950fc
a2d4e
a2d4e
Current time output at 2019-03-31T13:14:19.635127Z with random checks,
9e6f3
2b5bc
2b5bc
836ce
95955
a79e1</pre>
 
=={{header|PicoLisp}}==
350

edits