### My custom encryption: Math makes me nauseous...

Pages: 12
I have an encryption equation:

`z = (((x + (y + 1)) * (y + 1)) - ((y + 1) * 2));`

where y = The Nth character in the string (+ 1 because we start at 0 instead of 1)

y is:

-ALWAYS positive
-never zero

where x = the character ID (a-z -> 0-25)

x can be:

-equal to 0

and where z = the new character's ID.

z is/(can be):

- negative
- positive
- equal zero

Assume that the algorithm works, and that everything is fine but the equation. To decrypt a message, we need to inverse the encryption equation. Now, i never really liked Trig, and I never was really good at it. I have tried for about an hour now to inverse this THING, and the result is not promising. This is why i have come to you. If you are a math wiz, and would like to try your hand, please make a post with your answer, i will plug in the equation to my program, and post iether "success", or "failure". Thank you for your hard work, and your help. I really appreciate your time.

PS: for those of you who probably think this is a class assignment, it is not. I'm learning C++ on my own, and would thank you not to scrutinize my post.

IM SO SORRY!! I POSTED THE WRONG PARAMETERS FOR 'Y'!

here are the real parameters:

y >= 0

Again, im SO SO sorry. I know you may have put in a lot of effort and im sorry.
Last edited on
What's N? Can you give an example of encryption?
You need algebra not trig
try this, x=(z-(y*y))/(y-1.0f). It may or may not work.
Last edited on
 ``12345678`` `````` z = { [x + (y + 1)] * (y + 1) } - [(y + 1) * 2] z = [ (x + y + 1) * (y + 1) ] - 2(y + 1) //simplifying brackets z + 2(y + 1) = (y + 1)[x + y + 1] //adding 2(y + 1) to both sides [z + 2(y + 1)]/(y + 1) = x + y + 1 //dividing both sides by (y + 1) { [z + 2(y + 1)]/(y + 1) } - (y + 1) = x //subtracting (y + 1) from both sides [ z/(y + 1) ] + 2 - y - 1 = x // simplifying left hand side Therefore, inverted: x = [ z/(y + 1) ] + 2 - y - 1``````

Wow, this forum is not optimized for posting math

x = [ z/(y + 1) ] + 2 - y - 1
Last edited on
@Shacktar

@ blueberry

Mabey it would help if i gave you what I already have. This is the work I have done. It is not the invere, but it may or may not be close to it. Here it is:

Assume the variables have been interchanged, so that X takes the place of Z, and Z takes the place of X.
`Z = ([(x + ((y + 1) * 2)) / (y + 1)] - (y + 1));`

Mabey this will help, mabey it wont. I spent an hour on it, so it ought to be worth somthing (i hope, lol).
I get,
 `x = [z / (y + 1)] - y + 1`

Edit: Same as Shacktar's
Last edited on
X is going to replace Z. If X = 0, then (0 / (y + 1)) is UNDEFINED. Please make sure that when you post, the variables operate within the pre-defined parameters.

EDIT:
well, even if it isn't, it comes up with that error.

PS. I typed it in right, i even triple checked it after it didn't work. It was Naraku's equation to the letter.
Last edited on
Zero in numerator is not undefined.
Edit: You state y is positive and never zero, so it could never be undefined
Last edited on
Maybe I'm not understanding what you are trying to do. If you are trying to find the original x value then my (and Shacktar's) equation should work, I tried it out on paper and come up with correct values.
You already got the answer, but I wanted to comment on something.

The reason you couldn't solve it is because you chose an excessively complex expression for your function.
Your expression is z = (((x + (y + 1)) * (y + 1)) - ((y + 1) * 2)), where x in [0;26] and y in (0;+inf).
Your y+1 makes the expression more complex than it needs to be. You can simplify by declaring y to be shifted upwards:
z = (x+y)*y - 2*y, where x in [0;26] and y in (1;+inf).
The expression can be simplified further by taking y as a common factor:
z = (x+y-2)*y, where x in [0;26] and y in (1;+inf).
It's now perfectly clear how to invert over x:
z = (x+y-2)*y
z/y = x+y-2
z/y-y+2 = x

At this point I'd like to say that this is a very bad algorithm. Besides the fact that it's not actual encryption, the value of z grows quadratically with the distance to the beginning of the string. I don't see how to fix this without losing the function's bijectivity.

PS: I didn't know there were 27 letters in the English alphabet.
@Helios, i understand your concerns, and trust me when I say that it works. I have written a function specifically to confine any numbers returned by the equations within require parameters.

Also, on another note, it would appear parentheses are needed. That is probably why it isnt working. I'm not copying and pasting, but i am useing your formulas. (x+y) * z is different from x+y*z. you do y*z first in the second one, where in the first one, you do x+y first. I believe you meant to post `(z / y) - (y + 2)`?

Also, i meant 0-25. It was a mistype, i hate math and after working on that equation, i had posted this. I was a bit tired.

I would also like to point out that where 'y' is used, i will ALWAYS use (y + 1). No matter what equation i use. It is so that when x = 0, y does not equal zero.
Last edited on
I know now why i made it (y + 1) for all of em.... crap.
Last edited on
I re-tested my program with the simplest possible equation:

(x + y) = z

inverse:
(z - y) = x
| |
V V

(x - y) = z <---

IT WORKED! :)

So, I think i will take it 1 step at a time. The encryption is extrememly effective with even the simplest equation. If anyone else wants to try their hand at inversing tha equation provided in the first post (provided it is within the parameters specified), be my guest. If you do, I will be ever grateful. lol
Last edited on
@Zhuge holy s**t dude! I never knew that existed! Awsome...
I meant to post what I posted.

 i hate math
Then you can't know as much math as me. Then my question is: why are you trying to correct me?
The expressions shackstar, Zhuge, and I posted are all equivalent. Furthermore, they are the correct solution to the problem you posted. If you're getting incorrect results when plugging them into your code, then the problem you posted isn't equivalent to the problem in your code.

z = (((x + (y + 1)) * (y + 1)) - ((y + 1) * 2))
(Removing redundant parentheses.)
z = (x + y + 1) * (y + 1) - (y + 1) * 2
(Replacing x = z/(y+1)-y+1)
z = ((z / (y + 1) - y + 1) + y + 1) * (y + 1) - (y + 1) * 2
z = (z / (y + 1) + 2) * (y + 1) - (y + 1) * 2
z = z * (y + 1) / (y + 1) + 2 * (y + 1) - (y + 1) * 2
z = z + 2 * (y + 1) - (y + 1) * 2
z = z

 I have written a function specifically to confine any numbers returned by the equations within require parameters.
Oh, I've got to see that.
@ Helios
btw, those parentheses ARE NOT (ABSOLUTELY NOT) redundant. They mean:

X+(y+1)
then (x+(y+1)) * (y + 1)
THEN ((x + (y + 1)) * (y + 1)) - ... ((y + 1) * 2).

((y + 1) * 2) IS NOT THE SAME AS (y + 1 * 2). y + 1 * 2 = y + 2. whereas ((y + 1) * 2) = ((y + 1) * 2).

Parentheses modify the order in which the equation is executed, otherwise we go by this: muliplication/division is done, then addition and subtraction. But parentheses go first.

It is obvious i know more than you. So, wait until you do, and then you can make a post telling me I dont know anything.

If you want to see the function which confines the equation to specified parameters, here it is:

If you don't understand it PLEASE don't post it.
 ``123456789101112131415161718192021222324252627282930313233343536`` ``````void confine_shift(int& shift, int character_type) { if((character_type == 1) || (character_type == 2)) /// letters, so the shift would be the same for upper or lower. { while(shift > 25) ///to stay within the parameters of the vectors set, we use the max character - 1. (25 instead of 26 { ///this is true for the other while statements as well shift = (shift - 26); } while(shift < 0) { shift = (shift + 26); ///but we still have a total amount of characters... } } if(character_type == 3) ///this function directly modifies the values, so no return value is necessary. { while(shift > 32) { shift = (shift - 33); } while(shift < 0) { shift = (shift + 33); } } if(character_type == 4) { while(shift > 9) { shift = (shift - 10); } while(shift < 0) { shift = (shift + 10); } } }``````

I hope you're glad to know I'm not a complete idiot after all.
Last edited on
Pages: 12