Re: Chr() and Asc() problem
Can you post a more expanded code sample? Also, have you considered:
A) Not implementing your own encryption method, and using a tried and tested method built into the .NET Framework?
B) Using a StringBuilder for string appends for performance?
Re: Chr() and Asc() problem
I have considered A, but still want to do my own :p
It's quite a good logic, with this little exception I just can't get.
Re: Chr() and Asc() problem
Can you post a little more of the code you're using?
Re: Chr() and Asc() problem
You may want to try Text.ASCIIEncoding.GetEncoding(Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage).GetCh ars() instead of Chr() and Text.ASCIIEncoding.GetEncoding(Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage).GetBy tes() instead of Asc(). I think that Chr and Asc are pretty much culture agnostic and don't do a good job for anything else other than the standard ASCII character set.
Re: Chr() and Asc() problem
Quote:
Originally Posted by
gavio
I'm creating my own encryption routine. In my function I have a loop that goes through the complete string character by character and finally, concatenating each character (encrypted of course) to the final result (in this case, "x"):
Code:
x = x & Chr(SomeCode) 'where "SomeCode" is for example 255 (last ASCII)
Everything is fine until here. But when this function returns this result ("x"), 255 changes to 63.
And ideas what am I doing wrong?? :confused:
The standard encoder returns ? (63) for any value greater than 127. You can use windows-1252 (i think that is the one) and get all 256.
Re: Chr() and Asc() problem
I was wrong. This works:
Code:
Dim s As String = ""
For x As Integer = 0 To 255
s &= Chr(x)
Next
For Each c In s
Debug.Write(c & " ")
Debug.WriteLine(Asc(c))
Next