I very well understand the Diffie-Hellman key exchange method, at least I think I do. And I was trying to implement it to try it out.
I went and calculated a very large prime number $p$ about $400$ digits long. And I set $g$ to $5$.
I generated a random secret number $a$, for example : "$42523434$".
The problem I'm facing is when I calculate $g^a \operatorname{mod} p$, $g^a$ in particular, it seems to take my computer forever to calculate it, so it seems to be impractical to give $a$ such a number so I went for a smaller number (a five digit number) which takes about a second or two to calculate.
So now we have $A=g^a \operatorname{mod} p$, with the eavesdropper knowing $g$, $p$, and $A$.
But wouldn't it be possible to brute force $a$ by trying all $100000$ combinations until what he calculates matches $A$ which wouldn't take him that long if he good computing powers? A solution to this would be increasing $a$ but increasing $a$ would make the exchange take so long that it wouldn't be a good method to exchange the keys.
Edit:
We can compute g^a mod p using such a program:
for x in range(1,100000):
if(((g**x)%p)==A):
print x
pow(g,a,p)which is very fast. Try it! – Henno Brandsma Aug 15 '17 at 19:34