Finding the value based on the value of the remainder

  • Thread starter Thread starter Vital
  • Start date Start date
  • Tags Tags
    Remainder Value
Click For Summary
The discussion revolves around solving the equation (y - z + i) mod m = x - z, where y is the unknown value to be determined. The user is attempting to reverse-engineer the equation to find y given known values for x, z, and i. It is established that multiple values of y can satisfy the equation depending on the integer k, leading to the conclusion that without additional constraints, a unique solution for y cannot be found. However, the user notes that y must fall within a specific range (97 to 122), which could help narrow down possible solutions. The conversation emphasizes the need for an algorithm to systematically solve such equations in a programming context.
  • #31
Vital said:
Well... [19/26 , 44/26]
Isn't k an integer?
Edit:
@Vital, what integers are in that range?
 
Last edited:
Physics news on Phys.org
  • #32
Let's look at the initial equation again.

We have (y − 97 + i) mod 26 = x − 97

For encrypting, you start with a y value such that 97 ≤ y ≤ 122 .

This gives 0 ≤ (y − 97) ≤ 25 .

To this we add i, then perform the mod 26 operation so that values of x fall into the same range of values as do values of y.

Specifically, 0 ≤ (x − 97) ≤ 25 and thus 97 ≤ x ≤ 122 .

So you could say that it's that i value which which makes inverting this expression a bit tricky.

The quantity, (y − 97 + i), falls in the range of values, [ i , 25 + i ] .

The mod 26 operation preserves any of these values falling in the [ 0 , 25 ] interval. Any other values are put into the [ 0 , 25 ] interval, by adding or subtracting appropriate multiples of 26.

Consider the following idea:

If you were to subtract i from (y − 97 + i), then of course you have (y − 97)

Similarly, if you subtract i from (x − 97). that gives (x − 97 − i). The values for this fall in the interval [ −i , 25 − i ]. Applying the mod 26 operation to this should give the result you need to obtain (y − 97) .
.
 
  • #33
SammyS said:
Let's look at the initial equation again.

We have (y − 97 + i) mod 26 = x − 97

For encrypting, you start with a y value such that 97 ≤ y ≤ 122 .

This gives 0 ≤ (y − 97) ≤ 25 .

To this we add i, then perform the mod 26 operation so that values of x fall into the same range of values as do values of y.

Specifically, 0 ≤ (x − 97) ≤ 25 and thus 97 ≤ x ≤ 122 .

So you could say that it's that i value which which makes inverting this expression a bit tricky.

The quantity, (y − 97 + i), falls in the range of values, [ i , 25 + i ] .

The mod 26 operation preserves any of these values falling in the [ 0 , 25 ] interval. Any other values are put into the [ 0 , 25 ] interval, by adding or subtracting appropriate multiples of 26.

Consider the following idea:

If you were to subtract i from (y − 97 + i), then of course you have (y − 97)

Similarly, if you subtract i from (x − 97). that gives (x − 97 − i). The values for this fall in the interval [ −i , 25 − i ]. Applying the mod 26 operation to this should give the result you need to obtain (y − 97) .
.

Unfortunately, no. If I understood you correctly, then the expression should be:
(x - 97 - i)%26 + 97 = y
But this is the expression I came up with a week ago, when I tried to solve the problem. It doesn't work, and produces an inappropriate result.
 
  • #34
Vital said:
Unfortunately, no. If I understood you correctly, then the expression should be:
(x – 97 – i)%26 + 97 = y
But this is the expression I came up with a week ago, when I tried to solve the problem. It doesn't work, and produces an inappropriate result.
If the % operator does indeed give the remainder,then that should give correct results.

Try this on your test cases.
Vital said:
Let's say I have 3 initial equations:

(1) (99 – 97 + 17) mod 26 + 97 = x; x = 116
(2) (104 – 97 + 20) mod 26 + 97 = x; x = 98
(3) (105 – 97 + 18) mod 26 + 97 = x; x = 97

The next step is to do the reverse, namely finding Y:
(1) (Y – 97 + 17) mod 26 + 97 = 116
(2) (Y – 97 + 20) mod 26 + 97 = 98
(3) (Y – 97 + 18) mod 26 + 97 = 97
Use: y = (x – 97 – i)%26 + 97

(1): x = 116, i = 17, should give y = 99 .
y = [(116 – 97 – 17)%26] + 97 = [ 2 % 26] + 97 = 2 + 97 = 99​
(2) x = 98, i = 20, should give y = 104
y = [(98 – 97 – 20)%26] + 97 = [ (–19) % 26] + 97 = 7 + 97 = 104​
(3) x = 97, i = 18, should give y = 105
y = [(97 – 97 – 18)%26] + 97 = [ (–18) % 26] + 97 = 8 + 97 = 105​

It appears to work just fine.
 
  • #35
SammyS said:
If the % operator does indeed give the remainder,then that should give correct results.

Try this on your test cases.

Use: y = (x – 97 – i)%26 + 97

(1): x = 116, i = 17, should give y = 99 .
y = [(116 – 97 – 17)%26] + 97 = [ 2 % 26] + 97 = 2 + 97 = 99​
(2) x = 98, i = 20, should give y = 104
y = [(98 – 97 – 20)%26] + 97 = [ (–19) % 26] + 97 = 7 + 97 = 104​
(3) x = 97, i = 18, should give y = 105
y = [(97 – 97 – 18)%26] + 97 = [ (–18) % 26] + 97 = 8 + 97 = 105​

It appears to work just fine.
Yes, I thought so also when I initially came up with this same equation, so I thought that my math is completely incorrect, and I started asking for help, because the program doesn't compute it this way somehow, and I get completely different results. Well, maybe it's some problem with computing the remainder when the quotient is negative. It might be the case. I have to investigate that further.
Thank you so much for your huge patience and your help!
 
  • #36
Vital said:
Yes, I thought so also when I initially came up with this same equation, so I thought that my math is completely incorrect, and I started asking for help, because the program doesn't compute it this way somehow, and I get completely different results. Well, maybe it's some problem with computing the remainder when the quotient is negative. It might be the case. I have to investigate that further.
Thank you so much for your huge patience and your help!
Yes. I'm not sure about that "%" operation.

It appears that the values you are using for " i " also fall in the [ 0, 25 ] interval. If that's the case, and the problem is with computing the remainder for negatives, then adding 26 (or any positive multiple of 26), before applying the "%" operation should solve the problem.
 
  • #37
SammyS said:
Yes. I'm not sure about that "%" operation.

It appears that the values you are using for " i " also fall in the [ 0, 25 ] interval. If that's the case, and the problem is with computing the remainder for negatives, then adding 26 (or any positive multiple of 26), before applying the "%" operation should solve the problem.
Thank you! I have to try this. There is a good thing about all this; I am glad that I am not that bad in the most basic math; I was so desperate that my equation didn't work, and I couldn't understand why, so I came here, and "tortured" you while the problem was in the way the program treats negatives. :-) Again, thank you very much for your help, and I will try the +26 trick. :-)

EDIT: I just did - added 26 to the equation, and, viola, it does the job! :) What a relief! ) Thank you so much! Now I need to understand my mistake in programming - it's not right that the program can't compute such remainders. :-)
 
  • #38
Vital said:
Thank you! I have to try this. There is a good thing about all this; I am glad that I am not that bad in the most basic math; I was so desperate that my equation didn't work, and I couldn't understand why, so I came here, and "tortured" you while the problem was in the way the program treats negatives. :-) Again, thank you very much for your help, and I will try the +26 trick. :-)

EDIT: I just did - added 26 to the equation, and, viola, it does the job! :) What a relief! ) Thank you so much! Now I need to understand my mistake in programming - it's not right that the program can't compute such remainders. :-)
Not tortured too much ! (Most of any torture there was, I inflicted upon myself.)

I'm glad to see that you at least got it to work, even if that's with a "trick".

What programming language?
The main issue is with the details of how the % operation is defined.
 
  • #39
SammyS said:
Not tortured too much ! (Most of any torture there was, I inflicted upon myself.)

I'm glad to see that you at least got it to work, even if that's with a "trick".

What programming language?
The main issue is with the details of how the % operation is defined.
It's C. :-) And it might be some issues with negatives, some nuances I still have to learn. But I can't discuss the programming itself, unfortunately, because I promised to the person who helps me with C, not to seek for any help when it comes to programming; so I can't break my promise. :-)
 
  • Like
Likes SammyS
  • #40
SammyS said:
Yes. I'm not sure about that "%" operation.
It has always annoyed me the way % works with negatives in C. Clearly not specified by a mathematician.
 
  • Like
Likes SammyS

Similar threads

Replies
6
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
3
Views
2K
Replies
11
Views
2K
Replies
21
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
Replies
14
Views
2K