2017-02-03 169 views
-4

我一直在撞墙,试图将这个经典的asp(vb)转换为asp.net c#而没有运气。将此函数从VB转换为c#

Function Decrypt1(s) 
    if isnull(s) then 
    Decrypt1 = "" 
    else 
    Dim r, i, ch 
    For i = 1 To Len(s)/2 
     ch = "&H" & Mid(s, (i-1)*2+1, 2) 
     ch = ch Xor 111 
     r = r & Chr(ch) 
    Next 
    Decrypt1 = strReverse(r) 
    end if 
End Function 

任何接受者?

提前致谢!

编辑 - “0B031D00180003030A07” 应该解密为 “HelloWorld” 的

+0

您是否尝试过在线转换器? – Bugs

+0

什么是s的数据类型? –

+1

漂亮的蹩脚加密 – Plutonix

回答

0

更新

下面是用于解密你的字符串你的c-锐方法:

public static string Decrypt1(string s) 
    { 
     string functionReturnValue = null; 
     if (string.IsNullOrEmpty(s)) 
     { 
      functionReturnValue = ""; 
     } 
     else 
     { 
      string r = null; 
      int ch = null; 

      for (int i = 0; i < s.Length/2; i++) 
      { 
       ch = int.Parse(s.Substring((i) * 2, 2), NumberStyles.AllowHexSpecifier); 
       ch = ch^111; 
       r = r + (char)(ch); 
      } 

      var charArray = r.ToCharArray(); 
      Array.Reverse(charArray); 
      functionReturnValue = new string(charArray); 
     } 
     return functionReturnValue; 
    } 

Try it on Net Fiddle

+0

&H是在c#,十六进制代号0x。可能没有转换器是足够聪明的解决这个问题。 – dlatikay

+0

是啊上面的代码看起来就像代码我从转换器 –

+0

得到有这么多奇怪的隐式铸造进行,这并不像乍看起来那么微不足道,虽然xor很好; ^运算符 – dlatikay

0

这一个能与您的HelloWorld示例:

public static string Decrypt1(string s) 
    { 
     if (string.IsNullOrEmpty(s)) 
      return string.Empty; 

     string r = null; 
     for (int i = 1; i <= s.Length/2; i++) 
     { 
      var ch = Convert.ToUInt32(s.Substring((i - 1) * 2, 2), 16); 
      ch = ch^111; 
      r = r + (char)(ch); 
     } 

     var charArray = r.ToCharArray(); 
     Array.Reverse(charArray); 

     return new string(charArray); 
    } 
+0

这个作品也是!非常感谢! –

+0

@MikeMorehead不用担心。随意标记答案是有用的。 :-) – Freakshow