我认为这就是你要找的:
Module Module1
Sub Main()
Dim bytes() As Byte = {&H17, &H0, &H0, &H0, &HA4, &HEA, &HDB, &H13, &H2, &H0, &H0, &H0, &H0, &H0, &H0, &HA3, &HD3, &H2, &HCC}
Combine(New Byte() {}, bytes)
End Sub
Sub Combine(ByVal sequence() As Byte, ByVal pool() As Byte)
' test current sequence
If Test(sequence) Then
Console.Write("Found sequence: ")
For Each b As Byte In sequence
Console.Write("{0:X2} ", b)
Next
Console.WriteLine()
End If
' done if pool is empty
If pool.Length = 0 Then
Return
End If
' recurse adding next byte from the pool
Dim newSequence(sequence.Length) As Byte
Array.Copy(sequence, newSequence, sequence.Length)
newSequence(sequence.Length) = pool(0)
Dim newPool(pool.Length - 2) As Byte
Array.Copy(pool, 1, newPool, 0, pool.Length - 1)
Combine(newSequence, newPool)
' recurse without adding next byte from the pool
Combine(sequence, newPool)
End Sub
Function Test(ByVal sequence() As Byte) As Boolean
' the test function that you haven't provided goes here
' this example returns True if the sequence is 4 bytes or more, causing every combination of at least 4 bytes to be printed
If (sequence.Length >= 4) Then
Test = True
Else
Test = False
End If
End Function
End Module
我将测试功能的实现留给您,因为您没有在原始问题中提供。我的实现基本上将所有 4 个字节或更多字节的序列视为通过测试,因此它会打印所有组合。
我使用了一个递归算法,它以一个空序列和一个字节“池”中的所有 19 个字节开始。然后我通过将池的第一个字节移动到我正在构建的序列中进行递归,然后完全忽略池的第一个字节。