Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97870160
EvalEC.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:09
Size
2 KB
Mime Type
text/x-c
Expires
Thu, Jan 9, 00:09 (2 d)
Engine
blob
Format
Raw Data
Handle
23424064
Attached To
R3229 Genome Privacy - SHCS App
EvalEC.java
View Options
package
crypto.elgamal
;
import
java.math.BigInteger
;
import
java.util.Enumeration
;
import
org.bouncycastle.asn1.nist.NISTNamedCurves
;
public
class
EvalEC
{
public
static
final
int
COMBINATION_SIZE
=
20
;
public
static
final
int
NUMBER_TESTS
=
100
;
/**
* @param args
*/
public
static
void
main
(
String
[]
args
)
{
// evalCurves();
ECElGamal
ecceg
=
new
ECElGamal
(
NISTNamedCurves
.
getByName
(
"P-521"
));
ecceg
.
initReverseDLTable
();
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
timeDecrypt
(
ecceg
);
}
}
private
static
void
timeDecrypt
(
ECElGamal
ecceg
)
{
BigInteger
[]
msgs
=
new
BigInteger
[
256
];
FragmentEncrypted
[]
encrypted
=
new
FragmentEncrypted
[
msgs
.
length
];
BigInteger
[]
dec
=
new
BigInteger
[
msgs
.
length
];
for
(
int
i
=
0
;
i
<
msgs
.
length
;
i
++)
{
msgs
[
i
]
=
BigInteger
.
valueOf
(
i
);
}
long
startTimeEnc
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
msgs
.
length
;
i
++)
{
encrypted
[
i
]
=
ecceg
.
encrypt
(
msgs
[
i
]);
}
long
endTimeEnc
=
System
.
currentTimeMillis
();
long
startTimeDec
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
dec
.
length
;
i
++)
{
dec
[
i
]
=
ecceg
.
decrypt
(
encrypted
[
i
]);
}
long
endTimeDec
=
System
.
currentTimeMillis
();
System
.
out
.
println
((
endTimeEnc
-
startTimeEnc
)
+
"\t"
+
(
endTimeDec
-
startTimeDec
));
}
private
static
void
evalCurves
()
{
ECElGamal
ecceg
;
Enumeration
<
String
>
curveNames
=
NISTNamedCurves
.
getNames
();
while
(
curveNames
.
hasMoreElements
())
{
String
curveName
=
(
String
)
curveNames
.
nextElement
();
ecceg
=
new
ECElGamal
(
NISTNamedCurves
.
getByName
(
curveName
));
ecceg
.
initReverseDLTable
();
System
.
out
.
print
(
curveName
+
"\t"
);
FragmentEncrypted
encrypted
=
ecceg
.
encrypt
(
new
BigInteger
(
"25"
));
FragmentEncoded
encoded
=
encrypted
.
getFragmentEncoded
();
System
.
out
.
print
(
encoded
.
sizeByte
());
testRisk
(
ecceg
);
}
}
private
static
void
testRisk
(
ECElGamal
eccegScheme
)
{
BigInteger
[]
SNPs
=
new
BigInteger
[
COMBINATION_SIZE
];
BigInteger
[]
coeffs
=
new
BigInteger
[
COMBINATION_SIZE
];
FragmentEncrypted
[]
fragsEncrypted
=
new
FragmentEncrypted
[
COMBINATION_SIZE
];
for
(
int
i
=
0
;
i
<
SNPs
.
length
;
i
++)
{
SNPs
[
i
]
=
BigInteger
.
valueOf
(
i
%
3
);
coeffs
[
i
]
=
BigInteger
.
valueOf
((
i
+
2
)
%
3
);
fragsEncrypted
[
i
]
=
eccegScheme
.
encrypt
(
SNPs
[
i
]);
}
FragmentEncrypted
riskEncrypted
;
BigInteger
riskBigInteger
;
double
risk
;
long
startTime
=
System
.
currentTimeMillis
();
for
(
int
i
=
0
;
i
<
NUMBER_TESTS
;
i
++)
{
riskEncrypted
=
RiskAnalyzer
.
risk
(
fragsEncrypted
,
coeffs
);
riskBigInteger
=
eccegScheme
.
decrypt
(
riskEncrypted
);
risk
=
riskBigInteger
.
doubleValue
()
/
RiskAnalyzer
.
PRECISION
;
}
long
endTime
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"\t"
+
(
endTime
-
startTime
));
}
}
Event Timeline
Log In to Comment