You are on page 1of 25

uectuiotooo|qk,_=|vuect

uiotooo|qk,_=|vuectuiotooo
|qk,_=|vuectuiotooo|qk,
_=|vuectuiotooo|qk,_=|v
uectuiotooo|qk,_=|vuect
uiotooo|qktuiotooo|qk,_=|v
uectuiotooo|qk,_=|vuect
uiotooo|qk,_=|vuectuioto
oo|qk,_=|vuectuiotooo|qk
,_=|vuectuiotooo|qk,_=|
vuectuiotooo|qk,_=|vuect
uiotooo|qk,_=|vuectuioto
oo|qk,_=|vuectuiotooo|qk
,_=|vtuiotooo|qk,_=|vu
ectuiotooo|qk,_=|vuectui
otooo|qk,_=|vuectuiotooo|
qk,_=|vuectuiotooo|qk,
_=|vuectuiotooo|qk,_=|vu
ectuiotooo|qk,_=|vuectui
otooo|qk,_=|vuectuiotooo|
qk,_=|vuectuiotooo|qk,
Analysis of prime numbers as used in computer
security by Turing machines in the 2nd decade of
the 21st century and using BigO notation to study
the efficiency of prime number generating
algorithms and evaluating it as a threat to computer
security.

Abhi Agarwal
Subject: Computer Science
Supervisor: Romeu Barros
Candidate number:
Centre number:
Word count: 3,988
School: Bangkok Patana School





2


Abstract
In this technological world, as one starts to increase the use of computers, what
protects one from hackers on the Internet or even hackers in general? Prime number
encryption and decryption methods do. These methods allow you to make your data
secure, so when you go on Amazon or Ebay or a similar site, these methods help to
protect your data. These encryption and decryption methods have prime numbers
algorithms, which encrypt your shopping cart, or sometimes-even emails. Essentially,
large prime numbers are use to produce keys, which are used to communicate with the
transmission of the data. But what happens if someone is able to generate these very
large prime numbers to find your password? It would pose trouble for you as your
data can be compromised. The topic I researched for my Extended Essay was the
Analysis of prime numbers as used in computer security by Turing machines in the
2
nd
decade of the 21
st
century and using BigO notation to study the efficiency of prime
number generating algorithms and evaluating it as a threat to computer security. I
found that as the prime number generating algorithms grow more efficient, methods
of decrypting your private data will be easier, and therefore with grid computers
1
,
hackers will easily be able to breach your personal information. However as these
methods also get more secure everywhere, with all things constant I found that there
is a direct and positive correlation between the efficiency of prime number generators
and the security of encryption methods, as prime number generators get more efficient,
the encryption methods get more secure and therefore the security of the computer
increases. Nonetheless, I also found that the discovery of Quantum Computers in the
future would make this layer of security obsolete, however only to a certain extent.
(Word Count: 300)





1
Michael. C, 2005 Grid Computing,
http://net.educause.edu/ir/library/pdf/ERM05612.pdf, (accessed: 7th October 2011)

3


Table of Contents
INTRODUCTION 4
WHAT ARE PRIME NUMBERS? 5
THE IMPORTANCE OF PRIME NUMBERS IN COMPUTER SECURITY 5
PRIME NUMBER GENERATING ALGORITHMS 6
THE FIRST PRIME NUMBER GENERATOR ALGORITHM 7
THE SECOND PRIME NUMBER GENERATOR ALGORITHM 9
THE THIRD PRIME NUMBER GENERATOR ALGORITHM 11
COMPARISON OF THESE ALGORITHMS 14
PRIME NUMBERS AS A THREAT TO COMPUTER SECURITY 15
CONCLUSION 17
BIBLIOGRAPHY 18
APPENDIX 19

















4


Introduction
The ever-increasing dependency of the world on technological advancements
intrigues me immensely, and has made me interested in the future of computer
security. This increase on the reliance of technology by companies and individuals to
protect their data has increased the vulnerability and further has increased the chance
of them getting attacked by 3
rd
parties. As computer security was a too broad topic to
explore and being fascinated by the concept, I had considered the sub-topic of
encryption keys. Encryption keys are what computer systems use to encrypt their data
for protection from external users. I had considered this because this sector of
computer security is the one most growing and most vulnerable, there is a massive
increase in the amount of computer breaches every year, and because the way data is
encrypted is massively changing over the years. I had further broken down my topic
of computer security in terms of encryption to the usage of prime numbers to secure
information. One example of the usefulness of prime numbers is shown by RSA
2

encryption and decryption method, which makes computer security more secure by
using prime numbers instead of the generation of large integers to secure the data.
I propose to research this topic because there is an overgrowing usage of computer
systems in this developing world, in every field of human labor, such as banking
systems, personal computers, stock market systems and even agricultural systems.
Initially, in order to evaluate the usage of very large prime numbers in computer
security, I will calculate the efficiency of the prime number generating algorithms. In
order to find the efficiency of these algorithms, I intend to use BigO notation, which
describes the performance of complexity of algorithms. These algorithms will be
those, which Turing machines at home, or small businesses are able to execute.
Secondly, I will find the execution time and the space required for the algorithm to
execute as the growth of the prime numbers increase, which tells us the speed of the
execution as the prime number digits increase in size. Thirdly, I am also investigating
the threat of the generation of very large prime numbers as a threat to computer
security, thus using the efficiency of the prime number generation algorithms and

2
David. I, 2011 RSA Algorithm, http://www.di-mgt.com.au/rsa_alg.html,
(accessed: 3
rd
November 2011)

5


sample data I am able to comment on the extent to which the increasing efficiency of
prime number generating algorithms are a threat to computer security.
Lastly, I had considered the context or the setting in which these calculations and
conclusions will take place, and had concluded that they will take place in the 2
nd

decade of the 21
st
century. Therefore, I narrowed down the research question for this
Extended Essay to: Analysis of prime numbers as used in computer security by
Turing machines in the 2
nd
decade of the 21
st
century and using BigO notation to
study the efficiency of prime number generating algorithms and evaluating it as a
threat to computer security.
What are prime numbers?
A prime number
3
is a number that has only two positive integer factors. The factors
are itself and 1. For example, the number 17 can only be divided by 1 and 17, with no
remainder; therefore it is a prime number. These are the two characteristics that I will
consider and apply in this Extended Essay.
The Importance of Prime Numbers in Computer Security
So now we know what they are, what are they used for? In cryptography and
computer security, the major idea is to create and use functions that are quick and
easy for the computer to execute, however functions that are extremely difficult to
find the inverse of. Many major functions that have been adapted for data encryption
use prime numbers, as you cannot find a prime number by using other numbers, it
only has factors of 1 and itself, and therefore it decreases the chance of the data being
compromised.
There are many types of cryptography techniques such as Secret Key and Public Key;
however I will be concentrating on the Public Key method of cryptography. Public
Key cryptography
4
is a new and efficient method of encrypting data securely for a

3
Eric W, 2011 Prime Number, http://mathworld.wolfram.com/PrimeNumber.html,
(accessed: 24
th
August 2011)
4
Kristin. L, 2010 A Primer on Cryptography, http://research.microsoft.com/en-
us/groups/crypto/firstcrypto.aspx, (accessed: 20
th
August 2011)
Jerry. C, 2003 Prime Numbers in Public Key Cryptography,
http://www.sans.org/reading_room/whitepapers/vpns/prime-numbers-public-key-
cryptography_969, (accessed: 7
th
August 2011)


6


large number of users. Every user has a public key, and a private key, the public key
is transferred to all users while data transmission, and the private key is kept secret by
the users computer.
For example, using this simple model you will be able to see how prime numbers are
useful in computer security, if you take two primes and multiply them together, in this
case lets make them a and b, and the result is n, a*b=n, and if n is the product of the
two primes, then there is one and only such pair that could be made by only those
prime numbers. Therefore, decrypting the data would be a job that would require a lot
of work and complex decryption tools. Moreover, if the prime numbers are very large,
when they are multiplied together, it will take a very long time
5
and more than a
normal computer them to calculate and match both of those prime numbers.
Now if we look at the most commonly used encryption method using prime numbers
we have to consider the RSA encryption method. The RSA encryption method is
similar to the simple model we considered earlier but gets more complex; it is one of
the widely implemented algorithms on the Internet. In the RSA method you, use 2
huge prime numbers, each will have around 300 or more digits, and these will be set
as your private key, it will be called P and Q
6
. After that you will multiply these to
make a number called n, which will be your public key. By this time you probably
have realized that it will be very hard to find to get P and Q, from just n. The number
n will only be used in sending and receiving data between different computers to
further secure the information.
Prime number generating algorithms
Calculating prime numbers now has become very useful as they are required in
public-key cryptography and there are increasingly new methods of generating prime
numbers. In my research, I will look at methods of the generation of prime numbers
that can be carried out by individuals in their own workspaces and which do not
require advanced computers, in order to analyze the extent to which the average
computer in the 2
nd
decade of the 21
st
century would be able to use this to brute force

5
Tom. W, 2009 Number Theory, http://www-cs-
students.stanford.edu/~tjw/primes.html, (accessed: 8
th
August 2011)
6
Paul. J, 2009 RSA Algorithm, http://pajhome.org.uk/crypt/rsa/rsa.html, (accessed:
10
th
October 2011)

7


into other computers. I will look at a 3 common and efficient prime number
generating algorithms and compare their efficiency and comment on each of these
algorithms.
My dependent variable will be the time and the BigO Notation of the algorithms,
while my independent variable will be the amount of prime numbers generated.
For the results of the algorithms I will calculate, I will record the results as 3
significant figures, and my control variable will be the same CPU usage while these
results are processing, I will start with the same CPU usage and only run programs
each time that were running for all the results to be able to compare them fairly. The
CPU usage at the start of the program is shown in Figure 1, the CPU usage with the
user and system will roughly be 4% for each result. All these tests will be done on a
Apple Mac Book Pro Fall 2010, Intel Core i7, 2.66 GHz with 4 GB RAM, 1067 MHz
DDR3. I will also use Java SDK
7
and Eclipse
8
for the algortihms I will have.


For my graphical representations, I will use WolframAlpha
9
, as it is able to plot these
curves very efficiently and prisecely and I am able to get a equal representations to
compare the data.

The first prime number generator algorithm
10

This prime number generating algorithm is written in Java and creates a list that holds
integers. The user is prompted on what is the highest integer it can reach till where it
has to generate the prime numbers, and then it has a for loop and a for loop nested
inside it. It starts from when i = 2 as we know 1 is not a prime number, and then tries
to divide this number by all known primes, and if it isnt a prime number it continues

7
Oracle, 2011 Java SE Downloads,
http://www.oracle.com/technetwork/java/javase/downloads/index.html, (accessed:
20
th
October 2011)
8
The Eclipse Foundation, 2011 Eclipse, http://www.eclipse.org, (accessed: 20
th

October 2011)
9
Wolfram, 2011 WolframAlpha, http://www.wolframalpha.com, (accessed: 10
th

November 2011)
10
The data obtained below is summarized. The detailed data are given in Appendix
1.1
Figure 1- CPU Usage


8


and if it is it adds that prime number to the list and then returns that list which we are
able to display.
The BigO efficiency of this algorithm is O(

), I have calculated this by considering


the nested loops, it will have to go

amounts of time through the data.


I will now calculate the time it takes for the program to calculate prime numbers from
100,000 - 20,000,000, using ranges of limits
11
between. I predict that it starts to
increase exponentially after 100,000 and wouldnt affect the condition of the
computer by a massive amount to generate 9592 (100,000 limit) prime numbers.
However, when we go above that the time will start to increase rapidly.
Average of the 6 different limits:
12

Prime number limit Elapsed time in seconds:
100,000 0.742
500,000 19.2
1,000,000 61.2
5,000,000 955
10,000,000 3035
20,000,000 8842

This result fluctuated a lot because it took a long time to generate them, and these
results were not calculated in one go, they were spread over a few days for an
accurate average.




11
Limits: The barrier for the prime number generated to reach, for example if the
limit is 100,000 the highest prime number can be till 99,999.
12
The data obtained below is summarized. The detailed data in Tables are given in
Appendix 2.1

9


Graph




I was looking at the shape of Figure 2
13
, and I notice that it was shaped like the graph
of

the exponential increase in the results I had gathered, I noticed that it rapidly
increased from 100,000 to 5,000,000. We can see that this function is very efficient
for values that are smaller than 1,000,000 but grows very fast in time after that value.
We can see a similarity between the graphs; we can see that at

(Figure 2) it is
similar to (of Figure 3)
14
, and we can see that in Figure 2 there is an exponential
increase between those values. Therefore, I believe that the time exponentially
increases between the limits of the prime numbers for this algorithm.
Moreover, in summary this is one of the algorithms that is implemented into other
programs of mathematics and computer science, it is not used as a program alone to
generate prime numbers. I had chosen this because in computer security prime
number generation is used in conjunction with other tools, and not solely for
generation.
The second prime number generator algorithm
15

This prime number generating algorithm is also written in Java and doesnt use
variables or arrays to store the prime numbers but directly outputs them when they are
generated. In this algorithm, there is a Boolean variable called isPrime which is set to
true at the beginning, and a for loop, when it is executed, the inner for loop has a

13
Using WolframAlpha, I generated this graph, using the function:
ListPlot[{{100000,0.742},{500000,19.2},{1000000,61.2},{5000000,955},{10000000
,3035},{20000000,8842} }
14
Using WolframAlpha (Wolfram, 2011), I generated this graph, using the function:
plot [e^x x=(0.01 to 2)]
15
The data obtained below is summarized. The algorithm for this function is given in
Appendix 1.2
Figure 2 Compiled from the averages of
the 6 different limits
Figure 3 The graph of




10


range of y=2 till when y <= . Therefore it will attempt the values of y until the
square number of the limit, for example 100,000 is reached. The computer then has
only

possibilities of calculating that prime number. Furthermore, the algorithm


has an if statement which checks if the modulus of x and y is less than 1, if it is less
than one the isPrime is set to false, and the number is not printed on the screen, as for
example, the modulus of the two numbers could potentially be 0, therefore showing
that the two numbers divide by each other.
The BigO notation of this algorithm is also O(

) as there are nested for loops,


however the results that I had calculated from this algorithm at the same computer
usage and CPU usage as the previous one and I had got surprising results, which were
way lower than the other algorithm, which surprised me as though they were the same
efficiency and this calculated it in less than

of the time.
Average of the 6 different limits:
16

Prime number limit Elapsed time in seconds:
100,000 0.292
500,000 1.82
1,000,000 4.78
5,000,000 36.4
10,000,000 119
20,000,000 393
Graph



16
The data obtained below is summarized. The detailed data in Tables are given in
Appendix 2.2

Figure 4 Compiled from the averages of the 6 different limits

11



If we look at the curvature of Figure 4
17
we can see that it starts to increase rapidly
after as it becomes a straight line and the gradient changes by a massive
amount, this shows us that the algorithm is the most efficient until 10,000,000 as there
is a massive change in gradient from 10,000,000 onwards, The rate of growth of this
function increases nearly by a squared of what it was before, which is also reflected
by the BigO notation.
This algorithm is one of the most efficient algorithms of the common algorithms I
have seen, I have looked up why mathematically it is more efficient, it is because it
only divides by the square root of the limit of the prime number and not by every
number in the limit. It does not loop around the values of the limit twice, but the
square root of it. By what it seems, this algorithm looks like an algorithm that could
be used with the sole purpose of generating prime numbers. I had considered this
algorithm because it was one I had created myself using Mathematical concepts of
square roots.
The third prime number generator algorithm
18

The last algorithm I had chosen wasnt initially written in Java, but was by a Greek
mathematician, named Eratosthenes. This algorithm is called the Sieve of
Eratosthenes
19
, and sourced by the University of Tennessee Martin it is one of the
most efficient ways of generating small prime numbers (generating prime numbers
below 10,000,000 prime numbers). The algorithm is pretty simple, it creates a list of
the integers from 2 to n, n meaning the max number you input for the program, and
has a counter called p which is set as 2 (the first number). Then it starts from p and
goes up in increments of p and marks each number that is greater than p itself, and
some of them will already be marked. It will then find the number that is greater than
p that hasnt been marked, and now this number will be p. Then when p becomes

17
Using WolframAlpha, I generated this graph, using the function:
ListPlot[{{100000,0.292},{500000,1.82},{1000000,4.78},{5000000,36.4},{1000000
0,119},{20000000,393}}]
18
The data obtained below is summarized. The algorithm for the function is given in
Appendix 1.3
19
Chris. K, 2010 Sieve of Eratosthenes,
http://primes.utm.edu/glossary/page.php?sort=SieveOfEratosthenes, (accessed: 10
th

August 2011)


12


greater than n it stops and terminates the algorithm. And the numbers we are left with
which are unmarked are the prime numbers.
The efficiency of this algorithm in general (not the java version) is O(n(log n)log log
n), which is incredible the BigO would be very efficient, however the code of the
algorithm has a BigO efficiency of BigO(

), which is very large compared to the


efficiency of the concept. I have also found that for this algorithm the problem is not
the speed but the space it takes, the efficiency of it using more storage is (O(n)). If the
code of this algorithm was to have the efficiency of O(n(log n)log log n) the
generation time would decrease by at least a 1/5
th
of what it is right now. The graph of
the the efficency is below, so when we calculate the graph for the amount of time vs
the amount of prime numbers generated I predict we will be able to see a similar trend
in the graphing. The Figure 5
20
shows the graph of the efficiency O(n(log n)log log n)
with only the positive real values as that's what will be consider for our results.


If we only consider the real part we can see that it starts to increase at a similar
gradient as a straight line, we will further compare this to the graph of our result.
Results
For this algorithm, I have calculated the amounts of time it takes for various different
limits of prime numbers to be generated by the program, and have plotted a graph to
see the curvature of the graph.


20
Using WolframAlpha, I generated the graph of: n(log n)(log(logn))
Figure 5 only positive values of O(n(log n)log log n)

13


Average of the 6 different limits:
21

Prime number limit Elapsed time in seconds:
100,000 0.199
500,000 0.373
1,000,000 0.753
5,000,000 10.5
10,000,000 48.9
20,000,000 193
Graph

With this I have produced a graph that shows the relationship between the limit of
prime numbers generated, or in other words the amount of prime numbers generated
with the amount of time it has taken for the prime numbers to be generated. This will
help us see the efficiency of the generations and we can calculate a relationship
between the number of prime numbers and the time it takes for this algorithm to
generate them.


Figure 6
22
shows that this algorithm is also similar to the other algorithms we have
considered above, as the algorithm shows a small change in gradient from 1,000,000
to 10,000,000 but when it increases it shows a massive change in gradient, therefore
showing that there is a change in the rate of generating these prime numbers.

21
The data obtained below is summarized. The detailed data in Tables are given in
Appendix 2.3
22
Using WolframAlpha, I generated this graph, using the function:
ListPlot[{{100000,0.199},{500000,0.373},{1000000,0.753},{5000000,10.5},{10000
000,48.9},{20000000,193} }
Figure 6 Compiled from the averages of the 6
different limits


14


If we compare Figure 5 to Figure 6, we can reinforce that the efficiency of the code of
the algorithm isnt O(n(log n)log log n) but closer to

as the gradient of Figure 5


doesnt change as much as it does in Figure 6. However, there is a similarity between
the two graphs, which suggests that although the efficiency is different, there are other
factors that influence the generation but the efficiency of the algorithm.
Comparison of these algorithms
If we compare these algorithms in a table, we will be able to see the differences
in the efficiency and the BigO notations of these algorithms. Firstly I will
compare these algorithms using the graphs that they had produced.
We can see that they nearly follow the same trend of increasing, and the shape that the
curve increases. However, when I look at the y-axis of the graphs, I can see the major
differences in how long it takes for them to produce this result. Interestingly, if we
compare the 3
rd
algorithm to the 1
st
algorithm, on average the third algorithm is 40
times less efficient (

to generate

results).

0
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
5 6 6 7 7 7
Algorithm 1
Algorithm 2
Algorithm 3
Algorithm 1
Algorithm 2 Algorithm 3
Figure 7 Compiled from the all the results of the three
algorithms

15


Now if we actually more the time it took for each limit specially we can compare
these algorithms in much more depth.
Algorithm 1 Algorithm 2 Algorithm 3
100,000 0.742 0.292 0.199
500,000 19.2 1.82 0.373
1,000,000 61.2 4.78 0.753
5,000,000 955 36.4 10.5
10,000,000 3035 119 48.0
20,000,000 8842 393 193

Through this data, we can see that algorithm 1 took nearly 46 times less time to
generate these prime numbers, therefore showing that Algorithm 1 is very inefficient
in generating prime numbers comparatively. However, algorithm 1 and algorithm 3
are used in different parts of computer science to generate prime numbers. Figure 7 is
a representation graphically of the time taken for all three algorithms to execute and
generate those prime number limits.
Even though the BigO notation of all these algorithms is the same, I can clearly see
that algorithm 3 is the most efficient algorithm that I have tested. Which shows that
BigO notation shouldnt be the only base in consideration of efficiency but more
factors such as time taken to generate should be considered. Graphically, if I plot
them together, we can see in Figure 7 that Algorithm 3 is the quickest algorithm to
generate these prime numbers.
Prime numbers as a threat to computer security
If we see the practical uses of algorithm 3, and the fact that this algorithm is able to
get a lot more efficient than it already is in other programming languages, we are able
to see how the practical uses of these algorithms in the future will be a safety issue for
computers around the world.


16


In 2009 there was a New Pattern Found in Prime Numbers
23
, with the research of
more patterns in mathematics, these patterns can be applied in computers, and as more
and more hackers are able to create these efficient algorithms, they will be able to
enter and compromise data of other users, even on a small scale, using these
algorithms, people are able to decrypt data from websites on the Internet and
potentially use their information, or sell that information. It is becoming a big threat,
as the World Wide Web is growing every day and more people are putting their
private information on the Internet, it is more and more important that websites and
developers around the world create algorithms that are more and more secure.
To show this data practically, I created 2 algorithms that show how these prime
number generating algorithms are able to do this, with the implementation of
algorithm 3.
Algorithm a - Encryption
This algorithm basically generates 2 very large prime numbers, in this case 9,733 and
8,831 and then multiplied them together, to make 85,952,123. Then this number is
saved in a text file with only this number inside it, we will assume that this is the
public key.
Algorithm b - Decryption
This algorithm basically does the opposite of that algorithm and tries to decrypt the
public key that we had found earlier; firstly it reads the public key from the file and
then saves it in a variable in the program. Then it basically uses 2 for loops to loop
through prime numbers and multiplies them together until it equals the public key
from the other text files, and then when it equals this public key, it outputs how long it
took for it to decrypt the public key.
The average in the table
24
shows that it takes 305 seconds to decrypt the number
85,952,123, if we put this into prospective, even though we have used small numbers
in this example, we still have to consider that we have used a computer that is in the
average specs, and with a more powerful computer, or a grid computer system this

23
Lisa. Z, 2009 New Patterns Found in Prime Numbers,
http://www.physorg.com/news160994102.html, (accessed: 15
th
September 2011)
24
The data obtained below is summarized. The detailed data in Tables are given in
Appendix 2.4

17


process would take place in milliseconds. And with more efficient algorithms to be
able to decrypt this, it is possible to crack very big prime numbers, and as technology
grows and computers get faster, it is easier to brute force into computer systems over
the world.
Conclusion
As shown by my research, as prime number generation becomes more efficient the
decryption techniques will also get more efficient with it, and therefore the risk to
individuals will grow. The RSA algorithm, and many other algorithms are updated
every year to allow this growth to happen and they are strengthened. Supported by my
data, I believe that as prime numbers generating algorithms increase in efficiency, the
decryption methods, such as the RSA will also get more and more secure, also
reflected by the number of prime number hacking cases around the world.
My research suggests that there is a direct and positive correlation between the
efficiency of prime number generators and the security of encryption methods, as
prime number generators get more efficient, the encryption methods get more secure
and therefore the security of the computer increases, and therefore there is a self
balancing relationship. However this relationship only holds to the extent of the
discovery of Quantum Turing Computers.
The limitations I had while doing this Extended Essay, was that I wasnt able to
gather data from grid computers or supercomputers and compare it to data of average
Turing machines in order to see the difference in processing speed, this would have
helped me to strengthen my conclusion and my research. Moreover, in doing this
research it had brought up more questions, and queries which I would want to
research in the future. For example, to what extent will Quantum Computers make the
encryption and decryption methods using prime numbers obsolete? I wasnt sure of
how much effect would the production of Quantum Computers, which is equivalent in
power to a modern day computer do to cryptography methods.
Lastly, to sum up, Bill Gates once said that Computers are only secure until a major
breakthrough in Math or Computing, it is more likely that this breakthrough would
more likely come in Computing, and I believe this is what will happen.


18


Bibliography
Chris K. Caldwell. (2010). Sieve of Eratosthenes. Available:
http://primes.utm.edu/glossary/page.php?sort=SieveOfEratosthenes. Last accessed
10th August 2011.
David Ireland. (2011). RSA Algorithm. Available: http://www.di-
mgt.com.au/rsa_alg.html. Last accessed 3 November 2011.
The Eclipse Foundation. (2011). Eclipse. Available: The Eclipse Foundation. Last
accessed 20th October 2011.
Jerry Crow. (2003). Prime Numbers in Public Key Cryptography. Available:
http://www.sans.org/reading_room/whitepapers/vpns/prime-numbers-public-key-
cryptography_969. Last accessed 7th August 2011.
Kristin Lauter. (2010). A Primer on Cryptography. Available:
http://research.microsoft.com/en-us/groups/crypto/firstcrypto.aspx. Last accessed 20th
Aug 2011.
Lisa Zyga. (2009). New Pattern Found in Prime Numbers. Available:
http://www.physorg.com/news160994102.html. Last accessed 15th September 2011.
Michael P. Cummings. (2005). Grid Computing. Available:
http://net.educause.edu/ir/library/pdf/ERM05612.pdf. Last accessed 7th October 2011.
Oracle. (2011). Java SE Downloads. Available:
http://www.oracle.com/technetwork/java/javase/downloads/index.html. Last accessed
20th October 2011.
Paul Johnson. (2010). RSA Algorithm. Available:
http://pajhome.org.uk/crypt/rsa/rsa.html. Last accessed 10th October 2011.
Tom Wu. (2009). Number Theory. Available: http://www-cs-
students.stanford.edu/~tjw/primes.html. Last accessed 8th Aug 2011.
Weisstein, Eric W. (2011). Prime Number. Available:
http://mathworld.wolfram.com/PrimeNumber.html. Last accessed 24th Aug 2011.

19


Wolfram. (2011). WolframAlpha. Available: http://www.wolframalpha.com/. Last
accessed 10th November 2011.
Appendix
Appendix 1.1
25


int max = 20000000;
List<Integer> ab = generatePrimes(max);

System.out.print(((Object) ab).toString());

public static List<Integer> generatePrimes(int max)
{

List<Integer> primes = new ArrayList<Integer>();

// start from 2
OUTERLOOP:
for (int i = 2; i <= max; i++) {
// try to divide it by all known primes
for (Integer p : primes)
if (i % p == 0)
continue OUTERLOOP; // i is not prime

// i is prime
primes.add(i);
}
return primes;
}

Appendix 1.2
public static void main(String[] args) {
StopWatch s = new StopWatch();
s.start();

Boolean isPrime;
isPrime = true;
int x, y = 0; {

for(x=2; x<= 20000000; x++) {
for(y=2; y<= sqrt(x); y++)
{
if(x%y < 1) {
isPrime = false;
}
}
if (isPrime == true) {
System.out.print(x + " ,");

25
The source of this Algorithm is:
http://en.wikibooks.org/wiki/Algorithm_Implementation/Mathematics/Prime_
number_generation?&lang=en_us&output=json


20


}
isPrime = true;
}
}

Appendix 1.3
26

int max = 20000000;
boolean[] isComposite = new boolean[max + 1];
for (int i = 2; i * i <= max; i++) {
if (!isComposite [i]) {
for (int j = i; i * j <= max; j++) {
isComposite [i*j] = true;
}
}
}
int numPrimes = 0;
for (int i = 2; i <= max; i++) {
if (!isComposite [i]) numPrimes++;
}
int [] primes = new int [numPrimes];
int index = 0;
for (int i = 2; i <= max; i++) {
if (!isComposite [i]) primes [index++] = i;

}
int e;
for(e = 0; e<primes.length; e++)
{
System.out.print(primes[e]);
System.out.print(" ");
}












26
The source of this algorithm is:
http://stackoverflow.com/questions/586284/finding-prime-numbers-with-the-
sieve-of-eratosthenes-originally-is-there-a-bet?&lang=en_us&output=json

21


Appendix 2.1

Average of 100,000 as the limit
Test Number Elapsed time in seconds:
1 0.706
2 0.776
3 0.734
4 0.757
5 0.739
Average 0.742

Average of 500,000 as the limit
Test Number Elapsed time in seconds:
1 20.0
2 21.4
3 18.8
4 19.1
5 16.6
Average 19.2

Average of 1,000,000 as the limit
Test Number Elapsed time in seconds:
1 58.5
2 64.0
3 62.2
4 61.4
5 59.7
Average 61.2

Average of 5,000,000 as the limit
Test Number Elapsed time in seconds:
1 981
2 906
3 952
4 948
5 990
Average 955

Average of 10,00,000 as the limit


22


Test Number Elapsed time in seconds:
1 3001
2 2993
3 3045
4 3056
5 3082
Average 3035



Average of 20,000,000 as the limit
Test Number Elapsed time in seconds:
1 8954
2 8890
3 9020
4 8623
5 8724
Average 8842

Appendix 2.2

Average of 100,000 as the limit
Test Number Elapsed time in milliseconds:
1 0.257
2 0.301
3 0.314
4 0.294
5 0.293
Average 0.292

Average of 500,000 as the limit
Test Number Elapsed time in seconds:
1 1.77
2 1.74
3 1.78
4 1.84
5 1.96
Average 1.82


23


Average of 1,000,000 as the limit
Test Number Elapsed time in seconds:
1 4.67
2 4.63
3 5.10
4 4.96
5 4.54
Average 4.78


Average of 5,000,000 as the limit
Test Number Elapsed time in seconds:
1 36.1
2 39.0
3 34.7
4 32.0
5 40.0
Average 36.4

Average of 10,00,000 as the limit
Test Number Elapsed time in seconds:
1 117
2 125
3 119
4 114
5 120
Average 119

Average of 20,000,000 as the limit
Test Number Elapsed time in seconds:
1 396
2 414
3 364
4 402
5 387
Average 393



24


Appendix 2.3

Average of 100,000 as the limit
Test Number Elapsed time in seconds:
1 0.204
2 0.191
3 0.204
4 0.197
5 0.200
Average 0.199


Average of 5000,000 as the limit
Test Number Elapsed time in seconds:
1 0.373
2 0.365
3 0.377
4 0.377
5 0.372
Average 0.373

Average of 1,000,000 as the limit
Test Number Elapsed time in seconds:
1 0.739
2 0.701
3 0.735
4 0.769
5 0.820
Average 0.753

Average of 5,00,000 as the limit
Test Number Elapsed time in seconds:
1 10.4
2 10.6
3 10.4
4 10.5
5 10.8
Average 10.5

25




Average of 10,00,000 as the limit
Test Number Elapsed time in seconds:
1 47.0
2 48.0
3 50.8
4 52.4
5 46.5
Average 48.9


Average of 20,00,000 as the limit
Test Number Elapsed time in seconds:
1 195
2 185
3 200
4 190
5 195
Average 193

Appendix 2.4
Results for decryption (Using Algorithm 3 as the for loops)
Test Number Elapsed time in seconds:
1 304
2 302
3 312
4 298
5 309
Average 305

You might also like