How can I improve RSA d-key generation in c++? [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm writing a c++ implementation of RSA algorithm. It work but It takes hours to calcultate d key. Any help to make it work faster would be awesome.
unsigned __int64 calcolo_d(const unsigned __int64 eulero, const unsigned __int64 e) {
register unsigned __int64 d = 0;
while (!((e*d) % eulero == 1))
{
++d;
}
return d; }

What you are computing is the modular inverse of e mod eulero. This can be done efficiently via the extended euclidean algorithm.
There are many, many implementations out there to choose from.

Related

how do i write a code in c++ to find the maximum of 3 integer no. using function overloading [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 days ago.
Improve this question
using concept of function overloading making a program to find maximum of 3 integer no.
I don't understand how do i show overload a function that is taking 3 integers only
You can use the fact that the maximum of three numbers is the bigger of 1 of the numbers and the maximum of the other two.
int maximum(int a,int b) { return /* ... */ }
int maximum(int a,int b, int c) { return /* ... */ }

What is different between typedef with invariant and nomal typedef [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I came Across a line of code in an example that I can not understand how is it being utilized and what benefit on using this type of declaration.
following in the part of code extracted from that example
const uint16_t cycles = 8;
typedef uint8_t invariant(value < cycles) TIndex_t;
struct TData
{
uint16_t readings[cycles];
volatile uint16_t sum;
TIndex_t index;
void addReading(uint16_t arg)
writes(*this; volatile)
pre(invar())
pre(arg <= 1023)
post(invar())
{
sum = sum - readings[index] + arg;
readings[index] = arg;
index = static_cast<TIndex_t>((index + 1u) % cycles);
}
void init()
writes(*this; volatile)
post(invar());
ghost(
bool invar() const
returns((forall r in readings :- r <= 1023) && sum == + over readings);
)
This is GNU C++ the struct is a kind of class definition as I can tell
This is not pure C++.
It looks like somebody has written either a compiler extension or a series of macros to allow the specification of pre- and post-conditions for a block of code.
You're going to have to ask that person.
(As an aside, this is why just "extracting code" is often insufficient for understanding; you need to observe the full context in order to know what's going on. In this case, the context includes definitions and/or documentation found elsewhere and not included in your question.)

Calculate the log base n with Shift left or Shift right [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a little problem.
Who knows how we can calculate the log
base n with Shift_L or Shift_R?
for example: for n=2 we had this solution:
int log(int n){
int res = 0;
while((n>>=1))
res++;
return res;
}
You don't seem to want the logarithm for a base b, but the largest integer n so that n <= log_b(x). If that's the case, the following function should serve your needs:
int intlog(double base, double x) {
return (int)(log(x) / log(base));
}
well this is rather a math problem instead of an actuall programming problem, if i understand your problem correctly:
log_2 (x) = log_a (x) / log_a (2) where a can be any base.
Therefore you could use the math.h's function log(double)
double res = log(x)/log(2);

number repeated twice in the variable [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
#include <iostream>
using namespace std;
int main()
{
int a = 101;
return 0;
}
Question : How do I know that the number (1) is repeated twice in the variable
If you look at the code, you will see that the number 101 is assigned to the variable a and that number has the digit 1 twice in its decimal representation. So direct inspection is the way to go. I wouldn't even write the code for such a trivial requirement.
Use modulus 10 and division 10 to find it. Rough idea is,
while( a > 0 )
{
if( a % 10 == 1 )count_one++;
a=a/10;
}

Zero-crossing Sign function [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have written a Sign function and am wondering whether it is correct or not (Stupid question to ask, I know!) I'm just interested in knowing whether this is the best method to solve this particular task:
template<typename T>
T sign(T n)
{
if(n < 0) return -1;
if(n > 0) return 1;
return 0;
}
Would this give accurate enough results for large datasets? Can anyone see a problem, that I haven't come across that may arise when putting this into a real-life context?
Thanks
I would change return 0; to return n;. If n is NaN, sign should return NaN, not 0.