How do I calculate e, d and N based on raw and encrypted message in RSA? I've got raw and encrypted message, which contains only numbers. For example:

Message: 32016550980634121428089400169, encrypted: 35682226122303060179704449482


I've written such an algorithm:

d = 1
n = enc+1

for k in tqdm(range(1, 10**7)):
  e = k * n
  if pow(msg, e, n) == enc:
      print("WE")


But looks like I've mistaken somewhere. How do I make it work?
In general, you can't do that.  You have one equation and two unknowns (not three, since $d$ is uniquely determined by $n$ and $e$, even if actually computing it without knowing the factors of $n$ is difficult), so the solution will in general not be unique.

Of course, you could guess that $e$ might be one of the common values (e.g. 3 or 65537) and try to solve for $n$.  But that only works if you guess the right $e$.  And even if you do manage to determine $n$ this way, you'll still have to factor $n$ to be able to calculate $d$.



As for your code, it has many mistakes.  I have no idea why you're setting n = enc+1 or e = k * n, for example — neither of those make any sense whatsoever.  It looks as if you may be missing some fairly basic knowledge of either Python programming or the mathematics behind RSA.

As I can't really tell from just your code what it is that you might be missing, all I can suggest is finding some good tutorials and revising the basics.  And maybe ask for help from your instructor / TA / tutor / etc., if you have one available.