An Investigation Into Mathematical Cryptography with Applications
Total Page:16
File Type:pdf, Size:1020Kb
Project Report BSc (Hons) Mathematics An Investigation into Mathematical Cryptography with Applications Samuel Worton 1 CONTENTS Page: 1. Summary 3 2. Introduction to Cryptography 4 3. A History of Cryptography 6 4. Introduction to Modular Arithmetic 12 5. Caesar Cipher 16 6. Affine Cipher 17 7. Vigenère Cipher 19 8. Autokey Cipher 21 9. One-Time Pad 22 10. Pohlig-Hellman Encryption 24 11. RSA Encryption 27 12. MATLAB 30 13. Conclusion 35 14. Glossary 36 15. References 38 2 1. SUMMARY AND ACKNOWLEDGEMENTS In this report, I will explore the history of cryptography, looking at the origins of cryptosystems in the BC years all the way through to the current RSA cryptosystem which governs the digital era we live in. I will explain the mathematics behind cryptography and cryptanalysis, which is largely based around number theory and in particular, modular arithmetic. I will relate this to several famous, important and relevant cryptosystems, and finally I will use the MATLAB program to write codes for a few of these cryptosystems. I would like to thank Mr. Kuldeep Singh for his feedback and advice during all stages of my report, as well as enthusiasm towards the subject. I would also like to thank Mr. Laurence Taylor for generously giving his time to help me in understanding and producing the MATLAB coding used towards the end of this investigation. Throughout this report I have been aided by the book ‘Elementary Number Theory’ by Mr. David M. Burton, amongst others, which was highly useful in refreshing my number theory knowledge and introducing me to the concepts of cryptography; also Mr. Kuldeep Singh’s ‘Maths For All’ website for the same reasons. I hope you find this investigation very interesting and stimulating, as I did while producing it. 3 2. INTRODUCTION TO CRYPTOGRAPHY For as long as forms of communication have existed, there has always been a need to protect and secure information, from the sender to the recipient, without external parties being able to receive any of the information. Cryptography is the study into this field of protecting information, typically in the form of a message. Let’s begin with an example of this: Suppose two people, Alice and Bob, are exchanging messages over the internet. These messages are private between the two of them, so nobody or nothing else should be able to access or alter the information in the messages (this is known as eavesdropping). When Alice types a message to Bob, this is called plaintext – it is the information which is intended for Bob. When she sends the message, it is encrypted by a key which transforms the information into ciphertext – it has no clear relation to the original plaintext, and generally makes no sense. Once Bob receives the ciphertext, he can use a key (often the same key that Alice used) in order to decrypt the ciphertext and revert it back to plaintext, containing the original information that Alice wanted to send. The algorithm of using a key to encrypt and decrypt a message is known as a cipher, and altogether with the plaintext and ciphertext, we have a cryptosystem. FIGURE 1 – A DIAGRAM OF A TYPICAL CRYPTOSYSTEM (CETEF, 2013) As aforementioned, there are cases when the keys used in the cipher can be the same or different: • If the keys are the same (i.e. �f = �h), then the cipher is symmetric or private. This is because the key is symmetric between both parties, and must remain private between them to avoid the information being revealed to eavesdroppers. Both the sender and receiver need to know the key in advance for the system to work. This can be unpractical, as the two parties may not be able to securely share a key without another party gaining this information. • If the keys are different (i.e. �f ≠ �h), then the cipher is asymmetric or public. A user of such a cryptosystem creates a public key (�f) for encryption, and a private key (�h) for decryption, which is kept secret. Someone can then encrypt a message using the public key, and the recipient would decrypt with the private key. The two keys are mathematically related, but in such a way that calculating the decryption key from knowledge of the encryption key is unfeasible, making it a secure way to transfer information. 4 Ciphers and codes are closely related and are often used as synonyms for one another, in reference to encryption of a message. There is a difference between the two in practice, however. Ciphers are the encryption of individual or small groups of letters, whereas codes encrypt words or phrases wholly. For example, a cipher could replace ‘RUN’ with ‘QTM’, where each individual letter has been altered; a code could substitute ‘RUN’ with ‘RHYTHM UNDER NIGHTFALL’ – a new phrase has been introduced which disguises the real message. Codes require codebooks to list the codes and the words/phrases they encrypt. Ciphers do not require a codebook and so they have made codes redundant in modern cryptography. In this report I will not analyse any code-based cryptosystems. Cryptanalysis is the antithesis of cryptography – namely, it is the study of breaking ciphers and the techniques used to do so. Cryptanalysts will study ciphers and cryptosystems tirelessly to find any weaknesses in the system that could reveal parts or all of the plaintext information. This is usually done without any prior knowledge of the key or algorithm. Cryptographic methods have advanced over time, and naturally, cryptanalysis has too – each time a new encryption algorithm is developed, cryptanalysts work on deciphering the cryptosystem, resulting in newer, stronger algorithms being formed, and so on. The cycle between the creation of algorithms and breaking of systems repeats continuously and will most likely repeat for a very long time (Thawte, 2013). Cryptography is not only limited to exchanging messages. In recent years it has advanced prodigiously with the expansion of the internet and digital services, so that it is now a fundamental part of online banking and shopping, authentication and ATM cards, to name a few. Technology is always developing, and so the need for secure ways to encrypt information is fundamental to protect users from hackers and other malevolent parties. This makes cryptography a fast-growing subject in the current day and age. What was once perceived as an art in the field of linguistics has developed vastly to mathematics and computer science. 5 3. A HISTORY OF CRYPTOGRAPHY Whilst the study of cryptography has expanded in recent times with the increasing need for privacy and protection of data, the art of encrypting messages and secrets has existed for thousands of years. As a result, the term ‘classical cryptography’ has been created to encompass the origins of the field, where such cryptosystems were very simple - compared to modern systems - and were typically designed and implemented by hand. During this time there were two predominant types of ciphers: • Substitution cipher – plaintext characters are systematically replaced with other letters, numbers or symbols to create a ciphertext, but the order of the characters is not altered. Substitution ciphers can be separated into two different categories: o Monoalphabetic cipher – only one cipher alphabet is used for substitution, so each letter in the plaintext alphabet only has one encryption character. Once the key has been found, decryption becomes a simple task. o Polyalphabetic cipher – more than one cipher alphabet is used, so a character in the plaintext can be represented by more than one character in the plaintext, making it a much more secure form of encryption. • Transposition cipher – characters in the plaintext are rearranged in different orders or patterns, so the ciphertext is a permutation of the original characters, which remain unchanged. If the permutation can be found out, decryption only requires rearranging the ciphertext back into the plaintext. The word cryptography is derived from the Greek words ‘kryptos’ and ‘graphein’, which mean ‘hidden’ and ‘writing’ respectively. Ancient Greece was one of the first regions to record a recognisable cryptosystem, along with Ancient Rome (Damico, 2009). In Ancient Greece, a ‘scytale’ (pronounced ski-tah-lay) was one of the earliest forms of a cryptosystem. A ribbon was wrapped around a stick of a certain diameter with a message on the ribbon that could only be read while the ribbon was on the stick; once unravelled the letters on the ribbon would read as nonsense. The key was essentially a stick of the same diameter so both the sender and recipient could decipher the message. FIGURE 2 – AN ANCIENT GREEK SCYTALE This is an example of a transposition cipher (McCullough, 2003). Julius Caesar, the Roman emperor of the 1st century BC, developed a cipher so he could send messages of military and political importance to other members of the Roman Empire. He did this to reduce the risk of the message being intercepted and understood by enemies. The algorithm of the cipher was a simple shift substitution, which at the time was secure enough to protect military information; however, Caesar abandoned it soon after (Burton, 2011). 6 As centuries passed and more people worldwide became literate, cryptosystems began to improve. Leon Battista Alberti created one of the first polyalphabetic ciphers and cipher machines in the 15th century, by designing a cipher disk (known as the Formula) made up of two concentric disks; the outermost containing the plaintext alphabet and the innermost containing the ciphertext equivalent. The inner disk was rotated by a fixed system so that the plaintext characters had more than one representation in the ciphertext – at the time it was deemed unbreakable, since it was resistant to monoalphabetic decryption methods, and without knowledge of the cryptosystem itself, nobody would realise that a polyalphabetic system FIGURE 3 – THE ‘FORMULA’ was used (Kahn, 1967).