VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A simple Substitution function. Works on HEX data. (This _Applies_ it to the HEX data, You also nee

by Glenn Larsson (5 Submissions)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Originally Published: Mon 15th November 1999
Date Added: Mon 8th February 2021
Rating: (1 Votes)

A simple Substitution function. Works on HEX data. (This _Applies_ it to the HEX data, You also need the GenerateSBox() function.)

Rate A simple Substitution function. Works on HEX data. (This _Applies_ it to the HEX data, You also nee




'
' Disclaimer: This is not supposed to be used for any other purpose than to learn what an SBox is.
' This is not an encryption system but a part of one, if you use it AS one = Good luck!
'
' ABSOLUTELY NO SUPPORT will be provided via Email!
' Free for educational use (C) 1999 Glenn Larsson ([email protected])
'

Dim TMP As String
TMP = UCase(Data): Data = TMP ' Yes we should all be using UCase..
TMP = UCase(SBox): SBox = TMP
TMP = "0"

' Data = Hex data in a string you wish to apply the SBox on
' SBox = Hex string, the SBox returned from GenerateSbox()
' Marker
'   1 Encrypt
'   2 Decrypt
' Fairly simple..

If Marker = 1 Then GoTo Encrypt:
If Marker = 2 Then GoTo Decrypt:
Exit Function

Encrypt: ' Start the SBox
For BC = 1 To Len(Data) Step 2
    CB = HexToDec(Mid(Data, BC, 2))
    ZZ = 1 + (CB * 2)
    If ZZ < 0 Then ZZ = 0
    RCB = Mid(SBox, ZZ, 2)
    TOT = TOT & RCB
Next BC
GoTo Nding:

Decrypt: ' Reverse the SBox
For BC = 1 To Len(Data) Step 2
    CB = Mid(Data, BC, 2)
    For I = 1 To 512 Step 2
        If Mid(SBox, I, 2) = CB Then RCB = ((I + 1) / 2)
    Next I
    RCB = RCB - 1
    L = "" ' return proper 2 digit Hex value
    If RCB < 16 Then L = "0"
    TOT = TOT & L & Hex(RCB)
Next BC
GoTo Nding:

Nding:
ApplySBox = TOT

End Function


Download this snippet    Add to My Saved Code

A simple Substitution function. Works on HEX data. (This _Applies_ it to the HEX data, You also nee Comments

No comments have been posted about A simple Substitution function. Works on HEX data. (This _Applies_ it to the HEX data, You also nee. Why not be the first to post a comment about A simple Substitution function. Works on HEX data. (This _Applies_ it to the HEX data, You also nee.

Post your comment

Subject:
Message:
0/1000 characters