-7

At the moment i have this formula: 13^2 mod 5 = 4

I want to calculate back the 2 here like:

13^X mod 5 = 4

X = ?

I found several formula's/codes to do this online but i didn't find any which do it with a ^ symbol.

Would appreciate some help

My client received everything besides the TEST_PRIVATE so i want to calculate that.

This is the code i use (server sided) (This is the encryption, not the decryption)

string TEST_GENERATED = "13";
string TEST_PRIVATE = "2";
string TEST_PRIME = "5";
BigIntegerTEST TESTMOD_1 = new BigIntegerTEST(TEST_GENERATED, 10);
BigIntegerTEST TESTMOD_2 = new BigIntegerTEST(TEST_PRIVATE, 10);
BigIntegerTEST TESTMOD_3 = new BigIntegerTEST(TEST_PRIME, 10);
BigIntegerTEST TESTMOD_4 = TESTMOD_1.modPow(TESTMOD_2, TESTMOD_3);

So basicly i want to reverse TESTMOD_4 to TESTMOD_2 By only using TESTMOD_4, TESTMOD_3 and TESTMOD_1

(I know modPow usually has 3 parameters i'm using a special class for it)

TDLR; Working example:

(6 + 7) MOD 10 = 3

(3 - 6 + 10) MOD 10 = 7

This is the main result i want: ( I want to retrieve the 7)

(6^7) MOD 10 = 6

? = 7

Vargo
  • 308
  • 2
  • 13
Mika SD
  • 1
  • 1
  • 4
  • What's a `BigIntegerTEST`? – canton7 Apr 24 '19 at 20:06
  • Its just a class to hold really big numer value's – Mika SD Apr 24 '19 at 20:08
  • 3
    Judging by your result of `4`, you take the `^` to be the [exponent operator](https://stackoverflow.com/a/3034607/11683). In C# it is the [XOR operator](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/boolean-logical-operators#logical-exclusive-or-operator-). In either case you cannot possibly calculate back to `2` because reversing `mod` will give you infinitely many possible numbers all of which are 4 modulo 5. – GSerg Apr 24 '19 at 20:09
  • 5
    I think either you ask this as an algorithms question (in which case it shouldn't have the C# tag on it or C# code in it), or if you're asking a C# question then you need give an [mcve] – canton7 Apr 24 '19 at 20:09
  • I can't figure out what this question is asking. Can you clarify it? – Eric Lippert Apr 24 '19 at 21:46
  • @EricLippert The code TESTMOD_1.modPow(TESTMOD_2, TESTMOD_3) outputs 4, and with the numbers. And in my scenario i only have the numbers 4,5 and 13 and i need to calculate back to the 2 – Mika SD Apr 24 '19 at 21:50
  • OK, but your question appears to be entirely about something having to do with the `^` operator. I don't understand what you're asking when you say "using an `^` sign" or "I didn't find any with the `^` symbol". You seem to be confused about the meaning of `^` in C#; it is not exponentiation. C# has no exponent operator. If your question is not about the operator, then edit the post and title to stop referring to the operator, and **ask the question that you actually need an answer to**. – Eric Lippert Apr 24 '19 at 21:52
  • @EricLippert i have a calcuation: 13^2 MOD 5 = 4, 13^2 = 169 all i need is to calculate the 4 back to the 2 (or 169) with only the numbers 13, 5 and 5. (i mentioned the ^ because i saw a few examples where people undertook 13+2 instead of 13^2) – Mika SD Apr 24 '19 at 21:56
  • 2
    OK, so if your question is "how do I do this computation?" I again do not see what you're asking. You say that you've found numerous articles on the formula for solving this problem: **read those articles and implement the code**. Again, **what question are you asking here?** This isn't a service for doing your homework for you. – Eric Lippert Apr 24 '19 at 21:58
  • 3
    This formula is very similar to RSA, and the operation you are looking for is called a "discrete logarithm". For small values of a given modulus p (eg: 5) you can loop through all possible exponents less than p. For large values, there may be more efficient algorithms depending on the characteristics of p. See for example https://en.wikipedia.org/wiki/Pohlig%E2%80%93Hellman_algorithm. If, however, the encryption method is in fact RSA then let us know if you find a feasible algorithm better than trying them all: you will have significantly advanced humanity's understanding of mathematics. – Tadmas Apr 25 '19 at 00:16
  • 2
    As Tadmas notes, if you're trying to solve this problem in general efficiently, you are asking for an algorithm not known to humans; *it was chosen as the basis of an encryption algorithm because it is hard to solve*; if we knew of an efficient algorithm for that problem, we would not have chosen it as the basis of encryption! – Eric Lippert Apr 25 '19 at 00:19
  • @Tadmas you are correct, in my example im using quite small values. Altough in real use i will use far larger strings (wich is why bruteforcing is terrible like that) – Mika SD Apr 25 '19 at 01:44

1 Answers1

-2

it is here and much simple like this function:

public double DoCalc(double Number1, double Number2, double Number3)
    { return (Math.Pow(Number1, Number2)) % Number3; }

Then call it from the button click event, like this:

private void btmDoCalc_Click(object sender, EventArgs e)
    {
        // Here show it up in message box directly.
        MessageBox.Show("DoCalc= " + DoCalc(13, 2, 5).ToString());

        // Here assign it to some double variables.
        double N1 = 0, N2 = 0, N3 = 0;

        N1 = DoCalc(13, 2, 4);
        N2 = DoCalc(13, 2, 3);
        N3 = DoCalc(13, 2, 2);
        MessageBox.Show("DoCalc= " + N1);
        MessageBox.Show("DoCalc= " + N2);
        MessageBox.Show("DoCalc= " + N3);
    }

Here is some more images for the results. enter image description here

I hope this answers your questions ^_^

MAMPRO
  • 69
  • 6
  • The OP is asking how to find `Number2` given `Number1`, `Number3` and the result of `DoCalc`. – GSerg Apr 24 '19 at 21:33
  • Thats not what i ment like the code you sent (DoCalc(13, 2, 5)) outputs 4, and with the numbers. And in my scenario i only have the numbers 4,5 and 13 and i need to calculate back to the 2 – Mika SD Apr 24 '19 at 21:36
  • Now It is clear, I got your point, trying to give a solution. – MAMPRO Apr 24 '19 at 21:42