VB6 Unicode
-
I'm working on a simple encryption scheeme. I get the asc value of the a character in the string to be encrypted. Adding 255 to it turns it into a uniocode char. Then I use AscW to convert that char into a long. Then I convert the long to a hexidecimal. I store this as the encrypted string in my access database. It looks good sE='the string to be encrypted' for i=1 to len(sE) lValue = Asc(mid(Se,i,1)) + 256 sNew=sNew & format(hex(lvalue),"0000") next i Then I store this string in my access database. The problem lies when I decrypt the encrypted string sE='increpted string' for i=1 to len(se) step 4 lvalue="&h" & mid(se,1,4) sNew=sNew & ChrW(lValue) next i All I get is a lot of ?'s Instead of the unicode string?. Any advice would be appreaciated - Roger
-
I'm working on a simple encryption scheeme. I get the asc value of the a character in the string to be encrypted. Adding 255 to it turns it into a uniocode char. Then I use AscW to convert that char into a long. Then I convert the long to a hexidecimal. I store this as the encrypted string in my access database. It looks good sE='the string to be encrypted' for i=1 to len(sE) lValue = Asc(mid(Se,i,1)) + 256 sNew=sNew & format(hex(lvalue),"0000") next i Then I store this string in my access database. The problem lies when I decrypt the encrypted string sE='increpted string' for i=1 to len(se) step 4 lvalue="&h" & mid(se,1,4) sNew=sNew & ChrW(lValue) next i All I get is a lot of ?'s Instead of the unicode string?. Any advice would be appreaciated - Roger
The immediate problem with your code is that the
Hex
function will return a three-character string for any character whose ASCII code is less than 3840, but when you try to decode the string, you're taking four characters at a time. The larger problem is that you're trying to invent your own "encryption" algorithm, and that's never a good idea. Use an established and tested algorithm instead. CAPICOM[^] would be a good place to start. Finally, you appear to be starting a new project in a dead language. VB6 was released 15 years ago, and is no longer supported. You should switch to .NET - Visual Studio Express[^] is free, and should be more than enough to get you started.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer