Public Class Form1
Public Function XorChk(ByVal bytes() As Byte, ByVal length As Integer) As Byte
Dim tempByte As Byte
Dim Index As Integer
tempByte = bytes(0) '把第一个二进制数的值赋值给tmpByte
For Index = 1 To length - 1
tempByte = tempByte Xor bytes(Index) '依次对数值进行异或
Next
Return tempByte '返回异或后的值
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim byt(0) As Byte
If Me.TextBox1.Text <> "" And TextBox1.TextLength Mod 2 = 0 Then
ReDim byt(Me.TextBox1.TextLength / 2 - 1)
For i As Integer = 0 To Me.TextBox1.TextLength / 2 - 1
byt(i) = Convert.ToInt16(Mid(Me.TextBox1.Text, i * 2 + 1, 2), 16)
Next
TextBox2.Text = UCase(Convert.ToString(XorChk(byt, Me.TextBox1.TextLength / 2), 16))
End If
End Sub
End Class
Public Function XorChk(ByVal bytes() As Byte, ByVal length As Integer) As Byte
Dim tempByte As Byte
Dim Index As Integer
tempByte = bytes(0) '把第一个二进制数的值赋值给tmpByte
For Index = 1 To length - 1
tempByte = tempByte Xor bytes(Index) '依次对数值进行异或
Next
Return tempByte '返回异或后的值
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim byt(0) As Byte
If Me.TextBox1.Text <> "" And TextBox1.TextLength Mod 2 = 0 Then
ReDim byt(Me.TextBox1.TextLength / 2 - 1)
For i As Integer = 0 To Me.TextBox1.TextLength / 2 - 1
byt(i) = Convert.ToInt16(Mid(Me.TextBox1.Text, i * 2 + 1, 2), 16)
Next
TextBox2.Text = UCase(Convert.ToString(XorChk(byt, Me.TextBox1.TextLength / 2), 16))
End If
End Sub
End Class