[英]Xor function from C# to VB.NET
can some one help me with this? 有人可以帮我弄这个吗? I want to convert this CSharp function to VB. 我想将此CSharp函数转换为VB。
Function in CSharp: CSharp中的功能:
public static string XOR(string key, string input)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < input.Length; i++)
sb.Append((char)(input[i] ^ key[(i % key.Length)]));
String result = sb.ToString();
return result;
}
What I have in VB: 我在VB中拥有什么:
Public Function XOR(Key As String, Input As String) As String
Dim sb As StringBuilder = New StringBuilder()
For i As Integer = 0 To Input.Length - 1
sb.Append(Chr(Asc(Input(i))) ... )
Next
Dim Result As String = sb.ToString()
Return Result
End Function
Thanks 谢谢
I'm surprised you were able to write a function called XOR
because that's a keyword in VB.NET. 我很惊讶您能够编写一个名为XOR
的函数,因为这是VB.NET中的关键字。 You'll have to escape the name as follows: [XOR]
to have a method with that name. 您必须按如下所示对名称进行转义: [XOR]
具有使用该名称的方法。
To do your Xor operation, you just need the built in VB.NET Xor
operator. 要执行Xor操作,您只需要内置的VB.NET Xor
操作符。 Consider the following code. 考虑以下代码。
For i = 0 To Input.Length - 1
sb.Append(ChrW(AscW(input(i)) Xor AscW(key(i Mod key.Length))))
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.