2017-02-03 136 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