I created a simple two way cryptographic function which allows you to encrypt a message and decrypt it with the same key. Here's how it works.
- Split the message into an array of 32-bit (or something else, depending on your key's length) segments
- Generate a random 32-bit number and xor all segments with it, and append it to the start of the array. (This is done to prevent an attacker recognizing that the same message or certain parts of it have been sent twice)
- Xor all segments with a hash of the key and the index of the segment. The index is included to prevent an attacker finding patterns inside the message where there are 0s or some other known data.
My questions are:
- Does there already exist a similar two-way function?
- Are there any flaws in it, and if so, what can be done to correct them?
Please explain in simple terms, I'm not a cryptography expert.