How to calculate mod inverse
$begingroup$
Given a number set of integers $mathbb{Z}$, how do I find the inverse of a given number?
I am trying to test an algorithm to extract the $k$ and $x$ values from the Elgamal Signature algorithm given that $k$ is repeated.
What I have is
$k$ congruent to $(m_1 - m_2)times(s_1 - s_2)^{-1} mod p - 1$
given $k$ is used twice.
I am not sure how to calculate the mod inverse though?
_
Is the above formula the same thing as $((m_1 - m_2) mod p -1 times (s_1 - s_2)^{-1} mod p -1) mod p -1$
I am not sure if it is any different since I am doing a mod inverse.
PS. I am a programmer, not a mathematician so please elaborate.
number-theory
$endgroup$
|
show 3 more comments
$begingroup$
Given a number set of integers $mathbb{Z}$, how do I find the inverse of a given number?
I am trying to test an algorithm to extract the $k$ and $x$ values from the Elgamal Signature algorithm given that $k$ is repeated.
What I have is
$k$ congruent to $(m_1 - m_2)times(s_1 - s_2)^{-1} mod p - 1$
given $k$ is used twice.
I am not sure how to calculate the mod inverse though?
_
Is the above formula the same thing as $((m_1 - m_2) mod p -1 times (s_1 - s_2)^{-1} mod p -1) mod p -1$
I am not sure if it is any different since I am doing a mod inverse.
PS. I am a programmer, not a mathematician so please elaborate.
number-theory
$endgroup$
2
$begingroup$
Use the Extended Euclidean Algorithm, e.g. see here
$endgroup$
– Bill Dubuque
Nov 19 '18 at 20:36
$begingroup$
I know how to find a mod inverse. But if I have a number A*B^-1 mod p-1 is that equivalent to A mod p-1 * B mod p-1 mod p-1. That is what I found online but I wasn't sure.
$endgroup$
– User
Nov 19 '18 at 20:39
$begingroup$
$ab$ is invertible $iff a,b$ are invertible $iff a,b,$ are coprime to the modulus. When so we have $(ab)^{-1}equiv b^{-1}a^{-1},$ by $ b^{-1}a^{-1} (ab) equiv b^{-1}(a^{-1}a)bequiv b^{-1}b equiv 1 $ (inverses are always unique)
$endgroup$
– Bill Dubuque
Nov 19 '18 at 20:58
$begingroup$
So what if I have a number * an inverse mod p -1. How would I break that down?
$endgroup$
– User
Nov 19 '18 at 21:01
$begingroup$
Calculate the inverse then modular_multiply the two as you would any pair of (modular) integers - using the mod prodcut rule
$endgroup$
– Bill Dubuque
Nov 19 '18 at 21:05
|
show 3 more comments
$begingroup$
Given a number set of integers $mathbb{Z}$, how do I find the inverse of a given number?
I am trying to test an algorithm to extract the $k$ and $x$ values from the Elgamal Signature algorithm given that $k$ is repeated.
What I have is
$k$ congruent to $(m_1 - m_2)times(s_1 - s_2)^{-1} mod p - 1$
given $k$ is used twice.
I am not sure how to calculate the mod inverse though?
_
Is the above formula the same thing as $((m_1 - m_2) mod p -1 times (s_1 - s_2)^{-1} mod p -1) mod p -1$
I am not sure if it is any different since I am doing a mod inverse.
PS. I am a programmer, not a mathematician so please elaborate.
number-theory
$endgroup$
Given a number set of integers $mathbb{Z}$, how do I find the inverse of a given number?
I am trying to test an algorithm to extract the $k$ and $x$ values from the Elgamal Signature algorithm given that $k$ is repeated.
What I have is
$k$ congruent to $(m_1 - m_2)times(s_1 - s_2)^{-1} mod p - 1$
given $k$ is used twice.
I am not sure how to calculate the mod inverse though?
_
Is the above formula the same thing as $((m_1 - m_2) mod p -1 times (s_1 - s_2)^{-1} mod p -1) mod p -1$
I am not sure if it is any different since I am doing a mod inverse.
PS. I am a programmer, not a mathematician so please elaborate.
number-theory
number-theory
edited Nov 19 '18 at 21:02
Mason
1,9651530
1,9651530
asked Nov 19 '18 at 20:29
UserUser
11
11
2
$begingroup$
Use the Extended Euclidean Algorithm, e.g. see here
$endgroup$
– Bill Dubuque
Nov 19 '18 at 20:36
$begingroup$
I know how to find a mod inverse. But if I have a number A*B^-1 mod p-1 is that equivalent to A mod p-1 * B mod p-1 mod p-1. That is what I found online but I wasn't sure.
$endgroup$
– User
Nov 19 '18 at 20:39
$begingroup$
$ab$ is invertible $iff a,b$ are invertible $iff a,b,$ are coprime to the modulus. When so we have $(ab)^{-1}equiv b^{-1}a^{-1},$ by $ b^{-1}a^{-1} (ab) equiv b^{-1}(a^{-1}a)bequiv b^{-1}b equiv 1 $ (inverses are always unique)
$endgroup$
– Bill Dubuque
Nov 19 '18 at 20:58
$begingroup$
So what if I have a number * an inverse mod p -1. How would I break that down?
$endgroup$
– User
Nov 19 '18 at 21:01
$begingroup$
Calculate the inverse then modular_multiply the two as you would any pair of (modular) integers - using the mod prodcut rule
$endgroup$
– Bill Dubuque
Nov 19 '18 at 21:05
|
show 3 more comments
2
$begingroup$
Use the Extended Euclidean Algorithm, e.g. see here
$endgroup$
– Bill Dubuque
Nov 19 '18 at 20:36
$begingroup$
I know how to find a mod inverse. But if I have a number A*B^-1 mod p-1 is that equivalent to A mod p-1 * B mod p-1 mod p-1. That is what I found online but I wasn't sure.
$endgroup$
– User
Nov 19 '18 at 20:39
$begingroup$
$ab$ is invertible $iff a,b$ are invertible $iff a,b,$ are coprime to the modulus. When so we have $(ab)^{-1}equiv b^{-1}a^{-1},$ by $ b^{-1}a^{-1} (ab) equiv b^{-1}(a^{-1}a)bequiv b^{-1}b equiv 1 $ (inverses are always unique)
$endgroup$
– Bill Dubuque
Nov 19 '18 at 20:58
$begingroup$
So what if I have a number * an inverse mod p -1. How would I break that down?
$endgroup$
– User
Nov 19 '18 at 21:01
$begingroup$
Calculate the inverse then modular_multiply the two as you would any pair of (modular) integers - using the mod prodcut rule
$endgroup$
– Bill Dubuque
Nov 19 '18 at 21:05
2
2
$begingroup$
Use the Extended Euclidean Algorithm, e.g. see here
$endgroup$
– Bill Dubuque
Nov 19 '18 at 20:36
$begingroup$
Use the Extended Euclidean Algorithm, e.g. see here
$endgroup$
– Bill Dubuque
Nov 19 '18 at 20:36
$begingroup$
I know how to find a mod inverse. But if I have a number A*B^-1 mod p-1 is that equivalent to A mod p-1 * B mod p-1 mod p-1. That is what I found online but I wasn't sure.
$endgroup$
– User
Nov 19 '18 at 20:39
$begingroup$
I know how to find a mod inverse. But if I have a number A*B^-1 mod p-1 is that equivalent to A mod p-1 * B mod p-1 mod p-1. That is what I found online but I wasn't sure.
$endgroup$
– User
Nov 19 '18 at 20:39
$begingroup$
$ab$ is invertible $iff a,b$ are invertible $iff a,b,$ are coprime to the modulus. When so we have $(ab)^{-1}equiv b^{-1}a^{-1},$ by $ b^{-1}a^{-1} (ab) equiv b^{-1}(a^{-1}a)bequiv b^{-1}b equiv 1 $ (inverses are always unique)
$endgroup$
– Bill Dubuque
Nov 19 '18 at 20:58
$begingroup$
$ab$ is invertible $iff a,b$ are invertible $iff a,b,$ are coprime to the modulus. When so we have $(ab)^{-1}equiv b^{-1}a^{-1},$ by $ b^{-1}a^{-1} (ab) equiv b^{-1}(a^{-1}a)bequiv b^{-1}b equiv 1 $ (inverses are always unique)
$endgroup$
– Bill Dubuque
Nov 19 '18 at 20:58
$begingroup$
So what if I have a number * an inverse mod p -1. How would I break that down?
$endgroup$
– User
Nov 19 '18 at 21:01
$begingroup$
So what if I have a number * an inverse mod p -1. How would I break that down?
$endgroup$
– User
Nov 19 '18 at 21:01
$begingroup$
Calculate the inverse then modular_multiply the two as you would any pair of (modular) integers - using the mod prodcut rule
$endgroup$
– Bill Dubuque
Nov 19 '18 at 21:05
$begingroup$
Calculate the inverse then modular_multiply the two as you would any pair of (modular) integers - using the mod prodcut rule
$endgroup$
– Bill Dubuque
Nov 19 '18 at 21:05
|
show 3 more comments
1 Answer
1
active
oldest
votes
$begingroup$
Yes, the two formulas you wrote in the question give the same output.
More generally, as Bill Dubuque points out in the comments, you can usually just take mods at each step, instead of doing the whole computation and then modding at the end. However, exponentiation is a notable exception; you can reduce the base but generally not the exponent
$$ a^k bmod n quad=quad (abmod n)^k bmod n qquadneqqquad (abmod n)^{(k bmod n)}.$$
$endgroup$
$begingroup$
This answer exists primarily to remove this question from the Unanswered list; please upvote (or give Best Answer) to complete the process.
$endgroup$
– aleph_two
Dec 22 '18 at 5:06
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3005481%2fhow-to-calculate-mod-inverse%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Yes, the two formulas you wrote in the question give the same output.
More generally, as Bill Dubuque points out in the comments, you can usually just take mods at each step, instead of doing the whole computation and then modding at the end. However, exponentiation is a notable exception; you can reduce the base but generally not the exponent
$$ a^k bmod n quad=quad (abmod n)^k bmod n qquadneqqquad (abmod n)^{(k bmod n)}.$$
$endgroup$
$begingroup$
This answer exists primarily to remove this question from the Unanswered list; please upvote (or give Best Answer) to complete the process.
$endgroup$
– aleph_two
Dec 22 '18 at 5:06
add a comment |
$begingroup$
Yes, the two formulas you wrote in the question give the same output.
More generally, as Bill Dubuque points out in the comments, you can usually just take mods at each step, instead of doing the whole computation and then modding at the end. However, exponentiation is a notable exception; you can reduce the base but generally not the exponent
$$ a^k bmod n quad=quad (abmod n)^k bmod n qquadneqqquad (abmod n)^{(k bmod n)}.$$
$endgroup$
$begingroup$
This answer exists primarily to remove this question from the Unanswered list; please upvote (or give Best Answer) to complete the process.
$endgroup$
– aleph_two
Dec 22 '18 at 5:06
add a comment |
$begingroup$
Yes, the two formulas you wrote in the question give the same output.
More generally, as Bill Dubuque points out in the comments, you can usually just take mods at each step, instead of doing the whole computation and then modding at the end. However, exponentiation is a notable exception; you can reduce the base but generally not the exponent
$$ a^k bmod n quad=quad (abmod n)^k bmod n qquadneqqquad (abmod n)^{(k bmod n)}.$$
$endgroup$
Yes, the two formulas you wrote in the question give the same output.
More generally, as Bill Dubuque points out in the comments, you can usually just take mods at each step, instead of doing the whole computation and then modding at the end. However, exponentiation is a notable exception; you can reduce the base but generally not the exponent
$$ a^k bmod n quad=quad (abmod n)^k bmod n qquadneqqquad (abmod n)^{(k bmod n)}.$$
edited Dec 22 '18 at 5:52
community wiki
2 revs
aleph_two
$begingroup$
This answer exists primarily to remove this question from the Unanswered list; please upvote (or give Best Answer) to complete the process.
$endgroup$
– aleph_two
Dec 22 '18 at 5:06
add a comment |
$begingroup$
This answer exists primarily to remove this question from the Unanswered list; please upvote (or give Best Answer) to complete the process.
$endgroup$
– aleph_two
Dec 22 '18 at 5:06
$begingroup$
This answer exists primarily to remove this question from the Unanswered list; please upvote (or give Best Answer) to complete the process.
$endgroup$
– aleph_two
Dec 22 '18 at 5:06
$begingroup$
This answer exists primarily to remove this question from the Unanswered list; please upvote (or give Best Answer) to complete the process.
$endgroup$
– aleph_two
Dec 22 '18 at 5:06
add a comment |
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3005481%2fhow-to-calculate-mod-inverse%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
$begingroup$
Use the Extended Euclidean Algorithm, e.g. see here
$endgroup$
– Bill Dubuque
Nov 19 '18 at 20:36
$begingroup$
I know how to find a mod inverse. But if I have a number A*B^-1 mod p-1 is that equivalent to A mod p-1 * B mod p-1 mod p-1. That is what I found online but I wasn't sure.
$endgroup$
– User
Nov 19 '18 at 20:39
$begingroup$
$ab$ is invertible $iff a,b$ are invertible $iff a,b,$ are coprime to the modulus. When so we have $(ab)^{-1}equiv b^{-1}a^{-1},$ by $ b^{-1}a^{-1} (ab) equiv b^{-1}(a^{-1}a)bequiv b^{-1}b equiv 1 $ (inverses are always unique)
$endgroup$
– Bill Dubuque
Nov 19 '18 at 20:58
$begingroup$
So what if I have a number * an inverse mod p -1. How would I break that down?
$endgroup$
– User
Nov 19 '18 at 21:01
$begingroup$
Calculate the inverse then modular_multiply the two as you would any pair of (modular) integers - using the mod prodcut rule
$endgroup$
– Bill Dubuque
Nov 19 '18 at 21:05