decrypting RSA using c^d mod n - encryption

I'm trying to get a message out of an RSA code, but cant seem to understand
how.
The formula i'm trying to use to find the message is: c^d mod n.
In the text file i received (which is the RSA code), i have 3 parameters:
The c parameter:
c=62094327354293714871337806608043143339672711375275261525243238242322194473023610842261452370807533140129255594935713596899492336925573500404508972313463258470764117200138784924348362580128423518572743446058119722861164424364186271770831857887818550880280385895469933434901508250872871673722739401583613920865
the N parameter:
N=102518413348128616948064302091615267327586561544914497024946023154172320251650248158262401038211060025769143033483116931749752882566368072181993447378932810603880706573407783516535716219705301632360773290434984792276962906314924125193872533986871367036809927042370179209563059349511562287725586162360516841779
and the d parameter:
d=90575112832191634931822012293951618304193311969935139031973154594700485026947413962490036848108653090804963912366135718482295366073482828257042351498160831683665400283336482471506944874247073018050011183570224881323949477869741822928092177900190031155493051065073868895195339892585741809998466654281718606993
Now the problem is that the numbers are WAY too long (308 digits long, and the N parameter is 309 digits long). I couldn't find any calculator that can calculate c^d so far.
any help?

You can do that with java using math.BigInteger
BigInteger c = new BigInteger("62094327354293714871337806608043143339672711375275261525243238242322194473023610842261452370807533140129255594935713596899492336925573500404508972313463258470764117200138784924348362580128423518572743446058119722861164424364186271770831857887818550880280385895469933434901508250872871673722739401583613920865");
BigInteger N = new BigInteger("102518413348128616948064302091615267327586561544914497024946023154172320251650248158262401038211060025769143033483116931749752882566368072181993447378932810603880706573407783516535716219705301632360773290434984792276962906314924125193872533986871367036809927042370179209563059349511562287725586162360516841779");
BigInteger d = new BigInteger("90575112832191634931822012293951618304193311969935139031973154594700485026947413962490036848108653090804963912366135718482295366073482828257042351498160831683665400283336482471506944874247073018050011183570224881323949477869741822928092177900190031155493051065073868895195339892585741809998466654281718606993");
BigInteger m = new BigInteger("1");
m = c.modPow(d, N);
System.out.println(m);
And the result would be
12095051301478169748702315942951183566712581822646196016924926165965065297342257

Related

Incrementation in Julia

I want to solve this integration. With the upper limit phi ranging from 1-2.4. I want to receive answers at every increment of phi.
The code that I have pasted below is only outputting the answer when phi=2.4. How can I fix this? I am new to Julia and have basic knowledge of programming which is why i think i am not doing this correctly.
using Ranges
for ϕ in range(start=1, stop=2.4, step=0.2)
using QuadGK
f(ϕ) = ϕ*(cos(ϕ)/sin(ϕ))
a = 0
b = ϕ
I,est = quadgk(f, a, b, rtol=1e-8)
end
println(I, est)
Print should be inside the for loop, so you print all the iterations ...
using Ranges
using QuadGK
f(ϕ) = ϕ*(cos(ϕ)/sin(ϕ))
for ϕ in range(start=1, stop=2.4, step=0.2)
a = 0
b = ϕ
I,est = quadgk(f, a, b, rtol=1e-8)
println(I, est)
end

ndgrid - input and output from cell array

I am converting some code from Matlab to Scilab and ran into trouble trying to use Scilab 'ndgrid' function with input and output from cell array.
Specifically, I use ndgrid with an a priori unknown number of vectors (contained in a cell array) and intend to get the output grid matrices in a cell array.
In Matlab the code looks like that:
v = {0:3,0:3}; // not necessarily of length 2 (dynamically set)
G = cell(1,2);
[G{:}] = ndgrid(v{:});
I can't obtain similar behaviour using Scilab (neither for the input, nor for the output).
For the input, Scilab returns ndgrid: Wrong type for argument #1: Booleans, Integers, Decimals, Complexes, Polynomials, Rationals or Texts expected.
I hope a workaround exists. Thanks for your help!
v = list(0:3, 0:2); // not necessarily of length 2 (dynamically set)
G = list();
c = strcat(msprintf("G(%i)\n",(1:length(v))'),",")
execstr("[" + c + "] = ndgrid(v(:))")
G
does it:
--> c = strcat(msprintf("G(%i)\n",(1:length(v))'),",")
c =
"G(1),G(2)"
--> execstr("[" + c + "] = ndgrid(v(:))")
--> G
G =
(1) : [4x3 constant]
(2) : [4x3 constant]

Cretate multiple shared secrets in a (selfmade) public/privavte key infrastructure

I just try to understand cryptography, please be concern. Its not meant to be secure or professional. I create 3 numbers for each party. a public key, a secret key and a modulus. The first party (A) creates his keys
let pri = 133
let mod = 256
let pub = mod - pri
and shares "mod" and "pub" to other partys (B, C). When B want to encrypt a string he takes A's public key and modulus and do
// B encrypts
let enc = ( input + pubA ) % modA
A on his side is doing
// B decrypts
let dec = ( enc + priA) % modA
to decrypt it. My problem is, i can create multiple keypairs but only 1 associated public key to each secret key because i have to share the modulus of each pair for en/decryption.
Is it possible (in this situation) to create multiple publics numbers for a single private number? And if so, how can i do it?
Thank you (and sorry if this is a poor question)
EDIT Even if its not "good" to create your own cipher i want to do so..
I recognized that i missed the secret exponent d so that phi divides (e * expo)-1.
/* Pseude code */
p = q = primes()
n = p * q
phi = (p-1) * (q-1)
e = 3
d = ? // <-- have to find my own secret exponent!
if( gcd(e, p-1) != gcd(e, q-1) ) exit(0)
expo = 0
for(expo < 100000)
if( (e * expo)-1 == phi ) ) d = expo
And therefore i could have
public(n,e)
private(n,d)
so i can share (n,e). Is that correct?

RSA private key and public key

Little stuck on how to approach this question:
Xavier and Yvonne are in love. They both set up their own RSA keys:
Xavier’s public key is (eX , nX ) = (887, 15833), and Yvonne’s public key
is (eY , nY ) = (977, 13019). For each of the following, do not factor nX nor
nY , show the set up of the calculations and the results. You should use a
computer to perform the calculations.
(a) Yvonne wants to send Xavier a private message of love, which is
M = 3141. What is the ciphertext that Yvonne needs to send to Xavier?
(b) In return, Yvonne received three mysterious messages: C1 = 10889,
C2 = 2622, C3 = 4061. All three senders claim to be Xavier, and all
claim to have sent the message Ci ≡ MdX (mod nX) where M = 3141 and dX
is Xavier’s private key. However, only Xavier himself knows the actual
value of dX , and the other two are imposters trying to steal Yvonne away
from him. Help Yvonne determine which message is actually from Xavier,
and explain why your method works.
Any tips would be great thanks!
a) In order to send an RSA-encrypted message such that only the private key holder can decrypt it, it must be encrypted using the recipient's public key. In this case, the recipient is Xavier, so the message is encrypted using his public key: (eX, nX) = (887, 15833):
Message: M = 3141
Ciphertext: C = MeX mod nX
C = 3141887 mod 15833
C = 2054
b) This is essentially a signature verification of a message signed using Xavier's private key, which requires the use of the signer's public key. It is necessary to find which of the three messages, when decrypted using Xavier's public key results in the message that was sent (3141):
Ciphertext 1: C1 = 10889
Message 1: M1 = C1eX mod nX
M1 = 10889887 mod 15833
M1 = 6555 (mismatch)
Ciphertext 2: C2 = 2622
Message 2: M2 = C2eX mod nX
M2 = 2622887 mod 15833
M2 = 1466 (mismatch)
Ciphertext 3: C3 = 2622
Message 3: M3 = C3eX mod nX
M3 = 4061887 mod 15833
M3 = 3141 (match!)
Only C3 matches the message when decrypted using Xavier's public key, and so is the only authentic message.
Note: I used WolframAlpha to perform the modular exponentiation above, but it's easy enough (though rather more time-consuming) to do manually using repeated multiplication then reduction modulo n.

Diffie-Hellman -- Primitive root mod n -- cryptography question

In the below snippet, please explain starting with the first "for" loop what is happening and why. Why is 0 added, why is 1 added in the second loop. What is going on in the "if" statement under bigi. Finally explain the modPow method. Thank you in advance for meaningful replies.
public static boolean isPrimitive(BigInteger m, BigInteger n) {
BigInteger bigi, vectorint;
Vector<BigInteger> v = new Vector<BigInteger>(m.intValue());
int i;
for (i=0;i<m.intValue();i++)
v.add(new BigInteger("0"));
for (i=1;i<m.intValue();i++)
{
bigi = new BigInteger("" + i);
if (m.gcd(bigi).intValue() == 1)
v.setElementAt(new BigInteger("1"), n.modPow(bigi,m).intValue());
}
for (i=0;i<m.intValue();i++)
{
bigi = new BigInteger("" + i);
if (m.gcd(bigi).intValue() == 1)
{
vectorint = v.elementAt(bigi.intValue());
if ( vectorint.intValue() == 0)
i = m.intValue() + 1;
}
}
if (i == m.intValue() + 2)
return false;
else
return true;
}
Treat the vector as a list of booleans, with one boolean for each number 0 to m. When you view it that way, it becomes obvious that each value is set to 0 to initialize it to false, and then set to 1 later to set it to true.
The last for loop is testing all the booleans. If any of them are 0 (indicating false), then the function returns false. If all are true, then the function returns true.
Explaining the if statement you asked about would require explaining what a primitive root mod n is, which is the whole point of the function. I think if your goal is to understand this program, you should first understand what it implements. If you read Wikipedia's article on it, you'll see this in the first paragraph:
In modular arithmetic, a branch of
number theory, a primitive root modulo
n is any number g with the property
that any number coprime to n is
congruent to a power of g (mod n).
That is, if g is a primitive root (mod
n), then for every integer a that has
gcd(a, n) = 1, there is an integer k
such that gk ≡ a (mod n). k is called
the index of a. That is, g is a
generator of the multiplicative group
of integers modulo n.
The function modPow implements modular exponentiation. Once you understand how to find a primitive root mod n, you'll understand it.
Perhaps the final piece of the puzzle for you is to know that two numbers are coprime if their greatest common divisor is 1. And so you see these checks in the algorithm you pasted.
Bonus link: This paper has some nice background, including how to test for primitive roots near the end.

Resources