|
-
Apr 14th, 2010, 01:00 PM
#1
Chr() and Asc() problem
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??
-
Apr 14th, 2010, 01:07 PM
#2
Lively Member
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?
-
Apr 14th, 2010, 01:13 PM
#3
Re: Chr() and Asc() problem
I have considered A, but still want to do my own 
It's quite a good logic, with this little exception I just can't get.
-
Apr 14th, 2010, 01:15 PM
#4
Lively Member
Re: Chr() and Asc() problem
Can you post a little more of the code you're using?
-
Apr 15th, 2010, 04:36 PM
#5
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.
-
Apr 15th, 2010, 04:46 PM
#6
Re: Chr() and Asc() problem
 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?? 
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.
-
Apr 15th, 2010, 04:51 PM
#7
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
Last edited by dbasnett; Apr 15th, 2010 at 04:58 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|