Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27329

VS 2010 Checksum with Xor

$
0
0
Hi, If some one can helpme with my problem I'll really appreciate.

I'm trying ton send a string like "Hi this is the 2nd message"

to send it I need to get hex value from each character " 48 69 20 74 68 69 73 20 69 73 20 74 68 65 20 32 6e 64 20 6d 65 73 73 61 67 65"

my code already send word like AA or BEBE or numbers. but If I try to send something like "z" I get Conversion from string "A" to type 'Long' is not valid.

and with the numbers I only can send numbers with long 4,8,12. like 20,5612, 785394

but if I try to send 4 or 100 I get a wrong check sum.

my code is:


Private Sub btnDato_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDato.Click
Dim strTEmp As String
Dim strchecksum As String
Dim strtohex As String
Dim strReturn As String
Dim checksum As String = 74
Dim strcheck As String
Dim TAM As Long

spPuertos.DiscardOutBuffer()
StrSalida = txtSalida.Text
'spPuertos.Write(StrSalida)
'------------------------------------------------
'------------------------------------------------
For I = 1 To Len(StrSalida)
strTEmp = Hex$(Asc(Mid$(StrSalida, I, 1)))
' If Len(strTEmp) = 1 Then strTEmp = "0" & strTEmp
strReturn = strReturn & strTEmp
Next I
strtohex = strReturn
'resultado2.Text = strtohex FUNCIONA CORRECTAMENTE SI SE ENVIA 100 SE OBTIENE 313030

TAM = Len(strtohex)
resultado2.Text = TAM
For I = 1 To TAM

checksum = Hex(CLng("&H" & checksum) Xor CLng(Mid(strtohex, I, 1)))
''checksum = checksum Xor Mid(strtohex, I, TAM)
Next
strcheck = Val(checksum)

Viewing all articles
Browse latest Browse all 27329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>