Click here to Skip to main content
15,065,644 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Dim num5 As Integer = CInt((c And "ÿ"c))
Operator 'And' is not defined for the types 'Char' and 'Char'


Dim num7 As Integer = CInt((c >> 8))

Operator '>>' is not defined for types 'Char' and 'Integer'.


array2(num4) = CUShort((CInt(b2) << 8 Or CInt(b)))

'UShort' values cannot be converted to 'Char'. Use 'Microsoft.VisualBasic.ChrW' to interpret a numeric value as a Unicode character or first convert it to 'String' to produce a digit.


What I have tried:

Helllo Coders, I am having errors on mentioned codes, code & errors are mentioned.

Please help
Posted
Updated 11-Jan-21 6:46am

You are trying to use logical operators on characters which is not allowed. Secondly you are trying to turn a number into a character which again is not valid. Please read Operators and Expressions - Visual Basic | Microsoft Docs[^].
   
Comments
Hemil Gandhi 12-Jan-21 12:06pm
   
Dear Sir, Thanks for all your effort. Actually I have pre written code in which developer has encrypted sql query using some function & above lines are part of that function. I am getting error on those particular lines. So I have to solve this error to get what is written in query.
Richard MacCutchan 12-Jan-21 12:25pm
   
What do you expect us to do? I have explained what you are doing wrong and where to look to understand why.
To add to what Richard says: Even if it worked, AND is a bad idea from an encryption point of view.
If you AND two one bit values:
A->  0 1
B
| 0  0 0
V 1  0 1
You only have two results: zero and one. And three of them are zero, so you have no way to tell from the result what the original inputs were, even if you know one of them! If A == 0, then both B == 0 and B == 1 generate the same output, so you cannot "decrypt" your output and get your original value.
The same thing happens with a binary AND: each bit-pair in the two inputs is combined, and you can't work out what you started with even if you know the result and either A or B.

XOR is the only two value binary operation that can be reversed (or "decrypted").

And to be honest, even if you use XOR, your encrypted data is going to be ... unsafe. As in "very easy to crack".

If you want to encrypt strings, look at DES or similar: .NET includes implementations which need very little effort on your part and are miles stronger than anything a non-expert could produce.
   
Comments
Hemil Gandhi 12-Jan-21 12:06pm
   
Dear Sir, Thanks for all your effort. Actually I have pre written code in which developer has encrypted sql query using some function & above lines are part of that function. I am getting error on those particular lines. So I have to solve this error to get what is written in query.
OriginalGriff 12-Jan-21 12:23pm
   
I think you read his query wrong ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900