简体   繁体   English

反向XOR加密不起作用?

[英]Reversing XOR Encryption not working?

So I have the following function To XOR a string and it works but when I pass the encrypted string back into it the output is not decrypetd. 因此,我具有以下函数来对字符串进行XOR运算,并且可以正常工作,但是当我将加密的字符串传递回该字符串时,输出不会被解密。 MY understanding is to De XOR something is to simply XOR it again but it seems to fail, Any ideals on why this is ? 我的理解是对De XOR进行某种处理,就是对它再次进行XOR处理,但似乎失败了,这是为什么? Also Im storing the xor as hex 我也将异或存储为十六进制

Public Shared Function StringToHash(ByVal str As String) As Integer
    Dim hash As Integer = (AscW(Char.ToLower(str(0))) Xor &H4B9ACE2F) * &H1000193
    For i As Integer = 1 To str.Length - 1
        hash = (AscW(Char.ToLower(str(i))) Xor hash) * &H1000193
    Next
    hash = hash * &H1000193
    Return hash
End Function

As already indicated, this is about hashing, not encryption - two related but separate notions. 如前所述,这是关于散列而不是加密-两个相关但独立的概念。


Although secure hashes are one-way, the above function is certainly not a secure hash. 尽管安全哈希是单向的,但上述功能当然不是安全哈希。 So you may be able to reverse it for very small input sizes. 因此,对于很小的输入大小,您可以将其反转。

Besides that, although hashes are usually not reversible, it may be possible to brute force the hash value. 除此之外,尽管散列通常不可逆,但有可能强行强制散列值。

This would only work for if the input alphabet is limited (a few characters, or a limited set of words etc.) and it may return too many inputs if the hash output size is small (which in this case it certainly is). 这仅在输入字母有限(几个字符或一组有限的单词等)的情况下有效,并且如果散列输出大小较小(在这种情况下肯定是这样),则可能返回太多输入。 But otherwise you just toss in some input and test if it results in the same hash value. 但是,否则,您只需要输入一些输入并测试它是否导致相同的哈希值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM