C#中的运算符'^'(xor)出现问题 [英] Problem with Operator '^' (xor) in C#

查看:90
本文介绍了C#中的运算符'^'(xor)出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.
我在C#中的运算符XOR上遇到问题(运算符"^"不能应用于类型为"int"和"double"的操作数).
我不知道为什么会收到这个错误,我真的希望有人能够告诉我我做错了什么.

注意:我已经在VB中编写了代码,并且可以正常工作.

这是我在C#中的代码:

Hello There.
I''m having a problem with the operator XOR in C# (Operator ''^'' cannot be applied to operands of type ''int'' and ''double'').
I don''t know why I''m getting this error and I really hope that someone will be able to tell me what I''m doing wrong.

Note: I have made the code in VB and it works fine.

This is my code in C#:

string key, Pass2;
string car, code;
int i,j;
key = "&@/.^$#!%ü";
Pass2 = "";
j = 1;
for (i = 1; i <= Pass.Length; i +=2)
{
    car = Strings.Mid(Pass, i, 2);
    code = Strings.Mid(key, ((j - 1) % key.Length) + 1, 1);

    Pass2 = Pass2 + Strings.Chr(Strings.Asc(code) ^ Conversion.Val("&h" + car)); //here's where I'm getting the error 
    j = j + 1;
}
return Pass2;



而这在VB中:



And this one in VB:

Function DeCrypt(ByVal Pass As String) As String
    Dim Key As String, i As Integer, Pass2 As String
    Dim CAR As String, Code As String
    Dim j As Integer
    'Key = "%ü&/@#$A"
    Key = "&@/.^$#!%ü"
    Pass2 = ""
    j = 1
    For i = 1 To Len(Pass) Step 2
        CAR = Mid(Pass, i, 2)
        Code = Mid(Key, ((j - 1) Mod Len(Key)) + 1, 1)
        Pass2 = Pass2 & Chr(Asc(Code) Xor Val("&h" + CAR))
        j = j + 1
    Next i
    DeCrypt = Pass2
End Function

推荐答案

#!%ü"; Pass2 = " ; j = 1 ; for (i = 1 ; i >< = Pass.Length; i + = 2 ) { car = Strings.Mid(Pass,i, 2 ); 代码= Strings.Mid(key,(((j- 1 )%key.Length)+ 1 1 ); Pass2 = Pass2 + Strings.Chr(Strings.Asc(code)^ Conversion.Val(" 跨度> +汽车)); // 这是我收到错误消息的地方 j = j + 1 ; } 返回 Pass2;
#!%ü"; Pass2 = ""; j = 1; for (i = 1; i <= Pass.Length; i +=2) { car = Strings.Mid(Pass, i, 2); code = Strings.Mid(key, ((j - 1) % key.Length) + 1, 1); Pass2 = Pass2 + Strings.Chr(Strings.Asc(code) ^ Conversion.Val("&h" + car)); //here's where I'm getting the error j = j + 1; } return Pass2;



而这在VB中:



And this one in VB:

Function DeCrypt(ByVal Pass As String) As String
    Dim Key As String, i As Integer, Pass2 As String
    Dim CAR As String, Code As String
    Dim j As Integer
    'Key = "%ü&/@#


A" 键= "
A" Key = "&@/.^


#!%ü" Pass2 = " j = 1 对于 i = 1 Len(通过)步骤 2 CAR =中(Pass,i, 2 ) Code = Mid(Key,((j- 1 ) Mod Len(Key))+ 1 1 ) Pass2 = Pass2& Chr(Asc(Code) Xor Val(" + CAR)) j = j + 1 下一个我 解密= Pass2 结束 功能
#!%ü" Pass2 = "" j = 1 For i = 1 To Len(Pass) Step 2 CAR = Mid(Pass, i, 2) Code = Mid(Key, ((j - 1) Mod Len(Key)) + 1, 1) Pass2 = Pass2 & Chr(Asc(Code) Xor Val("&h" + CAR)) j = j + 1 Next i DeCrypt = Pass2 End Function


这篇关于C#中的运算符'^'(xor)出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆