Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TOTP 100% qb64 Yup - sorta LOL
#2
This is actually one of the best thing out there to be a project.
I have worked on the SHA256 algorithm yesterday: Github: SHA2
and I made some functions for managing rightRotate, LongToHex, BytesToLong, LongToBits, and a couple more.
Here they are:

__ to bits:
Code: (Select All)
Function ByteToBits$ (__BYTE As _Unsigned _Byte)
    Dim __I As _Unsigned _Byte
    Dim __O$8
    For __I = 0 To 7
        If _ReadBit(__BYTE, __I) Then Asc(__O$8, 1 + __I) = 49 Else Asc(__O$8, 1 + __I) = 48
    Next __I
    ByteToBits$ = __O$8
End Function
Function IntegerToBits$ (__A As _Unsigned Integer)
    Dim __I As _Unsigned _Byte
    Dim __O$16
    For __I = 0 To 15
        If _ReadBit(__A, 15 - __I) Then Asc(__O$16, 1 + __I) = 49 Else Asc(__O$16, 1 + __I) = 48
    Next __I
    IntegerToBits$ = __O$16
End Function
Function LongToBits$ (__A As _Unsigned Long)
    Dim __I As _Unsigned _Byte
    Dim __O$32
    For __I = 0 To 31
        If _ReadBit(__A, 31 - __I) Then Asc(__O$32, 1 + __I) = 49 Else Asc(__O$32, 1 + __I) = 48
    Next __I
    LongToBits$ = __O$32
End Function
Function Integer64ToBits$ (__A As _Unsigned _Integer64)
    Dim __I As _Unsigned _Byte
    Dim __O$64
    For __I = 0 To 63
        If _ReadBit(__A, 63 - __I) Then Asc(__O$64, 1 + __I) = 49 Else Asc(__O$64, 1 + __I) = 48
    Next __I
    Integer64ToBits$ = __O$64
End Function

__ to hex:
Code: (Select All)
Function ByteToHex$ (__A~%%)
    __H$ = Hex$(__A~%%)
    ByteToHex$ = String$(2 - Len(__H$), 48) + __H$
End Function
Function IntegerToHex$ (__A~%)
    __H$ = Hex$(__A~%)
    IntegerToHex$ = String$(4 - Len(__H$), 48) + __H$
End Function
Function LongToHex$ (__A~&)
    __H$ = Hex$(__A~&)
    LongToHex$ = String$(8 - Len(__H$), 48) + __H$
End Function
Function Integer64ToHex$ (__A~&&)
    __H$ = Hex$(__A~&&)
    Integer64ToHex$ = String$(16 - Len(__H$), 48) + __H$
End Function

rightRotate:
Code: (Select All)
Function rightRotateLong~& (A~&, B~%%)
    rightRotateLong~& = _SHR(A~&, B~%%) Or _SHL(A~&, 32 - B~%%)
End Function
Function rightRotateInteger64~& (A~&&, B~%%)
    rightRotateInteger64~& = _SHR(A~&&, B~%%) Or _SHL(A~&&, 32 - B~%%)
End Function

reverseCVL: (an alternative to your BytesToLong~&)
Code: (Select All)
Function ReverseCVL~& (__A$4)
    ReverseCVL~& = Asc(__A$4, 4) Or _SHL(Asc(__A$4, 3), 8) Or _SHL(Asc(__A$4, 2), 16) Or _SHL(Asc(__A$4, 1), 24)
End Function
The problem with using Bits is the Big-Endian and Little-Endian, I've had to debug them myself for minutes...

reverseCVI64: (for _integer64)
Code: (Select All)
Function ReverseCVI64~&& (__A$8)
    ReverseCVI64~&& = Asc(__A$8, 8) Or _SHL(Asc(__A$8, 7), 8) Or _SHL(Asc(__A$8, 6), 16) Or _SHL(Asc(__A$8, 5), 24) Or _SHL(Asc(__A$8, 4), 32) Or _SHL(Asc(__A$8, 3), 40) Or _SHL(Asc(__A$8, 2), 48) Or _SHL(Asc(__A$8, 1), 56)
End Function

I might also suggest you a couple of things, to optimize your algorithms:
1. Use ASC(S$, I) instead of ASC(MID$(I$, I, 1)), it is faster
2. Declare variables static, which you think will not affect the output of your algorithm... if not assigned to zero.
3. While calculating SHA1$, you can do this to make it fast: (provided you are using H(0 to 4) instead of H0, H1, H2, H3, H4)
Code: (Select All)

SHA1$ = String$(20, 0)

For I = 0 To 4
    Mid$(SHA1$, I * 4 + 1, 4) = MKL$(H(I))
Next I

You can refer to my sha256 algorithm, for optimizations.

I don't think anyone made this thing before, you are the first one.
Reply


Messages In This Thread
TOTP 100% qb64 Yup - sorta LOL - by Ra7eN - 06-02-2025, 05:51 PM
RE: TOTP 100% qb64 Yup - sorta LOL - by aadityap0901 - 06-02-2025, 06:30 PM
RE: TOTP 100% qb64 Yup - sorta LOL - by Ra7eN - 06-02-2025, 08:23 PM
RE: TOTP 100% qb64 Yup - sorta LOL - by Ra7eN - 06-02-2025, 08:45 PM
RE: TOTP 100% qb64 Yup - sorta LOL - by Ra7eN - 06-03-2025, 05:26 PM
RE: TOTP 100% qb64 Yup - sorta LOL - by Ra7eN - 06-03-2025, 12:00 PM
RE: TOTP 100% qb64 Yup - sorta LOL - by Jack - 06-03-2025, 07:10 PM
RE: TOTP 100% qb64 Yup - sorta LOL - by Ra7eN - 06-04-2025, 04:38 PM



Users browsing this thread: 2 Guest(s)