#c++ euclidean algorthm // modular inverse help

1 messages · Page 1 of 1 (latest)

undone wave
#

That's not how this works. You need to explain what is your problem here. If it's not too long to explain in DM, it isn't too long to explain it here

gusty wigeon
#

Ok sry

fresh basalt
#

does DM typing go 2x as fast or what?

gusty wigeon
#

i didn’t know dm had word count too like damn

undone wave
#

You can send multiple messages to add all information you need

#

And please read and follow the #📄・posting-guidelines. They will help you ask for help properly.

gusty wigeon
undone wave
#

That's a nice homework. Can you please explain more in details what you need help with exactly? What have you tried? What don't you understand? What prevents you from achieving you goal? ...

gusty wigeon
#

The code is sending sry

#

The one I have, there’s minor mistakes idk how to address

undone wave
#

Ok sorry. We're use to people sending their homework with nothing else.

#

Check the #📄・posting-guidelines. It shows how to properly send code

gusty wigeon
#

can yall see the last 8 lines or should i send them via another file

undone wave
#

We can see them don't worry

gusty wigeon
#

ok thank u sorry if the code itself is messy I lost my mind writing it

gusty wigeon
#

@fresh basalt @undone wave do either of y’all think you could help me 😞

undone wave
#

Again, I recommend that you look at the #📄・posting-guidelines and make sure you post follows them

gusty wigeon
#

From the instructions

naive rivet
#

I think it's really nice to understand the details of RSA,
but seriously, anyone should use a proper crypto library in production,
not cook their own, within reason facepalm 😬

gusty wigeon
gusty wigeon
#

im almost done

undone wave
gusty wigeon
glossy shore
#

Hi @gusty wigeon, Can you review your RelativelyPrime() function ?
You need e value = (p-1)(q-1)

#

I think you are close to solving the assignment; if you review your instructions again; you will find your error right away

#

I hope that helps!

gusty wigeon
gusty wigeon
#

or maybe do relativelyprime(phi);?

glossy shore
#

I think you can set your p and q as random values; and calculate your e = RelativelyPrime(p, q).

#

The e should be RelativelyPrime to (p-1)*(q-1); which is a prime number closer to it!

#

||
std::vector<int> relativelyPrime(int p, int q) {
std::vector<int> result;
phi = (p - 1) * (q - 1);
for (int i = 1; i < phi; ++i) {
if (gcd(i, phi) == 1) {
result.push_back(i);
}
}
return result;
}||

naive rivet
#

I don't think this would work for any p/q values over 32-bit 😬

glossy shore
#

That’s true @naive rivet, but the assignment is just for 32 bit integers

naive rivet
#

so you might need ~8 GiB of RAM (~2 billion * 4 bytes = 32 bits after removing even numbers 😛 )

gusty wigeon
gusty wigeon
#

int phi = (P - 1) * (Q - 1);
int PQ = P * Q;
// e is equivalent to the relative prime of phi: (p-1)*(q-1)
int e = RelativelyPrime (phi);
// d is equal to inverse modular of e and phi
int d = inverse (e, phi);

#

that’s what i submitted