c++ - XOR Encryption algorithm unable to handle input greater than 127 chars in length -
I have a similar encryption method on my client and my server:
QByteArray server :: Encrypt (Caststring input) {std :: string Basic = input.toStdString (); Std :: string encrypted = ""; Std :: string key = "key"; (Unsigned integer temp = 0; temp & lt; original.size (); temp ++) {encrypted + = original [temp] ^ ((atoi (key.c_str ()) + temp) + 2)% 253; } QByteArray byteArray (encrypted. C_str (), encrypted. Lang ()); Return bytes; } And I am passing QString with the length of 143 characters in the function. When I pass a QByteArray to my decrypt function with an encrypted text (which simply reverses Xor Encryption), it will first decrypt 126 characters correctly, but the remainder of the string is incorrect Will be decrypted by the way. If I look at the encrypted string, then 126th after all the characters in the instead of the random characters? I hope as I am not sure what is the reason that there is an array of QByteArray bytes, so the maximum element which can be an element is limited to the size of a byte, although I Not sure that the number of elements seems limited to the size of a byte, especially QByteArray :: size () returns an integer. When I debug the program and look at the contents of QByteArray , element 0-125 is fine, but the remaining element (127th element at position 126) are negative numbers - For example, instead of looking at 91 '[' as a value at any place], I see -79 / 177 I How can I go about fixing this issue, so I can run this encryption with an input length of more than 126?
If the encryption algorithm generates the value 0 for a byte Line encrypted + = original [temp] ^ ((ATO (cc seistrite) + temporary) + 2)% 253; Nothing will do anything, line
QByteArray byteArray (encrypted.c_str), encrypted. Lang ()); will end up reaching the bound memory.
In addition, you have defined
std :: string key = "key"; And then you are using atoi (key.c_str ()) . It will always return 0 to the hope that it is an inspection. My suggestion is:
QByteArray Server :: Encrypt (Caststring input) {std :: string Basic = input.toStdString (); Size_t size = original size (); Std :: vector & lt; Unsigned four & gt; Encrypted (size); Std :: string key = "key"; (Unsigned integer temp = 0; temp & lt; size; temp ++) {encrypted [temp] = root [temporary] ^ ((atoi (key.c_str ()) + temporary) + 2)% 253; } Cubic Array byte (encrypted data (size)); Return bytes; }
Comments
Post a Comment