Rfc4226 hotp Java implementation

I tried to copy hotalgorithm Java code (hotalgorithm. Java) and compare it with the official hotp RFC 4226 example implementation (rfc4226 page 27) on page 27 of the official rfc4226 document HOTPAlgorithm. The implementations in Java and RFC 4226 were written by the same author Loren Hart and set to version 1.0 The two codes are the same in my comparison

I tried to run the test vector of the 6-bit hotp code (without modifying the hotalgorithm. Java script) and noticed rfc4226 and hotalgorithm The source code given in Java generates different test vector results for the published rfc4226 results, with exactly the same settings

When compared with rfc4226 test vector, rfc4226 sample java code and hotalgorithm Are there any differences in Java code released by Java?

From hotalgorithm Test results of Java and rfc4226 java code (both produce the same results):

755224
030356
132975
957805
463120
994243
844697
570244
487336
025740

Test vector from rfc4226 publication (rfc4226 page 32)

755224
287082
359152
969429
338314
254676
287922
162583
399871
520489

Do I lack the difference between the officially released sample code and the officially released results?

Solution

change

int otp = binary % DIGITS_POWER[codeDigits];

to

int otp = (int) (binary % Math.pow(10,codeDigits));

or

int otp = binary % 1000000;
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>