Sei sulla pagina 1di 15

Cryptography in Context

Nathaniel Karst

November 19, 2014

Preface

It is safe to say that the world as we know it could exist without modern commu- nication systems. But from online credit card transactions to secure messages between organizations and their agents, these technologies allow us to trust each other in an increasingly digital world. In these notes, we will begin to un- pack these technologies, from both mathematical and practical perspective. You will have the opportunity to implement many of these communication protocols yourself, and in so doing, hopefully gain a deeper understanding and apprecia- tion for the underlying ideas. We will regularly confront the ethical issues that arise at the interface of these theoretic tools and their real world implementa- tion, as the use and abuse of modern cryptography has serious implications for the trajectory of our society.

How To Use These Notes

Content areas are intended to be relatively stand-alone. Each content area discusses the overall idea behind the topic, and then proceeds to Matlab im- plementation. (While I have not thoroughly tested it, Octave should work as a good substitute.) Each content area has associated studio problems located in Appendix A. These problems are intended to be started in class with the help of

an instructor and completed outside class. The solutions for studio problems are located in Appendix B. Teaching notes for instructors, including learning ob- jectives and discussion questions where appropriate, are including in Appendix

C.

Acknowledgements

I would like to thank the Teaching Innovation Fund at Babson College for sup- porting the development of these notes and exercises. My thanks also goes to the Spring 2014 cohort of Cryptology and Coding Theory for its help in molding these notes for general consumption.

i

Chapter 0.

Preface

Contents

Preface

i

1 Introduction

1

1.1 Communication Systems

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

2

1.1.1 Compression

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

2

1.1.2 Encryption

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

3

1.1.3 Protection .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

4

1.1.4 Representations of Data .

.

1.2 Matlab .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

4

6

1.2.1 Basic Arithmetic

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6

1.2.2 Variable Assignment

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

6

1.2.3

Arrays .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

7

1.2.4

Scripts and Functions

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

9

1.2.5

Loops

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

9

1.2.6

Provided Functions .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

10

2 Classical Cryptosystems

 

13

2.1 Transposition Ciphers

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

14

2.1.1 Scytales to Matrices

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

14

2.1.2 Encryption in Matlab

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

15

2.1.3 Decryption in Matlab

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

19

2.1.4 Cryptanalysis

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

19

2.2 Caesar Ciphers

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

21

2.2.1 Caesar Encryption and Modular Arithmetic

 

.

.

21

2.2.2 Caesar Decryption and Additive Inverses

 

.

.

.

.

.

.

.

.

.

23

2.2.3 Groups

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

23

2.2.4 Caesar Cryptanalysis

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

24

2.3 Affine Ciphers .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

27

2.3.1 Affine Encryption

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

27

2.3.2 Affine Decryption and Multiplicative Inverses

 

27

2.3.3 Rings

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

28

 

iii

 

Contents

2.3.4

Affine Cryptanalysis

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

32

2.4

Polyalphabetic Ciphers

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

34

2.4.1 Encryption

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

34

Decryption

2.4.2 .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

35

2.4.3 Cryptanalysis

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

35

2.4.4 Polyalphabetic Variants

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

38

3

Modern Cryptosystems

41

3.1 Diffie-Hellman Key Exchange

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

42

3.1.1

Primitive Roots

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

42

3.1.2

Key Exchange

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

43

3.1.3

3.1.4

3.2 RSA

Matlab Implementation

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

44

Man-in-the-middle Attacks .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

46

47

3.2.1 Encryption

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

49

3.2.2 Decryption

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

50

3.2.3

Security

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

50

3.3 Cryptographic Hashes

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

51

3.3.1 Properties .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

52

3.3.2 Applications

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

53

3.3.3 Cryptanalysis .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

54

3.4 Digital Signatures

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

57

3.4.1 RSA-based Signature Scheme

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

57

3.4.2 DLP-based Signature Scheme

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

59

3.5 Zero-Knowledge Proofs

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

63

3.5.1 Schnorr Authentication

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

64

3.5.2 Feige-Fiat-Shamir Authentication .

.

.

.

.

.

.

.

.

.

.

.

.

.

66

3.6 Ethics in Cryptography

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

69

3.6.1 Obligations to Customers

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

69

3.6.2 Utility of Hacking

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

70

3.6.3 What to do with a break-through .

.

.

.

.

.

.

.

.

.

.

.

.

.

71

Appendix A Studio problems

73

A.1

Studio 1.1: Communication Systems

 

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

74

A.2

Studio 1.2: Matlab

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

75

A.3

Studio 2.1: Transposition Ciphers .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

76

A.4

A.5

Studio 2.2: Caesar Ciphers

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

77

Studio 2.3: Affine Ciphers

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

79

A.6

Studio 2.4: Polyalphabetic Ciphers

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

82

A.7

Studio 3.1: Diffie-Hellman

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

84

A.8

Studio 3.2: RSA

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

85

A.9

Studio 3.3: Cryptographic Hashes .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

87

. A.11 Studio 3.5: Zero-Knowledge Proofs

A.10 Studio 3.4: Digital Signatures

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

89

93

Contents

Appendix B Studio solutions

95

B.1

Studio 1.1 Solutions: Communication Systems .

.

.

.

.

.

.

.

.

.

.

96

B.2

Studio 1.2 Solutions: Matlab

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

98

B.3

Studio 2.1 Solutions: Transposition Ciphers

.

.

.

.

.

.

.

.

.

.

.

.

100

B.4

B.5

Studio 2.2 Solutions: Caesar Ciphers

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

103

Studio 2.3 Solutions: Affine Ciphers

.

.

.

.

.

.

.

.

.

.

.

.

.

106

B.6

Studio 2.4 Solutions: Polyalphabetic Ciphers

.

.

.

.

.

.

.

.

.

.

.

110

B.7

Studio 3.1 Solutions: Diffie-Hellman

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

112

B.8

Studio 3.2 Solutions: RSA .

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

115

B.9

Studio 3.3 Solutions: Cryptographic Hashes

.

.

.

.

.

.

.

.

.

.

.

.

118

. B.11 Studio 3.5 Solutions: Zero-Knowledge Proofs

B.10 Studio 3.4 Solutions: Digital Signatures

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

121

128

Appendix C Teaching Notes

131

C.1

C.2

Teaching Note 1.1: Communication Systems

Teaching Note 1.2: Matlab

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

132

133

C.3

. Teaching Note 2.1: Transposition Ciphers

.

.

.

.

.

.

.

.

.

.

.

.

.

134

C.4

C.5

Teaching Note 2.2: Caesar Ciphers

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

135

Teaching Note 2.3: Affine Ciphers

.

.

.

.

.

.

.

.

.

.

.

.

.

136

C.6

Teaching Note 2.4: Polyalphabetic Ciphers

.

.

.

.

.

.

.

.

.

.

.

.

137

C.7

Teaching Note 3.1: Diffie-Hellman

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

138

C.8

Teaching Note 3.2: RSA

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

139

C.9

Teaching Note 3.3: Cryptographic Hashes

.

.

.

.

.

.

.