VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Rotate an 8 by 8 bit array. Greate as an addition to an encryption algorithm. The process takes upt

by BaMTek, Inc. (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 24th January 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Rotate an 8 by 8 bit array. Greate as an addition to an encryption algorithm. The process takes upto 8 chars and creates an 8 by 8 bit array

Rate Rotate an 8 by 8 bit array. Greate as an addition to an encryption algorithm. The process takes upt



'Create a form with for textboxes and a command button
Private Sub Command1_Click()
    Dim strReturn As String
    'Text1 contains the original text (up to eight chars)
    'Text3 should consist of a number between 0 and 3
    strReturn = RotateBitArray(Get_8_By_8_BitArray(Text1.Text), Text3.Text)
    Text2.Text = strReturn
    'Text4 holds to original string converted back
    Text4.Text = RotateBitArray(Get_8_By_8_BitArray(strReturn), 4 - Text3.Text)
End Sub

Private Function GetBitArray(ByVal Character As String) As Byte()
    'Creates an array of 8 bits based on the value of the single char
    Dim bytChar As Byte
    Dim strReturn As String
    Dim i As Integer
    Dim byReturn() As Byte
    
    bytChar = Asc(Left(Character, 1))
    
    Dim bytArray() As Byte
    
    ReDim bytArray(8)
    
    bytArray(0) = 1
    bytArray(1) = 2
    bytArray(2) = 4
    bytArray(3) = 8
    bytArray(4) = 16
    bytArray(5) = 32
    bytArray(6) = 64
    bytArray(7) = 128
    
    ReDim byReturn(8)
    For i = 7 To 0 Step -1
        If bytChar >= bytArray(i) Then
            byReturn(7 - i) = 1
            bytChar = bytChar - bytArray(i)
        Else
            byReturn(7 - i) = 0
        End If
    Next i
    
    GetBitArray = byReturn

End Function

Private Function Get_8_By_8_BitArray(ByVal EightChars As String) As Byte()
    'Creates an 8 by 8 bit array using 8 chars
    Dim strChars As String * 8
    Dim byArray() As Byte
    ReDim byArray(8, 8)
    
    strChars = EightChars
    
    Dim i As Integer
    Dim x As Integer
    Dim byTemp() As Byte
    For i = 0 To Len(strChars) - 1
        byTemp = GetBitArray(Mid(strChars, i + 1, 1))
        For x = 0 To 7
            byArray(i, x) = byTemp(x)
        Next x
    Next i
    Get_8_By_8_BitArray = byArray
End Function

Private Function RotateBitArray(ByRef byArray() As Byte, ByVal ModValue As Integer) As String
    'Rotates the 8 by 8 bit array clockwise 0 - 3 times and return the resulting string
    Dim i As Integer
    Dim strArray() As String
    Dim byTemp() As Byte
    Dim x As Integer
    ReDim strArray(8)
    ReDim byTemp(8)
    
    Select Case ModValue
        Case 1
            For i = 0 To 7
                For x = 7 To 0 Step -1
                    byTemp(7 - x) = byArray(x, i)
                Next x
                strArray(i) = Chr(ConvertBitArrayToByte(byTemp))
            Next i
        Case 2
            For i = 7 To 0 Step -1
                For x = 7 To 0 Step -1
                    byTemp(7 - x) = byArray(i, x)
                Next x
                strArray(7 - i) = Chr(ConvertBitArrayToByte(byTemp))
            Next i
        Case 3
             For i = 7 To 0 Step -1
                For x = 0 To 7
                    byTemp(x) = byArray(x, i)
                Next x
                strArray(7 - i) = Chr(ConvertBitArrayToByte(byTemp))
            Next i
        Case Else 'Default to 0 
            For i = 0 To 7
                For x = 0 To 7
                    byTemp(x) = byArray(i, x)
                Next x
                strArray(i) = Chr(ConvertBitArrayToByte(byTemp))
            Next i
    End Select
    
    RotateBitArray = Join(strArray, vbNullString)
End Function

Private Function ConvertBitArrayToByte(ByRef BitArray() As Byte) As Byte
    'Returns the byte value of a bitarray
    Dim bytArray() As Byte
    Dim byReturn As Byte
    ReDim bytArray(8)
    
    bytArray(7) = 1
    bytArray(6) = 2
    bytArray(5) = 4
    bytArray(4) = 8
    bytArray(3) = 16
    bytArray(2) = 32
    bytArray(1) = 64
    bytArray(0) = 128
    
    Dim i As Integer
    
    For i = 0 To 7
        byReturn = bytArray(i) * BitArray(i) + byReturn
    Next i
    
    ConvertBitArrayToByte = byReturn
End Function

Download this snippet    Add to My Saved Code

Rotate an 8 by 8 bit array. Greate as an addition to an encryption algorithm. The process takes upt Comments

No comments have been posted about Rotate an 8 by 8 bit array. Greate as an addition to an encryption algorithm. The process takes upt. Why not be the first to post a comment about Rotate an 8 by 8 bit array. Greate as an addition to an encryption algorithm. The process takes upt.

Post your comment

Subject:
Message:
0/1000 characters