我試圖用c#中的密鑰解密異或字符串,但解密是錯誤的,我得到錯誤的值。在c#中異或解密#
string text = "xorhash";
string key = "xorkey";
var result = new StringBuilder();
for (int c = 0; c < text.Length; c++)
result.Append((char)((uint)text[c]^(uint)key[c % key.Length]));
return result.ToString();
我已經從這個Python代碼中獲得了,它工作的很好。
def xor(message, key):
return "".join(chr(ord(message[i])^ord(key[i % len(key)])) for i in xrange(len(message)))
key = "my_xor_key"
message = "my_xor_hash".decode("hex")
print xor(message, key)
輸出什麼是期待? –
my_xor_hash^my_xor_key無法輸出你提供的任何值 –
無論如何,你的問題是因爲python字符串是從十六進制表示解碼,但c#不這樣做 –