# ABL Time-based one-time password (TOTP)

#### Cecil

##### 19+ years progress programming and still learning.
Min Requirements Openedge 11.7.4

As a pet project, I wanted to create a Time-based one-time password (TOTP) generator. In the near future, I can see that I'm going to need one because some websites use Multi-Factor Authentication. The end user does not want to use a mobile app (i.e. Microsoft Authenticator) to obtain a 6-digit code for two-step verification.

I know I could have used a .NET TOTP assembly class, but I wanted to write my own version in pure ABL. You can cross-validate code is working correctly using Online one-time password generator / TOTP (Google Authenticator) Online

Demo:

Source Code:

• LarryD and Stefan

#### Stefan

##### Well-Known Member
Nice, you can win some performance (about 15%) by allowing your bitwise OR and AND functions to short-circuit.

#### Cecil

##### 19+ years progress programming and still learning.
Nice, you can win some performance (about 15%) by allowing your bitwise OR and AND functions to short-circuit.

As you know bitwise operations in the ABL are my nemesis.
I think I have your variant somewhere.

• Stefan

#### Stefan

##### Well-Known Member
You just need to get rid of the intermediate variables b1 and b2 since b2 is always evaluated even when it's value is irrelevant based on b1.

Code:
``````function bitOR returns integer (input X as integer, input Y as integer):

define variable n  as integer no-undo.
define variable Z  as integer no-undo.

do n = 1 to 32:

if get-bits(X, n, 1) = 1 or get-bits(Y, n, 1) = 1 then
PUT-BITS(Z, n, 1) = 1.

end.

return Z.

end function.``````

Code:
``````function bitAnd returns integer (input X as integer, input Y as integer):

define variable b as integer no-undo.
define variable n  as integer no-undo.
define variable Z  as integer no-undo.

do n = 1 to 32:

if get-bits(X, n, 1) = 1 and get-bits(Y, n, 1) = 1 then
b = 1.

PUT-BITS(Z, n, 1) = b.
b = 0.

end.

return Z.

end function.``````

V
Replies
0
Views
103
Vyom Srivastava
V
J
Replies
0
Views
512
John Iwuozor
J
J
Replies
0
Views
185
Jessica Malakian
J
J
Replies
0
Views
342
John Iwuozor
J
E
Replies
0
Views
173
Edsel Garcia
E