Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97871692
FragmentEncryptedTest.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, Jan 7, 00:40
Size
1 KB
Mime Type
text/x-java
Expires
Thu, Jan 9, 00:40 (2 d)
Engine
blob
Format
Raw Data
Handle
23424680
Attached To
R3229 Genome Privacy - SHCS App
FragmentEncryptedTest.java
View Options
package
crypto.elgamal.fragment
;
import static
org.junit.Assert.*
;
import
java.math.BigInteger
;
import
org.bouncycastle.asn1.nist.NISTNamedCurves
;
import
org.junit.Test
;
import
crypto.elgamal.ECElGamal
;
public
class
FragmentEncryptedTest
{
@Test
public
void
testAdd
()
{
ECElGamal
eccegScheme
=
new
ECElGamal
(
NISTNamedCurves
.
getByName
(
"P-384"
));
eccegScheme
.
initReverseDLTable
();
BigInteger
msg1
=
new
BigInteger
(
"4"
);
BigInteger
msg2
=
new
BigInteger
(
"7"
);
FragmentEncrypted
fragEncrypted1
=
eccegScheme
.
encrypt
(
msg1
);
FragmentEncrypted
fragEncrypted2
=
eccegScheme
.
encrypt
(
msg2
);
FragmentEncrypted
fragSum
=
fragEncrypted1
.
add
(
fragEncrypted2
);
BigInteger
sumDecrypted
=
eccegScheme
.
decrypt
(
fragSum
);
assertTrue
(
"Addition homomorphic"
,
sumDecrypted
.
equals
(
msg1
.
add
(
msg2
)));
}
@Test
public
void
testScale
()
{
ECElGamal
eccegScheme
=
new
ECElGamal
(
NISTNamedCurves
.
getByName
(
"P-384"
));
eccegScheme
.
initReverseDLTable
();
BigInteger
msg
=
new
BigInteger
(
"7"
);
BigInteger
s
=
new
BigInteger
(
"3"
);
FragmentEncrypted
frag
=
eccegScheme
.
encrypt
(
msg
);
FragmentEncrypted
fragScaled
=
frag
.
scale
(
s
);
BigInteger
msgScaled
=
eccegScheme
.
decrypt
(
fragScaled
);
assertTrue
(
"Scale homomorphic"
,
msgScaled
.
equals
(
msg
.
multiply
(
s
)));
}
}
Event Timeline
Log In to Comment