0
我已經編寫了一個解決方案,我相信它可以在Visual Basic中進行循環位移。不過,我對這門語言很陌生,我不能100%確定這是有效的或功能性的。有沒有更好的方法來做到這一點?Visual Basic中的循環位移
如果您好奇,我試圖執行ARIA cipher,我需要這個功能來做到這一點。
Private Function CircularRotationLeft(ByVal bytes As Byte(), ByVal times As Integer) As Byte()
Dim carry As Boolean = False
If times < 0 Then
Return Nothing
End If
While times > bytes.Length * 8
times -= bytes.Length * 8
End While
If times = 0 Then
Return bytes
End If
Array.Reverse(bytes)
For index As Integer = 1 To times
For Each bits As Byte In bytes
If bits > 127 Then
bits -= 128
bits *= 2
If carry Then
bits += 1
End If
carry = True
Else
bits *= 2
If carry Then
bits += 1
End If
carry = False
End If
Next
If carry Then
bytes(0) += 1
End If
Next
Array.Reverse(bytes)
Return bytes
End Function
Private Function CircularRotationRight(ByVal bytes As Byte(), ByVal times As Integer) As Byte()
Dim carry As Boolean = False
If times < 0 Then
Return Nothing
End If
While times > bytes.Length * 8
times -= bytes.Length * 8
End While
If times = 0 Then
Return bytes
End If
Array.Reverse(bytes)
For index As Integer = 1 To times
For Each bits As Byte In bytes
If bits Mod 2 = 0 Then
bits /= 2
If carry Then
bits += 128
End If
carry = False
Else
bits /= 2
If carry Then
bits += 128
End If
carry = True
End If
Next
If carry Then
bytes(0) += 128
End If
Next
Array.Reverse(bytes)
Return bytes
End Function
請檢查標籤簡介,這不是[tag:vba]。 –
抱歉的錯誤,並感謝您修復它! – Tazze