inlinelonglong cryption(longlong msg, longlong n, int DorE) //Encryption with two keys
{
longlong msgcl = 1;
for(int i = 0; i < DorE; ++i)
{
msgcl = msgcl * msg % n;
}
msgcl = msgcl % n;
return msgcl;
}
It replicates the formula C = P^e % n where 'msg' is P, e is 'DorE' and n is 'n'. C is the return parameter.
Yes this is for encryption. I've noticed that the bigger the numbers, the slower it gets. So slow that it takes more than a minute to fully break down a number in the millions.
Sadly I do not know of any better algorithms or assembly to make it faster. If anyone knows how to make it faster please let me know
Have you been getting the right answers with your code? It looks wrong to me.
1 2 3 4 5 6 7 8 9
longlong cryption ( constlonglong msg, constlonglong n, constint DorE ) // Encryption with two keys.
{
longlong Ptte = msg; // Ptte = P to the e
for ( int i = 0; i < DorE - 1; ++i )
Ptte *= msg; // ( a = a * b ) == ( a *= b )
return Ptte % n;
}
Inlining a function doesn't really do much. If you have a good compiler it will be able to figure that out itself.
Making the variables you pass constant could help your compiler speed things up, possibly.
You don't need to calculate and store Ptte % n before returning it, you can just return it.
I don't know why you need long long's, but if you don't need them, smaller variables will be faster (on 32bit computers).