Massachusetts
Institute
of
Technology
Handout
12
6.857:
Network
and
Computer
Security
October
7,
2003
Professor
Ronald
L.
Rivest
Problem
Set
3
Solutions
Problem
31.
Prime
Triangles.
TA
Notes:
It
is
a
littleknown
fact
(to
us,
anyway)
that
the
Java
1.4.1
class
library
contains
a
bug
in
part
of
its
primality
tester.
Specifically,
the
LucasLehmer
test
is
implemented
incorrectly,
and
sometimes
reports
that
certain
large
numbers
are
composite
when
they
are
actually
prime
1
.
This
slowed
down
our
own
triangle
finding
algorithm
for
large
values
of
k
,
and
also
caused
some
false
alarms
during
grading.
Fortunately,
the
bug
is
fixed
in
version
1.4.2.
Most
good
solutions
(and
our
own,
as
well)
used
the
following
general
framework:
pick
a
value
a
(it
helps
if
a
is
prime,
so
that
it’s
relatively
prime
to
all
b
and
c
),
then
find
many
values
of
b
that
form
a
“prime
pair”
with
a
(i.e.,
both
a
b
and
b
a
are
prime).
For
each
newlyfound
value
of
b
,
see
if
it
forms
a
prime
pair
with
◦
any
previouslyfound
value
c
◦
;
if
so,
return
(
a,
b,
c
)
as
a
prime
triangle.
For
a
fast
implementation
of
the
above
algorithm,
there
are
several
optimizations
that
can
be
used
before
employing
full
MillerRabin
tests:
the
Sieve
of
Eratosthenes,
small
prime
divisor
tests,
and
greatest
common
divisor
tests.
While
this
strategy
works
very
well,
the
search
time
for
k
digit
prime
triangles
seems
to
vary
wildly,
even
for
fixed
k
.
This
is
probably
due
to
the
fact
that
some
a
values
can
work
in
many
triangles,
while
others
cannot
belong
to
any
at
all
(
a
=
73
is
one
example
for
k
=
2).
The
running
time,
then,
dramatically
depends
upon
how
lucky
we
are
at
choosing
a
good
initial
value
of
a
.
It
also
seems
that
code
written
in
C
(using
the
GMP
toolkit,
for
example)
still
has
significant
performance
advantages
over
code
written
in
Java.
Groups
that
wrote
their
programs
in
C
typically
were
able
to
find
triangles
for
larger
values
of
k
than
groups
who
used
Java,
using
comparable
algorithms.
For
grading,
we
reserved
the
top
scores
(9s
and
10s)
for
groups
who
described
good
algorithms
and
found
triangles
for
k
=
40
or
higher.
A
decent
algorithm
and
a
value
of
k
=
20
or
higher
typically
earned
7
to
8
points.
Using
an
algorithm
similar
to
the
one
below
(but
written
in
C),
the
group
of
Alexandros
Kyriakides,
Saad
Shakshir,
and
Ioannis
Tsoukalidis
found
a
prime
triangle
for
k
=
140
.
The
following
is
our
(heavilycommented)
implementation
of
a
prime
trianglefinder,
in
Java.
With
it,
we
were
able
to
find
a
prime
triangle
for
k
=
100
in
about
30
minutes
on
an
Athlon
1.4
GHz
machine
running
Debian
Linux.
On
average
and
on
the
same
hardware,
we
are
able
to
find
a
prime
triangle
for
k
=
140
in
about
6
hours.
The
code
can
be
downloaded
from
the
6.857
website.
1
/**
2
A
reasonably
efficient
prime
triangle
finder,
written
for
Problem
31
3
of
6.857,
Fall
2003.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '03
 Rivest
 Cryptography, Computer Security, Encryption, Advanced Encryption Standard, Block cipher, Block cipher modes of operation

Click to edit the document details