Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F97547813
FragmentEncrypted.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
Sun, Jan 5, 04:17
Size
1 KB
Mime Type
text/x-java
Expires
Tue, Jan 7, 04:17 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23424761
Attached To
R3229 Genome Privacy - SHCS App
FragmentEncrypted.java
View Options
package
crypto.elgamal.fragment
;
import
java.io.Serializable
;
import
java.math.BigInteger
;
import
org.bouncycastle.math.ec.ECPoint
;
public
class
FragmentEncrypted
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
3696282821457016342L
;
private
ECPoint
R
;
private
ECPoint
S
;
public
FragmentEncrypted
()
{
this
.
R
=
null
;
this
.
S
=
null
;
}
public
FragmentEncrypted
(
ECPoint
R
,
ECPoint
S
)
{
this
.
R
=
R
;
this
.
S
=
S
;
}
public
ECPoint
getR
()
{
return
R
;
}
public
ECPoint
getS
()
{
return
S
;
}
public
FragmentEncoded
getFragmentEncoded
()
{
return
new
FragmentEncoded
(
this
);
}
public
FragmentEncrypted
add
(
FragmentEncrypted
fragToAdd
)
{
ECPoint
first
;
ECPoint
second
;
// XXX beware shallow copy
if
(
this
.
R
==
null
&&
this
.
S
==
null
)
{
first
=
fragToAdd
.
getR
();
second
=
fragToAdd
.
getS
();
}
else
if
(
fragToAdd
.
getR
()
==
null
&&
fragToAdd
.
getS
()
==
null
)
{
first
=
R
;
second
=
S
;
}
else
{
first
=
R
.
add
(
fragToAdd
.
getR
());
second
=
S
.
add
(
fragToAdd
.
getS
());
}
return
new
FragmentEncrypted
(
first
,
second
);
}
public
FragmentEncrypted
scale
(
BigInteger
a
)
{
// TODO: check sanity of number
ECPoint
first
=
R
.
multiply
(
a
);
ECPoint
second
=
S
.
multiply
(
a
);
return
new
FragmentEncrypted
(
first
,
second
);
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
result
=
prime
*
result
+
((
R
==
null
)
?
0
:
R
.
hashCode
());
result
=
prime
*
result
+
((
S
==
null
)
?
0
:
S
.
hashCode
());
return
result
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(
obj
==
null
)
return
false
;
if
(
getClass
()
!=
obj
.
getClass
())
return
false
;
FragmentEncrypted
other
=
(
FragmentEncrypted
)
obj
;
if
(
R
==
null
)
{
if
(
other
.
R
!=
null
)
return
false
;
}
else
if
(!
R
.
equals
(
other
.
R
))
return
false
;
if
(
S
==
null
)
{
if
(
other
.
S
!=
null
)
return
false
;
}
else
if
(!
S
.
equals
(
other
.
S
))
return
false
;
return
true
;
}
}
Event Timeline
Log In to Comment