Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96805846
LagrangeInterpolation.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Dec 31, 00:07
Size
2 KB
Mime Type
text/x-c
Expires
Thu, Jan 2, 00:07 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23227198
Attached To
R3229 Genome Privacy - SHCS App
LagrangeInterpolation.java
View Options
package
ch.epfl.lca1.crypto
;
import
java.math.BigInteger
;
import
java.security.SecureRandom
;
import
org.bouncycastle.asn1.x9.X9ECParameters
;
public
class
LagrangeInterpolation
{
/**
* @param args
*/
public
static
void
main
(
String
[]
args
)
{
ECElGamal
ecceg
=
new
ECElGamal
();
SecureRandom
randGen
=
new
SecureRandom
();
BigInteger
order
=
ecceg
.
getECParams
().
getN
();
BigInteger
secret
=
new
BigInteger
(
order
.
bitLength
()
-
1
,
randGen
);
BigInteger
a1
=
new
BigInteger
(
order
.
bitLength
()
-
1
,
randGen
);
BigInteger
[]
coefficients
=
new
BigInteger
[
2
];
coefficients
[
0
]
=
secret
;
coefficients
[
1
]
=
a1
;
BigInteger
first
=
getPartialSecret
(
1
,
coefficients
,
order
);
BigInteger
second
=
getPartialSecret
(
2
,
coefficients
,
order
);
ECElGamal
eccegCI
=
new
ECElGamal
(
ecceg
.
getECParams
(),
secret
);
ECElGamal
eccegMU
=
new
ECElGamal
(
ecceg
.
getECParams
(),
first
);
ECElGamal
eccegSPU
=
new
ECElGamal
(
ecceg
.
getECParams
(),
second
);
eccegMU
.
setPartNumber
(
ECElGamal
.
PART_MU
);
eccegSPU
.
setPartNumber
(
ECElGamal
.
PART_SPU
);
eccegMU
.
initReverseDLTable
();
eccegSPU
.
initReverseDLTable
();
BigInteger
message
=
BigInteger
.
valueOf
(
123L
);
FragmentEncrypted
encryptedMessage
=
eccegCI
.
encrypt
(
message
);
FragmentPartial
partialMU
=
eccegMU
.
partialDecrypt
(
encryptedMessage
);
FragmentPartial
partialSPU
=
eccegSPU
.
partialDecrypt
(
encryptedMessage
);
BigInteger
messageReassembled
=
eccegMU
.
fullDecrypt
(
partialMU
,
partialSPU
);
System
.
out
.
println
(
message
);
System
.
out
.
println
(
messageReassembled
);
/*
* secret = 2 * SK_1 - SK_2 mod q
*/
// BigInteger recovered = first.multiply(BigInteger.valueOf(2)).subtract(second).mod(order);
//
// System.out.println(recovered.equals(secret));
}
public
static
BigInteger
getPartialSecret
(
int
partNumber
,
BigInteger
[]
coefficients
,
BigInteger
order
)
{
BigInteger
result
=
BigInteger
.
ZERO
;
for
(
int
i
=
0
;
i
<
coefficients
.
length
;
i
++)
{
int
xPow
=
(
int
)
Math
.
pow
(
partNumber
,
i
);
BigInteger
term
=
coefficients
[
i
].
multiply
(
BigInteger
.
valueOf
(
xPow
));
result
=
result
.
add
(
term
);
}
return
result
.
mod
(
order
);
}
}
Event Timeline
Log In to Comment