Wednesday, February 8, 2012 defeat simple padding obfuscation

There is an applicationthat obfuscates a serial number by padding each character. Here is a de-obfuscator I made.

First: define the array with all the characters the algorithm uses:

    Public charArray() As Char = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", _
                           "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", _
                           "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", _
                           "V", "W", "X", "Y", "Z"}

Function that will deobfuscate it.

    Private Function OffsetAChar(ByVal chartooffset As Char, ByVal offset As Integer)
        Dim posInArray As Integer = Array.IndexOf(charArray, chartooffset)
        Dim ArrayLength As Integer = charArray.Length

        If posInArray + offset = ArrayLength Then
            Return "0"
        End If

        If (posInArray + offset) <= ArrayLength And (posInArray + offset) > 0 Then
            Return charArray(posInArray + offset)
        End If

        If posInArray + offset = 0 Then
            Return 0
        End If

        If (posInArray + offset) < 0 Then
            Return charArray(ArrayLength + posInArray + offset)
        End If

        If (posInArray + offset) > ArrayLength Then
            Return charArray(Math.Abs(ArrayLength - (posInArray + offset)))
        End If

    End Function

Usage is simple:

        Dim charArray2() As Char

        Dim ArraySTring As String = txtDecode.Text
        ArraySTring = ArraySTring.Replace("-", "")
        charArray2 = ArraySTring

       txtCodeDecoded.Text += OffsetAChar(charArray2(0), -19).ToString.ToUpper

Figuring out the offset of two letters

    Public Function OffsetFinder(ByVal letter1 As Char, ByVal letter2 As Char)

        Dim CharPos1 = Array.IndexOf(charArray, letter1)
        Dim CharPos2 = Array.IndexOf(charArray, letter2)
        Return CharPos2 - CharPos1

    End Function

No comments:

Post a Comment