How do I find the 'd' in RSA (euclidean algorithm)? - rsa

In this video:
https://www.youtube.com/watch?v=mf7x9IiJndY
At 13:25 he shows that I should do the next row:
7 X d = 1(mod 160)
I didnt understook how did he get the 'd' from it?
He said somthing aboud euclidean algorithem. But all "euclidean algorithem" said is what the "GCD" of some two numbers..
After some reserch I found "extended algorithm" too, But I dont see how does this algorithem can help me too.
What are the steps here to find the 'd' and what is connection to "euclidean algorithm"?

Related

Neighbor of 10 wrong answer?

I am getting wrong answer to the following problem:
Given a non-negative number n, print True if n is within 2 of a multiple of 10, else print false. For example 22 is within 2 of a multiple of 10 (the multiple here is 20) and 23 is not within 2 of a multiple of 10 (it is within 3 of multiple 20).
Do you see anything wrong? Because certainly I do not.
This is my code:
closest_multiple = round(num/10)*10
return (abs(closest_multiple - num) <= 2)
Thanks to the comment of #user202729, the answer is:
apparently it has to do with the accuracy of the floating point representation, which applies to most languages. Perhaps is not that good to work with fp numbers then in this case... 9999999999999999.0 in fp64 would be 10000000000000000

How to get a new solution with high probability from previously found, incomplete solutions with different probabilities?

I am working on a AI algorithm. first when program runs a random solution is generated from which ,in first iteration of the program 10 solution vectors are created, by analyzing these solutions we could give each of them a probability ( highest , second highest, third highest and so on) towards the optimal solution , for the second input of the program I want it to be a vector (possible solution) obtained from those 10 vectors previously found. But i need the vector solution to consider all the previous solutions with a different impact depending on their probability ...
i.e A=[4.7 ,5.6, 3.5,9 ] b=[-7.9 ,8 ,-2.8 ,4.6] c=[7 ,9.7 , 4,6,3.9] ......
i used mean in my program
NextPossibleSolution = mean(([A;B;C;]))
But do you think mean is the right move ? i don't think because all the solution contributes equal to Next Possible Solution (next input) regardless of their likelihood ... Please if there is a method formula or anything , Let me know that ... I really need it badly .... A Billion Thanks

SAGE How do I find e in this equation using sagemath?

The question asks us to solve for x in the given equation c' = x^e mod N, given the fact that we already know c', e , mod N. I looked into my tutorial, bu they only gave us a way to get e, but not for x.
I have manually tried to solve it and got the equation:
log c' = e log x mod N
but I don't know how to put in in Sage Math.
This is from the tutorial to find e:
discrete_log (c',Mod(x,N))
The question is really asking how to find an e-th root of c' modulo N.
Say for example one wants to solve 12 = x^99 modulo 347.
This amounts to finding a 99-th root of 12 modulo 347.
Just set up the ring of integers modulo 347,
sage: A = Zmod(347)
sage: A
Ring of integers modulo 347
give a name to the element 12 in that ring,
sage: a = A(12)
and ask Sage for a 99-th root of this element:
sage: a.nth_root(99)
241
Check that this answers the question:
sage: A(241)^99
12
sage: pow(241, 99, 347)
12
sage: power_mod(241, 99, 347)
12
Samuel's answer is far more comprehensive than this, but if you are looking for a really quick fix, you could use this (naive) function for small moduli:
sage: solve_mod(x^99==12, 347)
[(241,)]

network security- cryptography

I was solving a RSA problem and facing difficulty to compute d
plz help me with this
given p-971, q-52
Ø(n) - 506340
gcd(Ø(n),e) = 1 1< e < Ø(n)
therefore gcd(506340, 83) = 1
e= 83 .
e * d mod Ø(n) = 1
i want to compute d , i have all the info
can u help me how to computer d from this.
(83 * d) mod 506340 = 1
i am a little wean in maths so i am having difficulties finding d from the above equation.
Your value for q is not prime 52=2^2 * 13. Therefore you cannot find d because the maths for calculating this relies upon the fact the both p and q are prime.
I suggest working your way through the examples given here http://en.wikipedia.org/wiki/RSA_%28cryptosystem%29
Normally, I would hesitate to suggest a wikipedia link such as that, but I found it very useful as a preliminary source when doing a project on RSA as part of my degree.
You will need to be quite competent at modular arithmetic to get to grips with how RSA works. If you want to understand how to find d you will need to learn to find the Modular multiplicative inverse - just google this, I didn't come across anything incorrect when doing so myself.
Good luck.
A worked example
Let's take p=11, q=5. In reality you would use very large primes but we are going to be doing this by hand to we want smaller numbers. Keep both of these private.
Now we need n, which is given as n=pq and so in our case n=55. This needs to be made public.
The next item we need is the totient of n. This is simply phi(n)=(p-1)(q-1) so for our example phi(n)=40. Keep this private.
Now you calculate the encryption exponent, e. Defined such that 1<e<phi(n) and gcd(e,phi(n))=1. There are nearly always many possible different values of e - just pick one (in a real application your choice would be determined by additional factors - different choices of e make the algorithm easier/harder to crack). In this example we will choose e=7. This needs to be made public.
Finally, the last item to be calculated is d, the decryption exponent. To calculate d we must solve the equation ed mod phi(n) = 1. This is most commonly calculated using the Extended Euclidean Algorithm. This algorithm solves the equation phi(n)x+ed=1 subject to 1<d<phi(n), where x is an unknown multiplicative factor - which is identical to writing the previous equation without using mod. In our particular example, solving this leads to d=23. This should be kept private.
Then your public key is: n=55, e=7
and your private key is: n=55, d=23
To see the workthrough of the Extended Euclidean Algorithm check out this youtube video https://www.youtube.com/watch?v=kYasb426Yjk. The values used in that video are the same as the ones used here.
RSA is complicated and the mathematics gets very involved. Try solving a couple of examples with small values of p and q until you are comfortable with the method before attempting a problem with large values.

Matlab: 'Matrix dimensions must agree' less than operator (<)?

A quick question because i fear there may already be an answer (although i cant find it)
i am getting the error: Matrix dimensions must agree.
because i am useing '<'
now with all the other operators there is a way around this either by putting '.' infront or by using a different formula. So what do people do about the less than operator????
i don't see why the greater than or equal to (>=) works but yet less than does not!?
am i being stupid and missed something really obvious??
code snippet
matrix 1 represents an array of 16 numbers
matrix 2 can represents anywhere between 10 and 20 numbers
idx = (matrix2 >= matrix1 * 0.1 & matrix2 < matrix1 * 1.5);
any help guidance or advice on the topic would be much appreciated! thank you!
EDIT
i know the matrices are different sizes but is there a way to use less then with different size arrays? as im not bothered about the size of the array but the numbers within
If you want to compare parts of matrices, like M(1:3,10:12)>A(5:7,1:3), you, probably, have to use the function squeeze():
squeeze(M(1:3,10:12))>squeeze(A(5:7,1:3))
This function remotes singleton dimensions and everything works fine after.