Learning and Experiencing Cryptography With Cryptool and Sagemath by Bernhard Esslinger
Learning and Experiencing Cryptography With Cryptool and Sagemath by Bernhard Esslinger
Esslinger
Learning and Experiencing Cryptography with CrypTool and SageMath presents
a broad overview of classic and modern cryptography and encourages you
to actively try out cryptography experiments and simulations using your
own data with modern open-source cryptography tools. This learn-by-doing
approach goes beyond simple teaching, showing you how to directly access
and use CrypTool (all versions), as well as the computer-algebra system (CAS)
SageMath, to derive direct feedback and results from your input.
LEARNING AND EXPERIENCING
CRYPTOGRAPHY WITH
ISBN: 978-1-68569-017-5
ARTECH HOUSE
BOSTON I LONDON
www.artechhouse.com
i i
i i
i i
i i
i i
i i
Bernhard Esslinger
i i
i i
i i
ISBN 978-1-68569-017-5
All rights reserved. Printed and bound in the United States of America. No part of this book
may be reproduced or utilized in any form or by any means, electronic or mechanical, including
photocopying, recording, or by any information storage and retrieval system, without permission
in writing from the publisher.
All terms mentioned in this book that are known to be trademarks or service marks have
been appropriately capitalized. Artech House cannot attest to the accuracy of this information.
Use of a term in this book should not be regarded as affecting the validity of any trademark or
service mark.
10 9 8 7 6 5 4 3 2 1
i i
i i
i i
CHAPTER 0
CHAPTER 0
Contents
Preface xv
Acknowledgments xix
Introduction xxi
CHAPTER 1
Ciphers and Attacks Against Them 1
1.1 Importance of Cryptology 2
1.2 Symmetric Encryption 2
1.2.1 AES 4
1.2.2 Current Status of Brute-Force Attacks on Symmetric Algorithms 4
1.3 Asymmetric Encryption 5
1.4 Hybrid Procedures 7
1.5 Kerckhoffs’ Principle 7
1.6 Key Spaces: A Theoretical and Practical View 8
1.6.1 Key Spaces of Historic Cipher Devices 8
1.6.2 Which Key Space Assumptions Should Be Used 11
1.6.3 Conclusion of Key Spaces of Historic Cipher Devices 13
1.7 Best Known Attacks on Given Ciphers 14
1.7.1 Best Known Attacks Against Classical Ciphers 15
1.7.2 Best Known Attacks Against Modern Ciphers 15
1.8 Attack Types and Security Definitions 16
1.8.1 Attack Parameters 16
1.8.2 Indistinguishability Security Definitions 20
1.8.3 Security Definitions 21
1.9 Algorithm Types and Self-Made Ciphers 24
1.9.1 Types of Algorithms 24
1.9.2 New Algorithms 24
1.10 Further References and Recommended Resources 24
1.11 AES Visualizations/Implementations 25
1.11.1 AES Animation in CTO 26
1.11.2 AES in CT2 26
1.11.3 AES with OpenSSL at the Command Line of the Operating
System 28
1.11.4 AES with OpenSSL within CTO 29
1.12 Educational Examples for Symmetric Ciphers Using SageMath 29
i i
i i
i i
vi Contents
1.12.1 Mini-AES 29
1.12.2 Symmetric Ciphers for Educational Purposes 32
References 32
CHAPTER 2
Paper-and-Pencil and Precomputer Ciphers 39
2.1 Transposition Ciphers 40
2.1.1 Introductory Samples of Different Transposition Ciphers 40
2.1.2 Column and Row Transposition 42
2.1.3 Further Transposition Algorithm Ciphers 43
2.2 Substitution Ciphers 45
2.2.1 Monoalphabetic Substitution 45
2.2.2 Homophonic Substitution 50
2.2.3 Polygraphic Substitution 51
2.2.4 Polyalphabetic Substitution 53
2.3 Combining Substitution and Transposition 56
2.4 Further P&P Methods 60
2.5 Hagelin Machines as Models for Precomputer Ciphers 63
2.5.1 Overview of Early Hagelin Cipher Machines 63
2.5.2 Hagelin C-52/CX-52 Models 65
2.5.3 Hagelin Component in CT2 71
2.5.4 Recap on C(X)-52: Evolution and Influence 72
2.6 Ciphers Defined by the American Cryptogram Association 73
2.7 Examples of Open-Access Publications on Cracking Classical Ciphers 74
2.8 Examples Using SageMath 74
2.8.1 Transposition Ciphers 76
2.8.2 Substitution Ciphers 80
2.8.3 Cryptanalysis of Classical Ciphers with SageMath 91
References 94
CHAPTER 3
Historical Cryptology 97
3.1 Introduction 97
3.2 Analyzing Historical Ciphers: From Collection to Interpretation 103
3.3 Collection of Manuscripts and Creation of Metadata 106
3.4 Transcription 109
3.4.1 Manual Transcription 109
3.4.2 CTTS: Offline Tool for Manual Transcription 114
3.4.3 Automatic Transcription 115
3.4.4 The Future of Automatic Transcription 119
3.5 Cryptanalysis 120
3.5.1 Tokenization 120
3.5.2 Heuristic Algorithms for Cryptanalysis 121
3.5.3 Cost Functions 129
3.6 Contextualization and Interpretation: Historical and Philological
Analysis 131
i i
i i
i i
Contents vii
CHAPTER 4
Prime Numbers 139
4.1 What Are Prime Numbers? 139
4.2 Prime Numbers in Mathematics 140
4.3 How Many Prime Numbers Are There? 143
4.4 The Search for Extremely Large Primes 144
4.4.1 The 20+ Largest Known Primes 144
4.4.2 Special Number Types: Mersenne Numbers and Mersenne
Primes 144
4.4.3 Challenge of the Electronic Frontier Foundation 150
4.5 Prime Number Tests 150
4.5.1 Special Properties of Primes for Tests 151
4.5.2 Pseudoprime Numbers 152
4.6 Special Types of Numbers and the Search for a Formula for Primes 155
4.6.1 Mersenne Numbers f (n ) = 2n − 1 for n Prime 156
4.6.2 Generalized Mersenne Numbers f (k, n ) = k · 2n ± 1 for n Prime
and k Small Prime/Proth Numbers 156
4.6.3 Generalized Mersenne Numbers f (b, n ) = bn ± 1 / The
Cunningham Project 156
n
4.6.4 Fermat Numbers Fn = f (n ) = 22 + 1 156
n
4.6.5 Generalized Fermat Numbers f (b, n ) = b2 + 1 157
4.6.6 Idea Based on Euclid’s Proof: p1 · p2 · . . . · pn + 1 158
4.6.7 As Above but −1 except +1: p1 · p2 · . . . · pn − 1 158
4.6.8 Euclid Numbers en = e0 · e1 · . . . · en−1 + 1 with n ≥ 1
and e0 := 1 158
4.6.9 f (n ) = n 2 + n + 41 159
4.6.10 f (n ) = n 2 − 79n + 1601 and Heegner Numbers 160
4.6.11 Polynomial Functions f (x ) = an x n + an−1 x n−1 + · · · + a1 x 1
+ a0 (ai ∈ Z, n ≥ 1) 161
4.6.12 Catalan’s Mersenne Conjecture 161
4.6.13 Double Mersenne Primes 162
4.7 Density and Distribution of the Primes 163
4.8 Outlook 165
4.8.1 Further Interesting Topics Regarding Prime Numbers 166
4.9 Notes about Primes 166
4.9.1 Proven Statements and Theorems about Primes 166
4.9.2 Arithmetic Prime Sequences 167
4.9.3 Unproven Statements, Conjectures, and Open Questions about
Primes 170
4.9.4 The Goldbach Conjecture 171
4.9.5 Open Questions about Twin Primes 173
i i
i i
i i
viii Contents
CHAPTER 5
Introduction to Elementary Number Theory with Examples 195
5.1 Mathematics and Cryptography 195
5.2 Introduction to Number Theory 196
5.2.1 Convention and Notation 197
5.3 Prime Numbers and the First Fundamental Theorem of Elementary
Number Theory 199
5.4 Divisibility, Modulus and Remainder Classes 201
5.4.1 Divisibility 201
5.4.2 The Modulo Operation: Working with Congruences 203
5.5 Calculations with Finite Sets 206
5.5.1 Laws of Modular Calculations 206
5.5.2 Patterns and Structures (Part 1) 207
5.6 Examples of Modular Calculations 207
5.6.1 Addition and Multiplication 208
5.6.2 Additive and Multiplicative Inverses 208
5.6.3 Raising to the Power 211
5.6.4 Fast Calculation of High Powers (Square and Multiply) 213
5.6.5 Roots and Logarithms 214
5.7 Groups and Modular Arithmetic in Zn and Z∗n 215
5.7.1 Addition in a Group 215
5.7.2 Multiplication in a Group 216
5.8 Euler Function, Fermat’s Little Theorem, and Euler-Fermat 217
5.8.1 Patterns and Structures (Part 2) 217
5.8.2 The Euler Phi Function 218
5.8.3 The Theorem of Euler-Fermat 219
5.8.4 Calculation of the Multiplicative Inverse 221
5.8.5 How Many Private RSA Keys d Are There in Modulo 26 222
5.9 Multiplicative Order and Primitive Roots 224
5.10 Proof of the RSA Procedure with Euler-Fermat 229
5.10.1 Basic Idea of Public-Key Cryptography and Requirements for
Encryption Systems 229
5.10.2 How the RSA Procedure Works 230
i i
i i
i i
Contents ix
CHAPTER 6
The Mathematical Ideas Behind Modern Asymmetric Cryptography 301
6.1 One-Way Functions with Trapdoor and Complexity Classes 301
6.2 Knapsack Problem as a Basis for Public-Key Procedures 303
6.2.1 Knapsack Problem 303
6.2.2 Merkle-Hellman Knapsack Encryption 304
6.3 Decomposition into Prime Factors as a Basis for Public-Key Procedures 305
i i
i i
i i
x Contents
CHAPTER 7
Hash Functions, Digital Signatures, and Public-Key Infrastructures 361
7.1 Hash Functions 361
7.1.1 Requirements for Hash Functions 361
7.1.2 Generic Collision Attacks 362
7.1.3 Attacks Against Hash Functions Drive the Standardization
Process 362
7.1.4 Attacks on Password Hashes 364
7.2 Digital Signatures 365
7.2.1 Signing the Hash Value of the Message 366
7.3 RSA Signatures 367
7.4 DSA Signatures 367
7.5 Public-Key Certification 369
7.5.1 Impersonation Attacks 369
7.5.2 X.509 Certificate 370
7.5.3 Signature Validation and Validity Models 372
References 373
CHAPTER 8
Elliptic-Curve Cryptography 375
8.1 Elliptic-Curve Cryptography: A High-Performance Substitute
for RSA? 375
8.2 The History of Elliptic Curves 377
i i
i i
i i
Contents xi
CHAPTER 9
Foundations of Modern Symmetric Encryption 393
9.1 Boolean Functions 394
9.1.1 Bits and Their Composition 394
9.1.2 Description of Boolean Functions 395
9.1.3 The Number of Boolean Functions 396
9.1.4 Bitblocks and Boolean Functions 397
9.1.5 Logical Expressions and Conjunctive Normal Form 398
9.1.6 Polynomial Expressions and Algebraic Normal Form 399
9.1.7 Boolean Functions of Two Variables 402
9.1.8 Boolean Maps 403
9.1.9 Linear Forms and Linear Maps 404
9.1.10 Systems of Boolean Linear Equations 406
9.1.11 The Representation of Boolean Functions and Maps 411
9.2 Block Ciphers 414
9.2.1 General Description 414
9.2.2 Algebraic Cryptanalysis 415
9.2.3 The Structure of Block Ciphers 418
9.2.4 Modes of Operation 420
9.2.5 Statistical Analyses 422
9.2.6 Security Criteria for Block Ciphers 423
9.2.7 AES 424
9.2.8 Outlook on Block Ciphers 426
9.3 Stream Ciphers 427
9.3.1 XOR Encryption 427
9.3.2 Generating the Key Stream 429
i i
i i
i i
xii Contents
CHAPTER 10
Homomorphic Ciphers 467
10.1 Origin of the Term Homomorphic 467
10.2 Decryption Function Is a Homomorphism 468
10.3 Classification of Homomorphic Methods 468
10.4 Examples of Homomorphic Pre-FHE Ciphers 469
10.4.1 Paillier Cryptosystem 469
10.4.2 Other Cryptosystems 470
10.5 Applications 471
10.6 Homomorphic Methods in CrypTool 472
10.6.1 CrypTool 2 with Paillier and DGK 472
10.6.2 JCrypTool with RSA, Paillier, and Gentry/Halevi 474
10.6.3 Poll Demo in CTO Using Homomorphic Encryption 474
References 474
CHAPTER 11
Lightweight Introduction to Lattices 477
11.1 Preliminaries 477
11.2 Equations 477
11.3 Systems of Linear Equations 480
11.4 Matrices 483
11.5 Vectors 487
11.6 Equations Revisited 491
11.7 Vector Spaces 498
11.8 Lattices 503
11.8.1 Merkle-Hellman Knapsack Cryptosystem 505
11.8.2 Lattice-Based Cryptanalysis 510
11.9 Lattices and RSA 513
11.9.1 Textbook RSA 513
11.9.2 Lattices Versus RSA 517
11.10 Lattice Basis Reduction 525
i i
i i
i i
Contents xiii
CHAPTER 12
Solving Discrete Logarithms and Factoring 555
12.1 Generic Algorithms for the Discrete Logarithm Problem in
Any Group 555
12.1.1 Pollard Rho Method 556
12.1.2 Silver-Pohlig-Hellman Algorithm 556
12.1.3 How to Measure Running Times 557
12.1.4 Insecurity in the Presence of Quantum Computers 557
12.2 Best Algorithms for Prime Fields F p 558
12.2.1 An Introduction to Index Calculus Algorithms 559
12.2.2 The Number Field Sieve for Calculating the Dlog 560
12.3 Best Known Algorithms for Extension Fields F pn and Recent
Advances 562
12.3.1 The Joux-Lercier Function Field Sieve 562
12.3.2 Recent Improvements for the Function Field Sieve 563
12.3.3 Quasi-Polynomial Dlog Computation of Joux et al. 564
12.3.4 Conclusions for Finite Fields of Small Characteristic 565
12.3.5 Do These Results Transfer to Other Index Calculus Type
Algorithms? 566
12.4 Best Known Algorithms for Factoring Integers 567
12.4.1 The Number Field Sieve for Factorization 567
12.4.2 Relation to the Index Calculus Algorithm for Dlogs in F p 568
12.4.3 Integer Factorization in Practice 569
12.4.4 Relation of Key Size versus Security for Dlog in F p and
Factoring 569
12.5 Best Known Algorithms for Elliptic Curves E 571
12.5.1 The GHS Approach for Elliptic Curves E [ p n ] 571
12.5.2 The Gaudry-Semaev Algorithm for Elliptic Curves E [ p n ] 571
12.5.3 Best Known Algorithms for Elliptic Curves E [ p ] Over
Prime Fields 572
12.5.4 Relation of Key Size versus Security for Elliptic Curves E [ p ] 573
12.5.5 How to Securely Choose Elliptic Curve Parameters 574
12.6 Possibility of Embedded Backdoors in Cryptographic Keys 575
12.7 Conclusion: Advice for Cryptographic Infrastructure 576
i i
i i
i i
xiv Contents
CHAPTER 13
Future Use of Cryptography 581
13.1 Widely Used Schemes 581
13.2 Preparing for Tomorrow 583
13.3 New Mathematical Problems 584
13.4 New Signatures 585
13.5 Quantum Cryptography: A Way Out of the Dead End? 585
13.6 Post-Quantum Cryptography 585
13.7 Conclusion 586
References 587
APPENDIX A
Software 589
A.1 CrypTool 1 Menus 589
A.2 CrypTool 2 Templates and the WorkspaceManager 590
A.3 JCrypTool Functions 592
A.4 CrypTool-Online Functions 594
APPENDIX B
Miscellaneous 601
B.1 Movies and Fictional Literature with Relation to Cryptography 601
B.1.1 For Grownups and Teenagers 601
B.1.2 For Kids and Teenagers 612
B.1.3 Code for the Light Fiction Books 614
B.2 Recommended Spelling within the CrypTool Book 615
References 616
Index 621
i i
i i
i i
CHAPTER 0
CHAPTER 0
Preface
The rapid spread of the internet has led to intensified research in the technologies
involved, especially within the area of cryptography where a good deal of new
knowledge has arisen.
This book provides a thorough overview of classical and modern cryptography.
In particular, it also guides you very specifically to try it out. The CrypTool (CT)
programs are used for this purpose, as well as sample code written for the computer-
algebra system SageMath. Both CrypTool and SageMath are open-source and free.
Another special feature is the selection of topics and the clear statements for
users. On the one hand, the theory is presented, but it also emphasizes which
procedures are really reliable and which official recommendations exist where.
To our knowledge, this book contains the first concrete summary in book form
of what concrete tasks the science of historical cryptology consists of.
This book is written for both laymen and beginners, as well as for students and
practitioners who would like to delve deeper into this field. Anyone who enjoys
prime numbers or wants to know what modern lattice methods are will find very
understandable information here. For a large number of ciphers, you can find in
tabular form what are currently the best attacks on them.
The first chapter of this book explains the principles of symmetric and
asymmetric encryption and discusses definitions for their resistibility.
Because of didactic reasons the second chapter gives an exhaustive overview
of paper-and-pencil encryption methods and explains a typical example of a
precomputer machine cipher that later became embroiled in scandal.
Chapter 3 gives a comprehensive overview about historical cryptology, a new
research area, which deals with the practical problems of cryptanalyzing and
contextualizing encrypted historical documents.
A major part of this book is dedicated to the fascinating topic of prime numbers
(Chapter 4).
Then, Chapter 5 introduces modular arithmetic and elementary number theory
using numerous examples. Here, the features of the RSA procedure are a key aspect.
Chapter 6 provides insights into the mathematical ideas and concepts behind
modern asymmetric cryptography including a new geometric illustration of the
processes involved in RSA encryption.
Chapter 7 gives a very brief overview about the status of attacks against modern
hash algorithms and is then briefly devoted to digital signatures and public-key
infrastructures, which are an essential component of e-business applications.
Chapter 8 describes elliptic curves, which are an alternative cryptosystem to
RSA and are particularly well suited for use on smart cards.
xv
i i
i i
i i
xvi Preface
The programs of this book and some specific additions can be found at the
CrypTool website: https://www.cryptool.org/en/documentation/ctbook/. There are
detailed introductions to SageMath and OpenSSL with many examples. SageMath
is placed there in a broader context (LaTeX, Python, Jupyter). Another addition is
the 90-page document CUDA Tutorial – Cryptanalysis of Classical Ciphers Using
i i
i i
i i
Preface xvii
i i
i i
i i
i i
i i
i i
CHAPTER 0
CHAPTER 0
Acknowledgments
There are many people involved in the creation and publication of a comprehensive
book about cryptography.
At this point I’d like to thank explicitly the following people who in particular
contributed to the CrypTool project. They applied their very special talents and
showed really great engagement:
• Mr. Henrik Koy
• Mr. Jörg-Cornelius Schneider
• Mr. Florian Marchal
• Dr. Peer Wichmann
• Mr. Dominik Schadow
• Mr. Simon Leischnig
• Dr. Nils Kopal
• Staff of Prof. Johannes Buchmann, Prof. Claudia Eckert, Prof. Alexander
May, Prof. Torben Weis, and especially Prof. Arno Wacker
The students must be mentioned who contributed through their far over 100
bachelor’s and master’s theses. Also, I want to thank the many people not mentioned
here for their focused work (mostly carried out in their spare time).
Thanks to Bart Wessel and George Lasry for information about the differences
between the C-52/CX-52 models. Thanks to Georg Illies for pointing me to Pari-
GP. Thanks to Lars Fischer for his help with fast Pari-GP code for primitive roots.
Thanks to Volker Simon for writing the SageMath Example 5.36. Thanks to Minh
Van Nguyen from Australia for his always quick, professional, and exhaustive help
with the first SageMath code samples. It’s a pity that he is no longer reachable
… Many thanks to Klaus Pommerening, who handed over the script of his lecture
about symmetric cryptography to the CrypTool project and who shared our love
for SageMath. We then first extended his script together. Subsequently, the editor
took over Chapter 9 on his own. R.I.P. Prof. Pommerening—we lost an admirable
person.
The contributors to this book would like to take this opportunity to thank
their colleagues in the particular companies and at the universities of Bochum,
Darmstadt, Frankfurt, Gießen, Karlsruhe, Lausanne, Munich, Paris, and Siegen.
A special thank you to Dr. Doris Behrendt, who took over the laborious task
to bring two books of 500+ pages to KOMA-Script, to clean up and modernize the
TeX sources written by different authors over years, and in addition critically read
the content.
xix
i i
i i
i i
xx Acknowledgments
Thanks also to the readers who sent us feedback, and especially to Olaf
Ostwald, Helmut Witten, and Prof. Ralph-Hardo Schulz for constructively proof-
reading many parts of this book. And to Herbert Voss, who helped us when things
got difficult in LaTeX. And finally, many thanks to the publisher’s staff and their
external reviewer, all of whom have been very helpful in keeping everything focused.
I hope that many readers have fun with this book and that they get out of
it more interest and a greater understanding of this modern but also very ancient
topic.
i i
i i
i i
CHAPTER 0
CHAPTER 0
Introduction
This section shows how the book and the programs work together.
The chapters of this book are largely self-contained and can be read and understood
independently of the CrypTool programs. In the following, we often abbreviate
“CrypTool” by CT.
Chapters 6 (“Modern Asymmetric Cryptography”), 8 (“Elliptic Curves”), 9
(“Modern Asymmetric Cryptography”), 10 (“Homomorphic Ciphers”), and 12
(“Results for Solving Discrete Logarithms and for Factoring”) require a deeper
knowledge of mathematics, while the other chapters should be understandable with
a high school diploma.
The authors have tried to describe cryptography for a broad audience—without
being mathematically incorrect, but with various links to get practical experience.
We believe that this didactic approach is the best way to promote awareness of IT
security and the willingness to use standardized modern cryptography.
This book provides a thorough overview of classical and modern cryptography
and also guides you to try it out using the following free programs.
CrypTool 1 (CT1) and its successor versions CrypTool 2 (CT2) and JCrypTool
(JCT) are used worldwide for training in companies and teaching in schools and
universities. CrypTool 1 is an educational program for Windows that allows you to
use and analyze cryptographic procedures within a unified graphical user interface.
The comprehensive online help in CrypTool 1 contains both instructions on how to
use the program and explanations of the methods themselves (both not as detailed
and in a different structure as in this book).
CT2 also runs on Windows and now has a significantly larger range of crypt-
analytic functions than CT1. JCT runs on Windows, Linux, and macOS, and now
includes many things not included in CT1.
The setups of these standalone desktop programs are downloaded more than
10,000 times a month.
xxi
i i
i i
i i
xxii Introduction
The scope of CTO is not yet as broad as that of the standalone CT1, CT2, and
JCT programs. However, as CTO is what people are using more and more as a first
contact, a lot of effort is going into the CTO development. So we redesigned the
backbone and frontend system using modern web technology to provide a fast, con-
sistent, and responsive look and feel. CTO also includes plugins using WebAssembly
(wasm) such as a Python IDE, Msieve, or OpenSSL. Using WebAssembly makes this
functionality run in a browser almost as fast as native applications. Another mod-
ern technology offered is models for cryptanalysis trained with machine learning
algorithms (deep learning, neural networks). See Section A.4.
Besides the classic ciphers, the most popular plugins in CTO are “RSA step-
by-step,” “RSA visual and more,” “AES step-by-step,” “AES animation,” and the
“Password meter.”
MysteryTwister
i i
i i
i i
CHAPTER 1
CHAPTER 1
Ciphers and Attacks Against Them
For centuries, plaintext messages were encrypted by the military, by diplomats, and
by alchemists, and much less frequently by businesses and the general population.
The goal of cryptography was to protect the privacy between sender and receiver.
Since the 1970s, further goals have been added to achieve integrity, authenticity,
and non-repudiation, and also to compute on encrypted data in the cloud or to
achieve quantum-computer resistance.
The science that deals with encryption is called cryptology—divided into the
branches of cryptography (designing secure encryption procedures) and cryptanal-
ysis (breaking encryption procedures). In reality, however, these branches are
closely interrelated and the terms cryptography and cryptology are often used
interchangeably. Therefore, cryptology is currently subdivided into fields like sym-
metric cryptography, public-key cryptography, hardware and embedded systems
cryptography, theoretical cryptology, and real-world crypto [1].
The importance of cryptology continues to grow as our society becomes more
and more dependent on information technology. Although cryptology and infor-
mation security are interdisciplinary fields of research, mathematics now plays the
largest role in cryptology. Finally, learning about cryptology can also be fun and
entertaining.
The special thing about this book is that you can always try out the procedures
right away—by using the links (in the footnotes) to the programs from the CrypTool
project, from OpenSSL, or from SageMath. All these programs are open-source.
In this book, the basics are covered in great detail, then from the very extensive
field of cryptology certain (current) topics are selected (like RSA, ECC, or lattices).
This makes this book accessible to a wide audience, not just only for those interested
in the natural sciences.
This chapter introduces the topic in a more descriptive way without using math-
ematics. To do so, it uses modern methods (RSA, AES) as examples. Then we dive
deepen, for example, the property, how many possible keys (key space) different
methods have (Section 1.6) and what are the best attacks against known methods
(Section 1.7). Recommended books are presented in Section 1.10. In Section 1.11
you will find screenshots of how to use AES in various programs. Classic methods
are presented in Chapters 2 and 3.
The purpose of encryption is to change data (plaintext messages) in such a way
that only an authorized recipient is able to reconstruct the plaintext. This allows
us to transmit encrypted data without worrying about it getting into unauthorized
hands. Authorized recipients possess a secret information—called the key—which
allows them to decrypt the data while it remains hidden from everyone else. An
attacker cannot only try to break a cipher: She still can disturb the connection
i i
i i
i i
With the use of the internet and wireless communication, encryption technolo-
gies are used (mostly transparently) by everyone. Cryptographic algorithms secure
ATMs and the privacy of messengers, allow anonymity for voters, but also help
criminals. Cryptography is dual-use, as are many human innovations.
However, cryptography is not only used today, but has been for centuries by
governments, the military, and diplomats. The side with a better command of these
technologies could exert more influence on politics and war with the help of secret
services. This book touches on history only twice: when introducing the earlier
cipher methods for didactical reasons in Chapter 2, and in Chapter 3 when explain-
ing the real application of earlier methods. You can gain an understanding of how
important cryptology was and still is by considering the following two examples: the
BBC documentary film War of the Letters [2] and the debates around the so-called
crypto wars.
The next two sections discuss the differences between symmetric (see
Section 1.2) and asymmetric (see Section 1.3) methods for encryption.
For symmetric encryption, both the sender and recipient must be in possession
of a common (secret) key that they have exchanged before actually starting to
communicate (over another channel, out of the band). The sender uses this key
i i
i i
i i
to encrypt the message and the recipient uses it to decrypt it. This is shown in
Figure 1.2.
All classical ciphers are of the symmetric type. Examples can be found within
the CT programs, in Chapter 2 of this book, or in [3]. In this section, however, we
want to consider only modern symmetric mechanisms.
The main advantage of symmetric algorithms is the high speed with which data
can be encrypted and decrypted. The main disadvantage is the high effort needed
for key distribution. In order to communicate with one another confidentially, the
sender and recipient must have exchanged a key using a secure channel before
actually starting to communicate. Spontaneous communication between individ-
uals who have never met therefore seems virtually impossible. If everyone wants
to communicate with everyone else spontaneously at any time in a network of
n subscribers, each subscriber must have previously exchanged a key with each
of the other n − 1 subscribers. A total of n (n − 1)/2 keys must therefore be
exchanged.
The current standard for modern symmetric ciphers is the Advanced Encryption
Standard (AES).
i i
i i
i i
1.2.1 AES1
Before AES, the most well-known modern symmetric encryption procedure was
the Data Encryption Standard (DES). The DES algorithm was developed by IBM
in collaboration with the National Security Agency (NSA), and was published as
a standard in 1975. Despite the fact that the procedure is relatively old, no effec-
tive attack on it has yet been detected (what “effective” exactly means depends on
the security definition—see Section 1.8). The most effective way of attacking DES
consists of testing (almost) all possible keys until the right one is found (brute-force
attack). Due to the relatively short key length of effectively 56 bit (64 bits, which
however include 8 parity bits),2 numerous messages encrypted using DES have in
the past been broken. Therefore, the procedure cannot be considered secure any
longer. Alternatives to the DES procedure include Triple-DES (TDES, 3DES) and
especially AES.
The standard among symmetric methods today is AES. The associated Rijndael
algorithm was declared the winner of the AES competition on October 2nd, 2000,
and thus succeeds the DES procedure. Since then, the AES has been subjected to
extensive research and has so far resisted all practical attempts at attack.
Further information about AES can be found in Section 9.2.7. Section 1.11
presents how the AES is animated in CTO, and how the AES is executed in CT2
and with OpenSSL.
1. - Using CTO in the browser, AES can be seen in two plugins: as “AES Animation” https://www
.cryptool.org/en/cto/aes-animation and via “AES (step-by-step)” https://www.cryptool.org/en/cto/aes-step-
by-step.
- Using CT1 Indiv. Procedures F Visualization of Algorithms F AES you can find three visualizations for
this cipher.
- Using the search string AES in CT2 Startcenter F Templates you can find a plugin performing AES step by
step.
2. As a unit in formulas, we write “bit” in lower case and without the plural “s.” See Section B.2.
3. - Using CT1 Analysis F Symmetric Encryption (modern) you can perform brute-force attacks of modern
symmetric algorithms.
- Using CT2 Templates F Cryptanalysis F Modern you also can perform brute-force attacks. The Key-
Searcher is a highly powerful component used within these templates, which can distribute the calculations
to many different computers.
4. If the plaintext is written in a natural language and at least 100 bytes long, this check also can be performed
automatically. To achieve a result in an appropriate time with a single PC you should mark only at bits of
the key as unknown. On a current PC in 2022, CT1 tries for AES 24 bit in about 20 seconds, but with 32
bit it takes 1:45 h. Compare screenshots in Section 1.6.
i i
i i
i i
In the case of asymmetric encryption (also called public-key encryption), each par-
ticipant has their own pair of keys consisting of a secret key (called private key)
and a public key. The public key, as its name implies, is made public—for example,
within a certificate (see Section 7.5.2) or in a key directory on the internet (this type
of billboard is also called a directory or sometimes public-key ring).
Figure 1.3 shows the process of asymmetric encryption and decryption.
If Alice6 wants to communicate with Bob, she looks for Bob’s public key and
uses it to encrypt her message (plaintext) for him. She then sends this ciphertext
to Bob, who is able to decrypt it again using his private key. As only Bob knows
his private key, only he can decrypt messages addressed to him. Even Alice who
sends the message cannot restore the plaintext from the (encrypted) message she
has sent. In reality, asymmetric methods are not used to encrypt the whole message
but only a session key (see Section 1.4). Asymmetric ciphers are designed in a way
that the public key cannot be used to derive the private key from it.
Such a procedure can be demonstrated using a series of thief-proof letter boxes.
If I have composed a message, I then look for the letter box of the recipient and post
5. Unfortunately, in May 2007 RSA Inc. announced that they will not confirm the correctness of the not-
yet-solved RC5-72 challenge. Alternatively, a wide spectrum of both simple and complex, and both
symmetric and asymmetric crypto riddles are included in the international cipher contest MysteryTwister:
https://www.mysterytwister.org.
6. In order to describe cryptographic protocols, participants are often named Alice, Bob, … (see [8, p. 23]).
Alice and Bob perform all 2-person-protocols where Alice will initiate the protocol and Bob answers. The
attackers are named Eve (eavesdropper) and Mallory (malicious active attacker).
i i
i i
i i
the letter through it. After that, I can no longer read or change the message myself,
because only the legitimate recipient has the key for the letter box.
The advantage of asymmetric procedures is the easier key management. Let’s
look again at a network with n subscribers. In order to ensure that each participant
can establish an encrypted connection to each participant, each participant must
possess a pair of keys. We therefore need 2n keys or n pairs of keys. Furthermore,
no secure channel is needed before messages are transmitted, because all the infor-
mation required in order to communicate confidentially can be sent openly. In this
case, you simply have to pay attention to the accuracy (integrity and authenticity)
of the public key. Nevertheless, the requirements for the key generation are not triv-
ial. What could go wrong is explained, for example, in Section 5.12.5.4. Besides
that, nowadays also (public-key) infrastructures themselves are targets of cyberat-
tacks. A disadvantage of pure asymmetric procedures is that they take a lot longer
to perform than symmetric ones (see Section 1.4).
i i
i i
i i
In 1883, the Dutch cryptographer Auguste Kerckhoffs formulated six principles for
the construction of secure military encryption procedures. The second one, Kerck-
hoffs’ principle or Kerckhoffs’ maxim, is now regarded as the principle of modern
cryptography. It states that an encryption scheme should be secure even if every-
thing about the scheme is known except the key used. Kerckhoffs’ principle is often
contrasted with “security through obscurity,” in which the encryption algorithm
must also be kept secret.
7. The RSA algorithm is extensively described within this book in Section 5.10. The topical research results
concerning RSA are described in Section 5.12. In Section 6.5 the RSA algorithm is more deeply reasoned
from number theory: The RSA plane is a model to illustrate the processes in this algorithm using pictures
of rectangles.
8. - Using CT1 Encrypt/Decrypt F Hybrid you can follow the single steps and its dependencies with concrete
numbers. The variant with RSA as the asymmetric algorithm is graphically visualized; the variant with ECC
uses the standard dialogs. In both hybrid cases AES is used as the symmetric algorithm.
- Using JCT Algorithm Perspective F Hybrid Ciphers also offers hybrid methods like ECIES.
i i
i i
i i
For good encryption procedures used today, the time needed to break an encryption
is so long that it is almost impossible to do so. Such procedures are considered (prac-
tically) secure—from an algorithm’s point of view. After the knowledge gathered
by Edward Snowden, there were many discussions debating whether encryption is
secure. In [9] is the result of an evaluation, which cryptographic algorithms can
be relied on—but only according to current knowledge. The article investigates:
Which cryptosystems can—despite the reveal of the NSA/GCHQ attacks—still be
considered as secure? Where have systems been intentionally weakened? How can
we create a secure cryptographic future? What is the difference between math and
implementation?
The key space of a cipher is an important indicator for the security of a cipher. In
a monoalphabetic substitution (MASC; also called simple substitution) for instance,
using an alphabet of length of k, the key space is k !. For AES-128 it is 2128 .
A (sufficiently) large key space (approx. 2100 ) is a necessary prerequisite for
a secure cipher, but not a sufficient condition: The MASC has a large key space
(with an alphabet of 26 characters approx. 288.4 that corresponds to the number of
possible ciphertext alphabets), but it has been cracked with frequency analysis for
centuries.
The key space is used to calculate the effort required for a brute-force (BF)
attack (i.e., for the systematic testing of all possible keys). If the key space is so small
that an attacker can carry out a complete BF attack, the procedure is broken—not
only theoretically but also practically.
In the case of a BF attack, the attacker decrypts the ciphertext (or parts of it)
with every possible key (see Section 1.2.2). Then the found plaintext is evaluated.
How surprisingly well fitness algorithms can recognize correct natural texts can be
seen in Figures 1.49 and 1.5.10 CT1 uses similar fitness functions as the solvers and
analyzers in CT2.
Whether an attacker really has to try the maximal, theoretical key space is
questionable, at least with the older ciphers. For this reason, the practical key space
introduced by Ralph Simpson for historic cipher devices and the work factor, which
is also known as attack time, are considered.
i i
i i
i i
Figure 1.4 Brute-force analysis of AES in CT1 with partly known key.
the codebreakers who broke that encryption. Of course, they were all eventually
broken.
For instance, the key space for the infamous Enigma I machine is larger than
the number of atoms in the universe. According to Table 1.1, the theoretical key
space of the Enigma is around 3 · 10114 , while the number of atoms in the universe
is around 1077 (according to Table 4.13).
There are two main problems with key spaces of historic cipher devices. The
first problem is that key space can be a misleading measure for the strength of
the encryption. The reason for the confusion on this point arises because the key
space of a modern symmetric cipher system, in contrast, usually provides a good
measure for the strength of the encryption. But historic devices are mechanical or
electromechanical, which results in limitations on the randomness of the encryp-
tions. This means that methods can be developed to break that encryption without
the need for brute force. Remember, key space is only a measure of the brute force
i i
i i
i i
i i
i i
i i
required to break an encryption, without taking into account any methods used by
cryptanalysts to shortcut (many) parts of that key space.
The second problem with key spaces of historic devices is due to the wild vari-
ations often reported for the very same device. This variation is usually due to
differences in base assumptions, but those assumptions are not always stated.
Another thing to consider about key spaces is that cryptanalysis methods for
some historic devices were not developed for many decades or even centuries after
their invention. As with all things crypto-related, cryptanalysis methods are not nec-
essarily made public. As an example, the Vigenère disk, which was invented in 1466,
was reported by Scientific American magazine to be unbreakable in 1917. This arti-
cle was published the same year that Joseph Mauborgne, U.S. Army Chief Signal
Officer, boasted that his cryptographers could decrypt the Vigenère disk faster than
the enemy could decrypt their own messages.
Despite the problems highlighted, a study of the key spaces of historic cipher
devices is a useful tool to better understand the mind of the cipher inventor, user,
and codebreaker. So with modern methods, we can discount and malign the value of
key spaces of historic devices, but that alone would miss the point of understanding
why historical decisions were made based on the strength of the encryption implied
by these large key spaces.
i i
i i
i i
This number is usually smaller than the practical key space because any known
cryptanalysis techniques are used as shortcuts. For the Enigma, this means that
Rejewski’s method of separating the cryptanalysis of the plugboard from the rotors
and reflector greatly reduced the total number of settings that needed to be tested.
Some of these cryptanalysis techniques were not known at the time of use or were
not known by the users of these cipher devices.
Work factor is a concept more commonly used for the modern cipher systems.
For the historical devices, there is very little available on work factors. It depends on
the size of the message or number of messages captured. And it depends on the state
of the cryptanalytic techniques that could be applied. For example: Although the
Enigma machine has a huge theoretical key space, the Turing-Welchman Bombe
only had to check about 422,000 settings in order to break the Enigma.11 This
work factor is what is called “attack time” when comparing the best attacks against
modern ciphers in Table 1.3. For DES the work factor is drastically smaller (243 )
than the practical key space, and for AES it is around 2 bits smaller (2254.4 ).
11. Why only 422,000? The British Bombe only tested for rotor order and rotor settings; ring settings and
plugboard settings were then manually determined. With three rotors chosen from five, there are 5 · 4 · 3 = 60
possible rotor orders. German procedures, however, did not allow any three rotor order to be repeated in
the same month, which reduced the 60 possible orders at the beginning of the month to 30 by the end of
the month. In addition, the Germans did not permit any individual rotor to be in the same position on the
following day, reducing the 60 possible rotor orders to 32. Combined, these two rules reduced the possible
orders to 32 at the beginning of the month, declining to 16 at the end of the month, or on average 24 rotor
orders. This average rotor order multiplied with the 263 rotor settings yielded to 24 · 17,576 = 421,824
settings tested by the Bombe for a full run.
i i
i i
i i
4. A “message setting” will be sent with each message, separate from the fixed
machine setting.
i i
i i
i i
Table 1.1 Key Space Sizes for 34 Historic and 4 Modern Cipher Systems
Year Cipher Maximum Key Space Practical Key Space
600 BCE Monoalphabetic substitution 4.03 · 1026 288 4.03 · 1026 288
50 BCE Caesar 2.50 · 101 25 2.50 · 101 25
1466 Vigenère (repeating keyword – 15 char.) 1.68 · 1021 271 1.68 · 1021 271
1586 Vigenère (autokey – 314 char. message) 2.00 · 10444
21476 2.00 · 10444
21476
1854 Playfair 6.20 · 1023 279 6.20 · 1023 279
1860s Wheatstone Cryptograph 4.03 · 1026 288 4.03 · 1026 288
1912 Lugagne Transpositeur 1.30 · 10532
21768 1.32 · 1013
244
1912 M-94 cylinder cipher 3.45 · 10666
22214 3.88 · 1026
288
1916 M-138A strip cipher 3.69 · 10799 22656 1.95 · 1059 2197
1918 ADFGX 4.19 · 1047 2158 4.19 · 1047 2158
1918 ADFGVX 1.01 · 1064
2213 1.01 · 1064
2213
1922 Hebern 5-rotor 1.27 · 10140
2466 4.56 · 1010
235
1924 Kryha 2.02 · 1053 2177 1.78 · 1029 297
1926 Enigma Swiss K 1.60 · 10101 2336 1.85 · 109 231
1930 Lugagne Le Sphinx 1.30 · 10532
21768 2.43 · 1024
281
1931 Abwehr Enigma G 7.17 · 10121
2405 4.82 · 1010
235
1932 Enigma I 3.28 · 10114 2380 4.31 · 1022 275
1937 SIGABA 1.82 · 10285 2941 5.95 · 1028 296
1939 Japanese Purple 3.81 · 1059
2198 1.45 · 1031
2104
1939 Japanese JN-25 codebook (100 words) 1.00 · 1012
240 8.25 · 1010
236
1941 Lorenz SZ40/SZ42 1.05 · 10170 2565 1.05 · 10170 2565
1941 SG-41 “Hitler Mill” 4.24 · 1051 2171 4.24 · 1051 2171
1942 M-209 pin & lug 6.16 · 1060
2202 6.02 · 1058
2195
1942 Enigma M4 2.33 · 10145
2483 3.13 · 1025
285
1942 T-52d Geheimschreiber 7.23 · 10213 2710 8.11 · 1023 279
1943 Typex Mark 22 1.82 · 10195 2649 5.51 · 1054 2182
1947 NEMA 5.99 · 10164
2551 1.83 · 1019
264
1952 Hagelin C-52 1.68 · 10117
2389 7.17 · 1057
2192
1952 Hagelin CX-52 1.17 · 10123 2409 1.10 · 10104 2346
1952 KL-7 5.87 · 10431
21434 1.70 · 1034
2114
1950s Transvertex HC-9 2.96 · 1071
2237 4.39 · 1069
2231
1953 VIC paper & pencil 9.09 · 1040 2136 1.00 · 1027 290
1956 Fialka 2.82 · 10458 21523 6.24 · 1077 2258
1957 Hagelin CD-57 1.52 · 10103
2343 1.49 · 1060
2200
1976 DES (56 bit) 7.21 · 1016 256 7.21 · 1016 256
1977 RSA-4096 2.22 · 101225 24071 2.22 · 101225 24071
1992 AT&T TSD 3600-E Clipper chip 1.21 · 1024 280 1.21 · 1024 280
2001 AES-256 1.16 · 1077 2256 1.16 · 1077 2256
Courtesy of Ralph Simpson.
It is important to remember that these key spaces are still not a good sole indi-
cator of the cryptographic strength of the encryption method—examples for these
criticisms are monoalphabetic substitution (288 ), Enigma I (275 ), and Playfair (279 ).
But using a common set of assumptions will at least add a level of consistency
among all these disparate devices.
Tables 1.2 and 1.3 contain the best attacks known today for well-known classical
and modern ciphers. For modern procedures, the effort (number of steps or attack
i i
i i
i i
time) is also given in Table 1.3. To our knowledge, this is the first time such a
complete table is created.
For symmetric ciphers, the key space derived from the key length is an impor-
tant indicator (see Section 1.6). It is used to calculate the effort required for a BF
attack, the maximum effort that an attacker can have.
The following applies to AES-128 (see Table 1.3): The key length is 128 bits.
The key space is 2128 and so is the theoretical attack time. The best known attack
(biclique attack) reduces this maximum effort to 2126.1 steps. This difference of
around 2 in the exponent means that the attack is about 4 times faster than a BF
attack on average. This shows that AES is vulnerable in principle, but this attack is
not at all relevant to practical security.
i i
i i
i i
If you are interested in the definitions used in modern cryptography, this section
explains them with the fewest amount of mathematics as possible. Also, the rela-
tionship between the various definitions is declared—something which often falls
short in courses. We believe that only understanding the differences between the
various concepts enables learners to grasp the idea and apply it correctly later.
i i
i i
i i
i i
i i
i i
1. Another attack claiming to break 855 rounds [97] of Trivium has been questioned in [98].
2. We are not aware of any attacks faster than brute force. Rabbit has four initialization rounds. The values within
the cipher become balanced after two rounds [83], hence there is a trivial distinguishing attack against at least
one round of the cipher.
3. There exist attacks against earlier versions of the cipher. The cryptanalysis of the final version made by the
designers is secret to the best of our knowledge.
4. Our upper-bound estimation: In [93], the attack time is given as 2, 700 core years of computations using Intel
Xeon Gold 6130 CPU (each 2.1 GHz). To convert this attack time to the RSA-250 encryptions, we would need
to know how much time is required on average to apply one encryption on the mentioned processor. For a rough
estimate, we assume that one encryption requires less time than one integer operation as tested in [99].
5. The actual attack time depends on the specific parameter choices. See [100] for more details.
Attack definition. Before proceeding to the discussion about various attack types
(see Section 1.8.1), it’s essential to clarify the concept of an attack against a modern
cipher. We start this explanation with Kerckhoffs’s principle (see Section 1.5). This
principle emphasizes that a cryptosystem should be secure even if all the system
details, excluding the secret key, are known to the attacker.
However, the principle brings up the term “secure.” To formulate the definition
of security, we use ideas about the infeasibility of distinguishing—see Sections 1.8.2
and 1.8.3. In a nutshell, a cryptographic attack is an algorithm that aims to
demonstrate the lack of security in a given cryptosystem.
Attack time. The attack time is generally expressed in the number of a partic-
ular cipher’s encryptions. This is done in order to demonstrate by which factor
i i
i i
i i
Single/multiple keys. Cryptanalytic attacks also vary based on the attacker’s abil-
ity to observe different numbers of encryption instances related to distinct keys.
Single-key attacks assume access to the ciphertexts encrypted under the same
key. Variable-key attacks assume access to ciphertexts encrypted under multiple
unknown keys. This often mirrors real-world situations where a cipher’s user must
change the key after a certain number of encryptions. If an attacker gains access
to several corresponding ciphertexts, he can use this information as an advantage
i i
i i
i i
i i
i i
i i
than |1/2 + η| where η is negligible. Clearly, the attacker cannot choose the same
messages for the challenge for which he gets the ciphertexts from the oracle. This
security definition can be applied to both symmetric and asymmetric encryption
schemes, although formally they are described differently [101]. However, in case
of deterministic asymmetric encryption schemes, an attacker has access to the pub-
lic key, which means that he can easily distinguish which ciphertext was produced
by which message by encrypting the messages by himself. Therefore, the definition
is only applied to probabilistic public-key encryption schemes where randomness is
used in the encryption process. This implies that the same message encrypted several
times under the probabilistic encryption scheme results in different ciphertexts.
• The first one is semantic security, which implies that it is infeasible for an
attacker to learn any information about the plaintext from the ciphertext;
i i
i i
i i
i i
i i
i i
i i
i i
i i
Here, two aspects of crypto procedures are mentioned briefly, which are often not
discussed early enough: types of algorithms and the thinking up of new algorithms.
Here are some good cryptography books that can serve as useful background on var-
ious topics in order from beginners (history) to intermediate (applied) to advanced
i i
i i
i i
(theory-focused):
Besides the information in these books and in the following chapters, there is
also a good number of websites and the online help of all CrypTool variants that
contain many details about encryption methods.
The book by Bruce Schneier [8] offers an easy overview of the different encryp-
tion algorithms. For a more in-depth introduction, in addition to the book by Rolf
Oppliger [103], we also recommend the books by David Wong [107], Jean-Philippe
Aumasson [108], and Douglas R. Stinson [110].
AES is now probably the most widely used modern encryption algorithm world-
wide. AES is a secure, standardized, symmetrical process that encrypts data, for
example, in Wi-Fi and browser connections. The AES-192 and AES-256 variants
are approved for top-class government documents in the United States.
In the following sections, first an AES animation is presented in CTO; and
then AES is executed directly—once in CT2 and twice with OpenSSL (once on the
command line of the operating system and once in the OpenSSL WebAssembly
plugin in CTO).
i i
i i
i i
14. https://www.cryptool.org/en/cto/aes-animation.
i i
i i
i i
i i
i i
i i
received ciphertext we are only interested in the first block (if the plaintext doesn’t
fill up a complete block, for the sake of simplicity, here we use zero padding).
For demonstration, we do it once with CT2 and twice with OpenSSL.15
The plaintext AESTEST1USINGCT2 is converted to hex (41 45 53 54
45 53 54 31 55 53 49 4E 47 43 54 32). Using this and the key
3243F6A8885A308D313198A2E0370734 the AES component creates the cipher-
text, which is in hex: B1 13 D6 47 DB 75 C6 D8 47 FD 8B 92 9A 29 DE 08.
Figure 1.10 shows the encryption of one block in CT2.16
1.11.3 AES with OpenSSL at the Command Line of the Operating System
OpenSSL Example 1.1 achieves the same result as CT2 with OpenSSL from the
(Windows) command line.
OpenSSL Example 1.1: AES Encryption (Of Exactly One Block and Without
Padding)
>openssl enc -e -aes -128-cbc -K 3243F6A8885A308D313198A2E0370734 -iv 00 �
� 000000000000000000000000000000 -in klartext -1.hex -out klartext -1. �
� hex.enc
>dir
06.07.2016 12:43 16 key.hex
20.07.2016 20:19 16 klartext -1.hex
20.07.2016 20:37 32 klartext -1.hex.enc
Figure 1.10 AES encryption (here exactly 1 block and without padding) in CT2.
15. OpenSSL is a widespread free open-source crypto library that contains the command line tool openssl.
Using OpenSSL you can try out the functionality on many operating systems.
You can find an introduction into the CLI openssl (e.g. at https://www.cryptool.org/en/documenta-
tion/ctbook/).
16. This is similar to the following template: CT2 Templates F Cryptography F Modern F Symmetric F AES
Cipher (Text Input).
i i
i i
i i
Note: As OpenSSL Example 1.2 shows, with a little effort, pipes, and the tool
xxd, this can be achieved also in a Bash shell and without using temporary files:17
OpenSSL Example 1.2: AES Encryption (Without Temporary Files) With Bash
$ echo 0: 41 45 53 54 45 53 54 31 55 53 49 4E 47 43 54 32 | xxd -r | �
� openssl enc -e -aes -128-cbc -nopad -K 3243F6A8885A308D313198A2E03707 �
� 34 -iv 00000000000000000000000000000000 | xxd -p
b113d647db75c6d847fd8b929a29de08
1.12.1 Mini-AES
The SageMath module crypto/block_cipher/miniaes.py supports Mini-AES to
allow students to explore the inner working of a modern block cipher.
Mini-AES, originally described in [111], is a simplified variant of AES to be
used for cryptography education.
Here is a short list about how Mini-AES was simplified compared to AES:
17. xxd creates a hex dump of a given file or of standard input. With the option “-r” it converts hex dump
back to its original binary form.
18. https://www.cryptool.org/en/cto/openssl.
i i
i i
i i
• The AES has a block size of 128 bits, and supports key sizes of 128, 192,
and 256 bits. The number of rounds is 10, 12, or 14 for the three different
key sizes, respectively.
Mini-AES has a 16-bit block size, a 16-bit key size, and 2 rounds.
• The 128-bit block of the AES is expressed as a matrix of 4 × 4 bytes, in
contrast to Mini-AES expressing its 16-bit block as a matrix of 2 × 2 nibbles
(half-bytes).
• The AES key schedule takes the 128-bit secret key and expresses it as a group
of four 32-bit words.
i i
i i
i i
The Mini-AES key schedule takes the 16-bit secret key and expresses it as a
group of four nibbles (4-bit words).
# decryption process
plaintxt = maes.decrypt(C, key)
print(plaintxt == P)
P = maes.integer_to_binary(P)
key = maes.integer_to_binary(key)
C = maes(P, key , algorithm =" encrypt "); print ("C:\n",C, sep ="")
plaintxt = maes(C, key , algorithm =" decrypt ")
print(plaintxt == P)
i i
i i
i i
Further details concerning cryptosystems within SageMath (e.g., about the Sim-
plified Data Encryption Standard (SDES)) can be found in the thesis of Minh Van
Nguyen [113].
References
20. A very good starting point to learn cryptanalysis is the book from Mark Stamp [109]. Also good, but very
high-level and concentrating on analyzing symmetric block ciphers only, is the article from Bruce Schneier
[114].
Several of the cipher challenges at MysteryTwister (https://www.mysterytwister.org) are also well
suited for educational purposes.
21. If you double-click on the title of the icon of the SDES component in CT2 you can see a visualiza-
tion of the SDES algorithm, showing how the bits of the given data flow through the whole algo-
rithm. A corresponding screenshot: https://www.facebook.com/CrypTool2/photos/a.505204806238612
.1073741827.243959195696509/597354423690316.
22. See the template: CT2 Templates F Cryptography F Modern F Symmetric F S-AES.
i i
i i
i i
[4] The RSA Secret Key Challenge, RSA Labs (formerly RSA Security), https://web.archive
.org/web/20170417095446/http://www.emc.com/emc-plus/rsa-labs/historical/the-rsa-lab
oratories-secret-key-challenge.htm.
[5] DES Challenge, RSA Labs (former RSA Security), https://web.archive.org/web/
20061210141223/http://www.rsasecurity.com/rsalabs/node.asp?id=2108.
[6] Press and Articles Related to Project RC5-64, https://www.distributed.net/Press-
room_press-rc5-64.
[7] BSI, Technical Guideline TR-02102-1, Cryptographic Mechanisms: Recommendations
and Key Lengths (Version 2022-01), Tech. Rep. 2022, https://www.bsi.bund.de/Shared-
Docs/Downloads/EN/BSI/Publications/TechGuidelines/TG02102/BSI-TR-02102-1.pdf.
[8] Schneier, B., Applied Cryptography, Protocols, Algorithms, and Source Code in C, Second
Edition, Wiley, 1996.
[9] Esslinger, B., J. Schneider, and V. Simon. “Krypto + NSA = ? – Kryptografische Folgerun-
gen aus der NSA-Affäre,” in KES Zeitschrift für Informationssicherheit, March 2014, pp.
70–77, https://www.cryptool.org/assets/ctp/documents/krypto_nsa.pdf.
[10] Miller, A. R., The Cryptographic Mathematics of Enigma, Revised Edition, 2019, Center
for Cryptologic History, National Security Agency, 1995, https://www.nsa.gov/portals/
75/documents/about/cryptologic-heritage/historical-figures-publications/publications/ww
ii/CryptoMathEnigma_Miller.pdf.
[11] Ostwald, O., Cryptographic Design Flaws of Early Enigma, 2023, https://cryptocel-
lar.org/enigma/files/enigma-design-flaws.pdf.
[12] International Conference on Cryptologic History (ICCH), https://www.cryptologichi
story.org/.
[13] Kopal, N, “Solving Classical Ciphers with CrypTool 2,” in Proceedings of the 1st
International Conference on Historical Cryptology, 2018, pp. 29–38.
[14] Kopal, N, “Cryptanalysis of Homophonic Substitution Ciphers Using Simulated Anneal-
ing with Fixed Temperature,” in Proceedings of the 2nd International Conference on
Historical Cryptology, 2019, pp. 107–116.
[15] Lasry, G., N. Biermann, and S. Tomokiyo, “Deciphering Mary Stuart’s Lost Letters from
1578–1584,” Cryptologia, Vol. 47, No. 2, 2023, pp. 101–202.
[16] Lasry, G., B. Megyesi, and N. Kopal, “Deciphering Papal Ciphers from the 16th to the
18th Century,” Cryptologia, Vol. 45, No. 6, 2021, pp. 479–540, https://www.tandfon-
line.com/doi/full/10.1080/01611194.2020.1755915.
[17] Dunin, E., et al., “How We Set New World Records in Breaking Playfair Ciphertexts,”
Cryptologia, Vol. 46, No. 4, 2022, pp. 302–322.
[18] Lasry, G., “Solving a 40-Letter Playfair Challenge with CrypTool 2,” in Proceedings of
the 2nd International Conference on Historical Cryptology, 2019, pp. 23–26.
[19] Lasry, G., “Deciphering German Diplomatic and Naval Attaché Messages from
1914–1915,” in Proceedings of the 1st International Conference on Historical Cryptol-
ogy, 2018, pp. 55–64.
[20] Lasry, G., et al., “Cryptanalysis of Chaocipher and Solution of Exhibit 6,” Cryptologia,
Vol. 40, No. 6, 2016, pp. 487–514.
[21] Lasry, G., N. Kopal, and A. Wacker, “Cryptanalysis of Columnar Transposition Cipher
with Long Keys,” Cryptologia, Vol. 40, No. 4, 2016, pp. 374–398.
[22] Lasry, G., N. Kopal, and A. Wacker, “Solving the Double Transposition Challenge with a
Divide-and-Conquer Approach,” Cryptologia, Vol. 38, No. 3, 2014, pp. 197–214.
[23] Lasry, G., et al., “Deciphering ADFGVX Messages from the Eastern Front of World War
I,” Cryptologia, Vol. 41, No. 2, 2017, pp. 101–136.
[24] Gillogly, J. J., “Ciphertext-Only Cryptanalysis of Enigma,” Cryptologia, Vol. 19, No. 4,
1995, pp. 405–413.
[25] Lasry, G., N. Kopal, and A. Wacker, “Cryptanalysis of Enigma Double Indicators with
Hill Climbing,” Cryptologia, Vol. 43, No. 4, 2019, pp. 267–292.
i i
i i
i i
[26] Ostwald, O., and F. Weierud, “Modern Breaking of Enigma Ciphertexts,” Cryptologia,
Vol. 41, No. 5, 2017, pp. 395–421.
[27] Lasry, G., “Solving a Tunny Challenge with Computerized ‘Testery’ Methods,” in
Proceedings of the 3rd International Conference on Historical Cryptology, 2020.
[28] Lasry, G., N. Kopal, and A. Wacker, “Automated Known-Plaintext Cryptanalysis of Short
Hagelin M-209 Messages,” Cryptologia, Vol. 40, No. 1, 2016, pp. 49–69.
[29] Lasry, G., N. Kopal, and A. Wacker, “Ciphertext-Only Cryptanalysis of Short Hagelin
M-209 Ciphertexts,” Cryptologia, Vol. 42, No. 6, 2018, pp. 485–513.
[30] Lasry, G., “A Practical Meet-in-the-Middle Attack on SIGABA,” in Proceedings of the
2nd International Conference on Historical Cryptology, 2019, pp. 23–26.
[31] Lasry, G., “Cracking SIGABA in Less than 24 Hours on a Consumer PC,” Cryptologia,
Vol. 47, No. 1, 2023, pp. 1–37.
[32] Matsui, M., “Linear Cryptanalysis Method for DES Cipher,” in Advances in
Cryptology—EUROCRYPT’93: Workshop on the Theory and Application of Crypto-
graphic Techniques, Lofthus, Norway, May 23–27, 1993, Springer, pp. 386–397.
[33] Junod, P., “On the Complexity of Matsui’s Attack,” in Selected Areas in Cryptogra-
phy: 8th Annual International Workshop, SAC 2001, Toronto, Ontario, Canada, August
16–17, 2001, Springer, pp. 199–211.
[34] Merkle, R. C., and M. E. Hellman, “On the Security of Multiple Encryption,” Commu-
nications of the ACM, Vol. 24, No. 7, 1981, pp. 465–467.
[35] Daemen, J., and V. Rijmen, The Design of Rijndael, Volume 2, Springer, 2002.
[36] Bogdanov, A., D. Khovratovich, and C. Rechberger, “Biclique Cryptanalysis of the Full
AES,” in Advances in Cryptology–ASIACRYPT 2011: 17th International Conference on
the Theory andApplication of Cryptology and Information Security, Seoul, South Korea,
December 4–8, 2011, Springer, pp. 344–371.
[37] Aoki, K., et al., “Camellia: A 128-Bit Block Cipher Suitable for Multiple Platforms—
Design and Analysis,” in Selected Areas in Cryptography: 7th Annual International
Workshop, SAC 2000, Waterloo, Ontario, Canada, August 14–15, 2000, Springer,
pp. 39–56.
[38] Li, L., et al., “Meet-in-the-Middle Technique for Truncated Differential and Its Appli-
cations to CLEFIA and Camellia,” in Fast Software Encryption: 22nd International
Workshop, FSE 2015, Istanbul, Turkey, March 8–11, 2015, Revised Selected Papers,
Springer, pp. 48–70.
[39] Matsui, M., “New Block Encryption Algorithm MISTY,” in Fast Software Encryption:
4th International Workshop, FSE’97, Haifa, Israel, Springer, pp. 54–68.
[40] Bar-On, A., and N. Keller, “A 270 Attack on the Full MISTY1,” in Advances in
Cryptology–CRYPTO 2016: 36th Annual International Cryptology Conference, Springer:
Santa Barbara, California, August 14–18, 2016, pp. 435–456.
[41] Todo, Y., “Integral Cryptanalysis on Full MISTY1,” Journal of Cryptology, Vol. 30,
No. 3, 2017, pp. 920–959.
[42] ETSI (2014-10), Universal Mobile Telecommunications System (UMTS); LTE; 3G Secu-
rity; Specification of the 3GPP Confidentiality and Integrity Algorithms; Document
2: Kasumi Specification (3GPP TS 35.202 version 12.0.0 Release 12), https://www
.etsi.org/deliver/etsi_ts/135200_135299/135202/07.00.00_60/ts_135202v070000p.pdf.
[43] Dunkelman, O., N. Keller, and A. Shamir, “A Practical-Time Related-Key Attack on the
KASUMI Cryptosystem Used in GSM and 3G Telephony,” in Advances in Cryptology–
CRYPTO 2010: 30th Annual Cryptology Conference, Santa Barbara, California, August
15–19, 2010, Springer, pp. 393–410.
[44] Hong, D., et al., “HIGHT: A New Block Cipher Suitable for Low-Resource Device,”
in Cryptographic Hardware and Embedded Systems—CHES 2006: 8th International
Workshop, Yokohama, Japan, 2006, Springer, pp. 46–59.
i i
i i
i i
[45] Hong, D., B. Koo, and D. Kwon, “Biclique Attack on the Full HIGHT,” in Informa-
tion Security and Cryptology-ICISC 2011: 14th International Conference, Seoul, Korea,
November 30–December 2, 2011, Revised Selected Papers 14, Springer, pp. 365–374.
[46] Adams, C., RFC2144: The CAST-128 Encryption Algorithm, 1997, https://www.rfc-
editor.org/rfc/r fc2144.
[47] Wang, S., T. Cui, and M. Wang, “Improved Differential Cryptanalysis of CAST-128
and CAST-256,” in Information Security and Cryptology: 12th International Conference,
Inscrypt 2016, Beijing, China, November 4–6, 2016, Springer, pp. 18–32.
[48] Lee, H. J., et al., RFC4009: The SEED Encryption Algorithm, 2005, https://www.rfc-
editor.org/rfc/rfc4269.
[49] Sung, J., “Differential Cryptanalysis of Eight-Round SEED,” Information Processing
Letters, Vol. 111, No. 10, 2011, pp. 474–478.
[50] Bogdanov, A., et al., “PRESENT: An Ultra-Lightweight Block Cipher,” in Cryptographic
Hardware and Embedded Systems-CHES 2007: 9th International Workshop, Vienna,
Austria, September 10–13, 2007, Springer, pp. 450–466.
[51] Blondeau, C., and K. Nyberg. “Links between Truncated Differential and Multidi-
mensional Linear Properties of Block Ciphers and Underlying Attack Complexities,”
Eurocrypt, Vol. 14, 2014, pp. 165–182.
[52] Shirai, T., et al.,“The 128-Bit Blockcipher CLEFIA,”in Fast Software Encryp-
tion, 14th International Workshop, FSE 2007, LNCS 4593, 2007, pp. 181–195.
2007, http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.111.9703&rep=rep1&
type=pdf#page=191.
[53] Hong, D., et al. “LEA: A 128-Bit Block Cipher for Fast Encryption on Common Proces-
sors,” in Information Security Applications: 14th International Workshop, WISA 2013,
Jeju Island, Korea, August 19–21, 2013, pp. 3–27.
[54] Dwivedi, A. D., and G. Srivastava, “Differential Cryptanalysis of Round-Reduced LEA,”
IEEE Access, Vol. 6, 2018, pp. 79105–79113.
[55] Diffie, W., and G. Ledin, “SMS4 Encryption Algorithm for Wireless Networks,” Cryptol-
ogy ePrint Archive, 2008.
[56] Liu, Y., et al., “New Linear Cryptanalysis of Chinese Commercial Block Cipher Standard
SM4,” Security and Communication Networks, 2017.
[57] Zabotin, I. A., G. P. Glazkov, and V. B. Isaeva, “Cryptographic Protection for Information
Processing Systems, Government Standard of the USSR, GOST 28147-89,” Government
Committee of the USSR for Standards, 1989.
[58] Courtois, N. T., “An Improved Differential Attack on Full GOST,” in The New Code-
breakers: Essays Dedicated to David Kahn on the Occasion of His 85th Birthday (P. Y.
A. Ryan, D. Naccache, and J.-J. Quisquater, eds.), Berlin: Springer, 2016, pp. 282–303.
[59] Federal Agency on Technical Regulation and Metrology (GOST), GOST R 34.12-2015:
Block Cipher “Kuznyechik,” https://www.rfc-editor.org/rfc/rfc7801.
[60] AlTawy, R., and A. M Youssef, “A Meet in the Middle Attack on Reduced Round
Kuznyechik,” IEICE Transactions on Fundamentals of Electronics, Communications and
Computer Sciences, Vol. 98, No. 10, 2015, pp. 2194–2198.
[61] Bruwer, F. J., W. Smit, and G. J. Kuhn, Microchips and Remote Control Devices
Comprising Same, U.S. Patent 5,517,187, May 1996.
[62] Indesteege, S., et al., “A Practical Attack on KeeLoq,” in Advances in Cryptology–
EUROCRYPT 2008: 27th Annual International Conference on the Theory and Applica-
tions of Cryptographic Techniques, Istanbul, Turkey, April 13–17, 2008, Springer, 2008,
pp. 1–18.
[63] Beaulieu, R., et al., “The SIMON and SPECK Lightweight Block Ciphers,” in Proceedings
of the 52nd Annual Design Automation Conference, 2015, pp. 1–6.
i i
i i
i i
[64] Chen, H., and X. Wang, “Improved Linear Hull Attack on Round-Reduced Simon with
Dynamic Key-Guessing Techniques,” in Fast Software Encryption: 23rd International
Conference, FSE 2016, Bochum, Germany, March 20–23, 2016, Springer, pp. 428–449.
[65] Song, L., Z. Huang, and Q. Yang, “Automatic Differential Analysis of ARX Block
Ciphers with Application to SPECK and LEA,” in Information Security and Privacy: 21st
Australasian Conference, ACISP 2016, Melbourne, Victoria, Australia, July 4–6, 2016,
Springer, pp. 379–394.
[66] Miyaguchi, S., “The FEAL Cipher Family,” in Advances in Cryptology-CRYPTO’90:
Proceedings 10, Springer. 1991, pp. 628–638.
[67] Biham, E., and A. Shamir, “Differential Cryptanalysis of Feal and N-Hash,” in Advances
in Cryptology—EUROCRYPT’91: Workshop on the Theory and Application of Crypto-
graphic Techniques, Proceedings 10, Brighton, UK, April 8–11, 1991, Springer, pp. 1–16.
[68] Schneier, B., et al., “Twofish: A 128-Bit Block Cipher,” NIST AES Proposal, Vol. 15,
No. 1, 1998, pp. 23–91.
[69] Lucks, S., “The Saturation Attack—A Bait for Twofish,” in Fast Software Encryption:
8th International Workshop, FSE 2001, Yokohama, Japan, Springer, pp. 1–15.
[70] Vanhoef, M., and F. Piessens, “All Your Biases Belong to Us: Breaking RC4 in WPA-TKIP
and TLS” in 24th USENIXSecurity Symposium (USENIXSecurity 15), 2015, pp. 97–112.
[71] Briceno, M., “A Pedagogical Implementation of A5/1,” 1995, http://www. scard.org.
[72] Barkan, E., E. Biham, and N. Keller, “Instant Ciphertext-Only Cryptanalysis of GSM
Encrypted Communication,” in Advances in Cryptology-CRYPTO 2003: 23rd Annual
International Cryptology Conference, Proceedings 23, Santa Barbara, California, August
17–21, 2003, Springer, pp. 600–616.
[73] Briceno, M., I. Goldberg, and D. Wagner, “A Pedagogical Implementation of the GSM
A5/1 and A5/2 ‘Voice Privacy’ Encryption Algorithms,” 1999, http://www.scard.org,
mirror at http://cryptome.org/gsm-a512.htm 26.
[74] Bernstein, D. J., et al., “ChaCha, a Variant of Salsa20,” Workshop Record of SASC,
Vol. 8, Citeseer, 2008, pp. 3–5.
[75] Aumasson, J.-P., et al., “New Features of Latin Dances: Analysis of Salsa, ChaCha, and
Rumba,” in Fast Software Encryption: 15th International Workshop, FSE 2008, Revised
Selected Papers 15, Lausanne, Switzerland, February 10–13, 2008, Springer, pp. 470–488.
[76] Bernstein, D. J., “The Salsa20 Family of Stream Ciphers,” New Stream Cipher Designs:
the eSTREAM Finalists, 2008, pp. 84–97.
[77] Nohl, K., “Mifare, Little Security, Despite Obscurity,” in The 24th Congress of the
Chaos Computer Club in Berlin, December 2007.
[78] Courtois, N. T., K. Nohl, and S. O’Neil, “Algebraic Attacks on the Crypto-1 Stream
Cipher in MiFare Classic and Oyster Cards,” Cryptology ePrint Archive, 2008,
https://eprint.iacr.org/2008/166.pdf.
[79] Hell, M., et al., “A Stream Cipher Proposal: Grain-128,” in 2006 IEEE International
Symposium on Information Theory, IEEE, 2006, pp. 1614–1618.
[80] Fu, X., et al., “Determining the Nonexistent Terms of Non-linear Multivariate Polyno-
mials: How to Break Grain-128 More Efficiently,” IACR Cryptol ePrint Archive, 2017,
p. 412.
[81] De Canniere, C., and B. Preneel, “Trivium,” New Stream Cipher Designs: The eSTREAM
Finalists, 2008, pp. 244–266.
[82] Fouque, P.-A., and T. Vannet, “Improving Key Recovery to 784 and 799 Rounds of
Trivium Using Optimized Cube Attacks,” in Fast Software Encryption: 20th International
Workshop, FSE 2013, Singapore, March 11–13, 2013, Springer, pp. 502–517.
[83] Boesgaard, M., et al. “Rabbit: A New High-Performance Stream Cipher,” in Fast
Software Encryption: 10th International Workshop, FSE 2003, Revised Papers 10, Lund,
Sweden, February 24–26, 2003, Springer, pp. 307–329.
i i
i i
i i
[84] Watanabe, D., et al. “Update On Enocoro Stream Cipher,” in 2010 International
Symposium On Information Theory & Its Applications, IEEE, 2010, pp. 778–783.
[85] Shibayama, N., and Y. Igarashi, “A New Higher Order Differential of Enocoro-128v2,”
in 2021 Ninth International Symposium on Computing and Networking Workshops
(CANDARW), IEEE, 2021, pp. 379–384.
[86] Ekdahl, P., and T. Johansson, “A New Version of the Stream Cipher SNOW,” in Selected
Areas in Cryptography: 9th Annual International Workshop, SAC 2002, St. John’s,
Newfoundland, Canada, August 15–16, 2002, Springer, pp. 47–61.
[87] Funabiki, Y., et al., “Several MILP-Aided Attacks Against SNOW 2.0,” in Cryptology
and Network Security: 17th International Conference, CANS 2018, Proceedings, Naples,
Italy, September 30–October 3, 2018, Springer, pp. 394–413.
[88] Watanabe, D., etal., “A New Key Stream Generator MUGI,” in Fast Software Encryp-
tion: 9th International Workshop, FSE 2002, Leuven, Belgium, February 4–6, 2002,
Springer, pp. 179–194.
[89] Watanabe, D., et al., MUGI Psuedorandom Number Generator, Self Evaluation, Tech.
Rep., Hitachi Ltd., 2001, http://www.sdl.hitachi.co.jp/crypto/mugi/index-e.html.
[90] ETSI/SAGESpecification, Specification of the 3GPP Confidentiality and Integrity
Algorithms 128-EEA3 & 128-EIA3, Document 2: ZUC Specification, Version: 1.6, 2011.
[91] Rivest, R. L., A. Shamir, and L. Adleman,“A Method for Obtaining Digital Signatures
and Public-Key Cryptosystems,” Communications of the ACM, Vol. 21, No. 2, 1978,
pp. 120–126.
[92] Boudot, F., et al., “Comparing the Difficulty of Factorization and Discrete Logarithm:
A 240-Digit Experiment,” in Advances in Cryptology–CRYPTO 2020: 40th Annual
International Cryptology Conference, CRYPTO 2020, Proceedings, Part II 40, Santa
Barbara, CA, August 17–21, 2020, Springer, pp. 62–91.
[93] Boudot, F., et al., “The State of the Art in Integer Factoring and Breaking Public-Key
Cryptography,” IEEE Security & Privacy, Vol. 20, No. 2, 2022, pp. 80–86.
[94] ElGamal, T., “A Public Key Cryptosystem and a Signature Scheme Based on Discrete Log-
arithms,” IEEE Transactions on Information Theory, Vol. 31, No. 4, 1985, pp. 469–472.
[95] Hoffstein, J., et al., “Practical Lattice-Based Cryptography: NTRUEncrypt and
NTRUSign,” in The LLL Algorithm: Survey and Applications (P. O. Nguyen, and V.
Vallee, eds.), Berlin: Springer-Verlag, 2009, pp. 349–390.
[96] Howgrave-Graham, N., “A Hybrid Lattice-Reduction and Meet-in-the-Middle Attack
against NTRU,” in Advances in Cryptology-CRYPTO 2007: 27th Annual International
Cryptology Conference, Proceedings 27, Santa Barbara, CA, August 19–23, 2007,
Springer, pp. 150–169.
[97] Fu, X., et al., “A key-Recovery Attack on 855-Round Trivium,” in Advances in
Cryptology–CRYPTO 2018: 38th Annual International Cryptology Conference,
Proceedings, Part II 38, Santa Barbara, CA, August 19–23, 2018, Springer, pp. 160–184.
[98] Hao, Y., et al., “Observations on the Dynamic Cube Attack of 855-Round TRIVIUM
from Crypto’18,” Cryptology ePrint Archive, 2018.
[99] PassMark Software, CPU Benchmarks. Intel Xeon Gold 6130, 2.10GHz, https://www
.cpubenchmark.net/cpu.php?cpu=Intel+Xeon+Gold+6130+%40+2.10GHz&id=3126.
[100] Hoffstein, J., et al., “Choosing Parameters for NTRUEncrypt,” in Topics in Cryptology–
CT-RSA 2017: The Cryptographers’ Track at the RSA Conference 2017, Springer: San
Francisco, CA, February 14–17, 2017, pp. 3–18.
[101] Bellare, M., and P. Rogaway, Introduction to Modern Cryptography, University of
California Davis Department of Computer Science, 2005, p. 283.
[102] Goldreich, O., Foundations of Cryptography: Volume 2, Basic Applications, Cambridge,
UK: Cambridge University Press, 2009.
[103] Oppliger, R., Cryptography 101: From Theory to Practice, Norwood, MA: Artech
House, 2021, https://rolf.esecurity.ch/?page_id=465.
i i
i i
i i
[104] Menezes, A. J., P. C. van Oorschot, and S. A. Vanstone, Handbook of Applied Cryptog-
raphy, Fifth Edition, Boca Raton, FL: CRC Press, 2001, https://cacr.uwaterloo.ca/hac/.
[105] Singh, S., The Code Book: The Science of Secrecy from Ancient Egypt to Quantum
Cryptography, New York: Anchor Books, 1999.
[106] Paar, C., and J. Pelzl, Understanding Cryptography–A Textbook for Students and
Practioners, Berlin: Springer Verlag, 2009, https://www.crypto-textbook.com/.
[107] Wong, D., Real-World Cryptography, Shelter Island, NY: Manning Publications, 2021,
https://www.manning.com/books/real-world-cryptography.
[108] Aumasson, J.-P., Serious Cryptography: A Practical Introduction to Modern Encryption,
San Francisco, CA: NoStarch Press, 2017, https://books.google.de/books?id=hLcrD-
wAAQBAJ.
[109] Stamp, M., and R. M. Low, Applied Cryptanalysis: Breaking Ciphers in the Real World,
Hoboken, NJ: Wiley-IEEE Press, 2007, https://www.cs.sjsu.edu/∼stamp/crypto/.
[110] Stinson, D. R., Cryptography: Theory and Practice, Third Edition, Boca Raton, FL:
Chapman & Hall/CRC Press, 2006.
[111] Raphael Chung-Wei Phan. “Mini Advanced Encryption Standard (Mini-AES): A Testbed
for Cryptanalysis Students,” Cryptologia 26.4 (2002), pp. 283–306.
[112] Nguyen, M. V., Number Theory and the RSA Public Key Cryptosystem – An Introduc-
tory Tutorial on Using SageMath to Study Elementary Number Theory and Public Key
Cryptography, 2009, https://faculty.washington.edu/moishe/hanoiex/Number%20The-
ory%20Applications/numtheory-crypto.pdf.
[113] Nguyen, M.V., Exploring Cryptography Using the Sage Computer Algebra System,
Bachelor of Science Thesis, Victoria University, Australia, 2009, www.sagemath.org/files
/thesis/nguyen-thesis-2009.pdf url2: https://www.sagemath.org/library-publications.html.
[114] Schneier, B., “A Self-Study Course in Block-Cipher Cryptanalysis,” Cryptologia, Vol. 24,
2000, pp. 18–34, https://www.schneier.com/wp-content/uploads/2015/01/paper-self-
study.pdf.
[115] Schaefer, E. F., Cryptography Research: Devising a Better Way to Teach and Learn
the Advanced Encryption Standard, Santa Clara University, 2011, https://web.archive
.org/web/20110829213229/http://www.scu.edu/cas/research/cryptography.cfm.
[116] Schaefer, E. F., “A Simplified Data Encryption Standard Algorithm,” Cryptologia,
Vol. 20, No. 1, 1996, pp. 77–84.
[117] Chung-Wei Phan, R., “Impossible Differential Cryptanalysis of Mini-AES,” Cryptologia,
Vol. 27, No. 4, 2003, pp. 361–374, https://www.tandfonline.com/doi/abs/10.1080/0161-
110391891964.
[118] Musa, M. A., E. F. Schaefer, and S. Wedig. “A Simplified AES Algorithm and Its Linear
and Differential Cryptanalyses,” Cryptologia, Vol. 17, No. 2, April 2003, pp. 148–177,
https://www.rose-hulman.edu/∼holden/Preprints/s-aes.pdf.
[119] Hoffman, N., “A Simplified IDEA Algorithm,” 2006, https://www.nku.edu/∼chris-
tensen/simplified%20IDEA%20algorithm.pdf.
[120] Davod Mansoori, S., and H. Khaleghei Bizaki, “On the Vulnerability of Simpli-
fied AES Algorithm Against Linear Cryptanalysis,” IJCSNS International Journal
of Computer Science and Network Security, Vol. 7, No. 7, 2007, pp. 257–263,
http://paper.ijcsns.org/07_book/200707/20070735.pdf.
i i
i i
i i
CHAPTER 2
CHAPTER 2
Paper-and-Pencil and Precomputer
Ciphers
The term paper-and-pencil methods (P&P methods, also called hand ciphers or
pen’n’paper ciphers) embraces all techniques that people can apply manually to
encrypt and decrypt (encipher or decipher) a message. This includes all classic
encryption methods (as opposed to those that require machines or computers), but
also some newer ones that were deliberately developed with the aim of achieving
a very high level of security by hand (which was not always successful), such as
ElsieFour, Solitaire, Hutton, or Handycipher.
P&P methods were also popular with secret services, as a writing pad and a
pencil are unsuspicious.
This chapter provides a broad overview (encyclopedic approach) of many of
these P&P methods, each with an example and references to deeper information.1
Section 2.5 in this chapter presents Hagelin rotor machines as an example of
electromechanical cipher machines that were in use until the 1970s.
At the end of this chapter (Section 2.8) you find sample code (for ciphers like
Caesar, Atbash, monoalphabetic substitution, Vigenè, Hill, columnar transposi-
tion) written for the computer-algebra system SageMath.
While this chapter describes the procedures from the point of view of modern
cryptography (and so that the ciphertext is already available correctly), Chapter 3
takes the view of a historian who first has to transcribe a found document before
he can cryptographically examine it.
The first paper-and-pencil methods already arose about 3,500 years ago in
Mesopotamia. All paper-and-pencil methods are a matter of symmetric methods.
Even the earliest encryption algorithms use the basic principles such as trans-
position, substitution, block construction, and their combinations. Hence, it is
worthwhile to closely consider these ancient methods especially under didactic
aspects.
Ciphers to be successful and widespread had to fulfill the same characteristics
required for modern algorithms:
1. The footnotes of this chapter describe how the cryptographic methods can be performed using the offline
programs CrypTool 1 (CT1), CrypTool 2 (CT2), and JCrypTool (JCT). See Sections A.2 and A.3. Many of
the methods can also be performed within a browser (e.g., on the website CrypTool-Online (CTO)). See
Section A.4.
While the CrypTool websites and programs offer both classic and modern ciphers, there are several
sites related to the American Cryptogram Association (ACA) [1] that provide very detailed focus only on
classic ciphers: for instance the sites of Bion [2] and Pilcrow [3].
39
i i
i i
i i
Convention: If the alphabet uses only 26 letters, we write from now onward the
plaintext in lowercase letters and the ciphertext in capital letters.
The letters of the ciphertext are—as used historically—grouped within blocks
of five letters. It does not matter if a different (constant) block length is used for the
output or if there is no separation by blanks.
Encrypting a message by means of transposition does not change the original char-
acters of this message, only their order in the plaintext is modified (transposition =
exchange). There is no ciphertext alphabet.
Sometimes, the name permutation is used to describe how characters, groups
of characters, numbers, or columns of the plaintext are exchanged; for example,
(1, 2, 3, 4, 5) ⇔ (3, 4, 2, 1, 5).
2. - Using CTO, this cipher can be seen in the browser in the plugin “Rail fence”: https://www.cryptool
.org/en/cto/railfence. Here, not only the result but also the graphical zigzag display is output.
- This method can also be found using CT1 Encrypt/Decrypt F Symmetric (classic) F Scytale /
Rail Fence.
- A rail fence with 2 lines and offset 1 can be simulated as simple columnar transposition; that is, using
CT1 Encrypt/Decrypt F Symmetric (classic) F Permutation, using as key “(B,A)” and accepting the
default settings (only one permutation, where your input is done line-by-line and the output is taken column-
by-column). This was done in Table 2.1.
Using the key “(A,B)” would start the zigzag pattern in Table 2.1 in such a way that the first letter is
written into the first line instead of the second line. Normally, the rail fence cipher cannot be simulated via
a simple columnar transposition.
i i
i i
i i
• Scytale3 [4]: This method has probably been used since 600 B.C.—a descrip-
tion of how it operated is not known from before Plutarch (50–120 B.C.).
A long strip of paper is wrapped around a wooden cylinder and then the
message is written along the length of this strip. After unwinding, the
strip contains the ciphertext. For decryption the recipient needs to have a
previously agreed cylinder of the same diameter.
• Grille cipher [5]: Both parties use identical stencils. Line by line, their holes
are filled with plaintext that is read out column by column to produce the
ciphertext. If there is plaintext left, the procedure is repeated.
• Turning grille [6]: The German army used turning grilles during WW1. It
was invented in 1881 by Eduard Fleissner von Wostrowitz.4 A square grille
serves as a stencil, a quarter of its fields being holes. The first part of the
message is written on a piece of paper through these holes, then the grille is
rotated by 90 degrees and the user can write down the second part of the
message, and so forth. But this method only works if the holes are chosen
carefully: Every field has to be used, and no field may be used twice. The
ciphertext is read out line by line.
In the example for a turning grille in Table 2.2 you can write 4 times 16
characters of the plaintext on a piece of paper (each character into the circles
which should symbolize a punched hole).
3. - Using CTO, this cipher can be seen in the plugin “Scytale”: https://www.cryptool.org/en/cto/
scytale. Here, also the graphical arrangement is displayed.
- This method can also be found using CT1 Encrypt/Decrypt F Symmetric (classic) F Scytale /
Rail Fence. As this method is a special case of a simple columnar transposition, you also can simulate
Scytale via CT1 Encrypt/Decrypt F Symmetric (classic) F Permutation: Use within the dialog box
only the first permutation. If the wood has, for example, four angles use as key “1,2,3,4.” This is equivalent
to writing the text horizontally in blocks of four letters in a matrix and to read it out vertically. Because the
key is in an ascending order, the Scytale is denoted as an identical permutation. And because writing and
read-out is done only once it is a simple (and not double) permutation.
- The Scytale can also be found in CT2 Startcenter F Templates F Cryptography F Classical.
4. Using JCT Default Perspective F Analysis F Fleissner-Grille-Analysis you can encrypt and
decrypt texts, but you can also attack ciphertexts encrypted with this turning grille.
Another nice visualization can be found archived under https://web.archive.org/web/20050922
123752/http://www.turning-grille.com:80/.
i i
i i
i i
i i
i i
i i
Column transposition, General Luigi Sacco [6]: The columns of a table are num-
bered according to the letters of the keyword. The plaintext is entered line by line,
in the first line up to column number one, in the second line up to column number
two, and so forth. Again, the ciphertext is read out in columns.
See Table 2.4.
Plaintext: an example of transposition
9. Using CT1: Choose a key for first permutation, input line by line, permute column by column and output
line by line. The component in CT2 also visualizes the row-wise transposition.
i i
i i
i i
Cadenus cipher [1]: Cadenus is a form of a columnar transposition that uses two
keywords. Cadenus combines a complete columnar transposition with a keyed
column rotation. The procedure—both for encryption and decryption—is rather
error-prone.
Let’s say the first keyword (KEY) has a length of n = 3. The second keyword
has a maximal length of the alphabet. It can be shorter, but it must contain the letters
of the first keyword. The second keyword is a permutation of the used elements.
We have a table with a first column (stub column), and three blocks each con-
sisting of n columns. The first keyword is written in the header row of each block
and used to swap the columns of the second and third block later.
The second keyword is used to build the stub column and so define the initial
letter of each column of the third block.
The plaintext is filled line by line in the first block. Then each column of the first
block is moved to the second block, transposed in the order of the first keyword.
The columns of the third block are created by copying each column from block 2 to
block 3 and moving the elements within a column wrap-around such that it begins
with the letter, which is in the same line as the corresponding key letter of the first
keyword within the second keyword. The ciphertext is then read out line by line
from the third block.
See Table 2.6: The letters of the first keyword are marked bold in the stub
column. Within the second block, those letters are printed blue, which will be at
i i
i i
i i
the top of the columns in block 3 (after wrapping around the selected columns). The
sample here is a slightly enhanced version of Cadenus, as the length of the second
keyword must not be exactly 25. But still the plaintext length (here 51 with the filler
“x”) has to be a multiple of the length of the second keyword (here 17).
Ciphertext: SAASR PIFIU LONNS KTGWN EDOOA TXNND IIUFA SMYOC ROUCO AEMRS R.
Substitution methods assign to each plaintext object (i.e., to each element of the
plaintext alphabet or to each element of the nomenclator) a ciphertext object (a
ciphertext character or the corresponding nomenclator code).
Monoalphabetic substitution ciphers keep the same assignment for the whole
encryption process once the assignment is decided—in contrast to polyalphabetic
substitution. Treating more than one letter as one object is called polygraphic sub-
stitution. If an object in the plaintext alphabet can be mapped to more than one
object in the ciphertext alphabet, it is called homophonic. If an object in the cipher-
text alphabet can be mapped to more than one object in the plaintext alphabet,
it is called polyphonic—this has been rarely used in the wider world because the
decryption is no longer unique, but it is a common cipher type in the ACA where
it’s known as a key phrase cipher.
i i
i i
i i
Atbash cipher11 [4]: Replace the first letter of the alphabet by the last letter of
the alphabet, the second one by the second-to-last, and so forth. So the key is an
inversion of the given alphabet.
Shift cipher or Caesar cipher12 [4]: The ciphertext alphabet is created by shifting
the whole plaintext alphabet by a determined number of letters. The shift value is
less than the length of the alphabet. Remark: Emperor Caesar always shifted by 3
positions.
Plaintext: three positions to the right
Ciphertext: WKUHH SRVLWLRQV WR WKH ULJKW
Affine cipher13 : This is a generalization of the shift cipher. A plaintext character is
first substituted by another character and then the result is encrypted using the shift
cipher. The name “affine cipher” was chosen because its encryption and decryption
can be described as affine or linear function.
Substitution with symbols [4], for instance the so-called freemason cipher: Each
letter is replaced with a symbol.
Variants: Fill characters, intentional mistakes [4].
Nihilist substitution14 [1]: The alphabet is entered into a 5 × 5 matrix and during
processing each plaintext letter is assigned the number formed from the row and
column number. The alphabet is built from a first keyword (SUBSTITUTION ==>
SUBTION) and the remaining letters of the alphabet in the normal order. Then a
second keyword (KEY) is chosen and placed above the columns of a second table.
The plaintext is entered line by line (row by row) into this table. The ciphertext’s
numerical values are written below each plaintext letter—each of these values is
the sum of the number of the plaintext letter and the number of the keyword letter.
Numbers between 100 and 110 are transformed to numbers between 00 and 10,
so that each letter is represented by a two-digit number. Here is the example cal-
culation for the first letter in the plaintext: Since A = 23 and K = 35, a becomes
23 + 35 = 58.
i i
i i
i i
Ciphertext: 58 53 85 88 54 96 78 72 85 56 63 65 47 44 65 49 46 68 47
55 69 56 53
Codes [4]: In the course of time, codebooks were used again and again. A codebook
assigns a codeword, a symbol, or a number to every possible word of a message.
Only if both parties hold identical codebooks and if the assignment of codewords
to plaintext words is not revealed, a successful and secret communication can take
place.
15. Pure steganography tries to conceal the existence of the message instead of encrypting it.
Different steganographic techniques can be found in CT2: For example, image steganography (with
BPCS and with LSB), text steganography [with capital letters (alone or in binary mode), with letter
marking, with zero width spaces], or watermarking (invisible, robust, or visible). See CT2 Templates F
Steganography F Image Steganography with BPCS.
i i
i i
i i
Straddling checkerboard16 [5]: A 3×10 matrix is filled with the 26 letters of the used
alphabet and two arbitrary digits (or special characters) as follows: The different
letters of a keyword and the remaining characters are written into the grille. The
columns are numbered 0 to 9, the second and the third line are numbered 1 and
2. Each plaintext character is replaced by the corresponding digit, respectively the
corresponding pair of digits. As “1” and “2” are the first digits of the possible
two-digit numbers, they are not used as single digits. The special thing is that the
ciphertext characters sometimes have 1 digit and sometimes 2 digits: The letter “K”
becomes “0,” “E” becomes “3,” but “B” becomes “10.”
See Table 2.8.
Plaintext: an example of substitution
i i
i i
i i
traversed column by column from the grille and transferred row by row into the
matrix.
See Table 2.9.
Plaintext: an example of substitution
• The seven most frequent letters in Spanish are distributed in the first row;
• Four instead of three rows are used;
• So one could encrypt 10 · 4 − 3 = 37 different characters.
Tridigital cipher [1]: A keyword with 10 letters is used to create a numeric key by
numbering its letters corresponding to their alphabetical order. This key is written
above the columns of the 3 × 10-matrix. This matrix is filled line by line with the
alphabet as follows: The different letters of a keyword are inserted first, followed by
the remaining letters. The last column is left out. Plaintext characters are substituted
with numbers, and the number of the last column is used to separate words.
i i
i i
i i
Baconian cipher19 [1]: This is actually a code and not a cipher (there is no key).
Assign a five-digit binary code to every letter and to six numbers or special charac-
ters (00000 = A, 00001 = B, etc.), and replace the plaintext characters with this
binary code. Now use a second, unsuspicious message to hide the ciphertext inside
of it. This may happen by upper and lower case or italicized letters: For example,
all letters of the unsuspicious message below a binary “1” are capitalized. Overall
this is obtrusive.
See Table 2.10.
Table 2.10 Baconian Cipher
Plaintext / message F I G H T
Intermediate ciphertext 00101 01000 00110 00111 10011
Unsuspicious message itisw arman thesu nissh ining
Ciphertext itIsW aRman thESu niSSH IniNG
i i
i i
i i
Beale cipher [4]: The Beale cipher is a book cipher that numbers the words of a key
text. These numbers replace the plaintext letters by the words’ initial letters.
Grandpré cipher [6]: A square grille with 10 columns (other layouts are possible,
too) is filled with 10 words. The initial letters should result in an eleventh word. As
columns and rows are numbered from 0 to 9, letters can be replaced by two-digit
numbers. It is obvious that with the table having 100 fields, most letters can be
represented by more than one pair of numbers. You should keep in mind that those
10 words have to contain all letters of the plaintext alphabet.
Spanish strip cipher (SSC) [9]: This homophonic substitution cipher was the official
method of ciphering by the Spanish ministries in the late 19th century, and the
method mostly used by both sides, the Republicans and the Nationalists, in the
Spanish Civil War (1936–1939).21
21. - CT2 Templates F Cryptography F Classical F Spanish Strip Cipher. See Figure 2.3. CT2 can
break it with the Homophonic Analyzer.
- MTC3: For example, https://mysterytwister.org/challenges/level-2/spanish-strip-cipher-
part-1.
- The Kopal video explains in detail how the keys are generated and how to break this cipher with CT2:
https://www.youtube.com/watch?v=-C-hgnrUMKo.
i i
i i
i i
Grand Chiffre [4]: This cipher was used by Louis XIV in the 17th century and was
not solved until the end of the 19th century. Cryptograms consisted of 587 different
numbers, every number representing a syllable. The inventors of the Grand Chiffre
(Rossignol, father and son) constructed additional traps to increase security. For
example, a number could assign a different meaning to or delete the preceding one.
Compare the “operational code elements” in Chapter 3.
Playfair cipher22 [4]: A 5 × 5-matrix is filled with the plaintext alphabet (e.g., the
Latin alphabet without the “J”) in the following way: The different letters of a
keyword are inserted first, followed by the remaining letters (like in the straddling
checkerboard). The plaintext (PT) is then divided into pairs; these digraphs are
encrypted using the following rules:
1. If both letters can be found in the same column, they are replaced by the
letters underneath.
2. If both letters can be found in the same row, take the letters to their right.
3. If both letters of the digraph are in different columns and rows, the replace-
ment letters are obtained by scanning along the row of the first letter up to
the column where the other letter occurs and vice versa.
4. Double letters are treated by special rules, if they appear in one digraph.
They can be separated by a filler, for example.
1. Three equal letters are substituted by three equal letters, which is the letter
on the right underneath the original letter (example from Table 2.11: BBB
⇒ LLL).
2. A trigraph with two different letters is encrypted like a digraph in Playfair.
i i
i i
i i
i i
i i
i i
the entire text that follows unusable. Such errors can occur at the encryptor, in
transmission, in reception, or occur at the decryptor (i.e., also at the parties who
know the correct key).
Vigenère variants:
• Interrupted key: The key is not repeated continuously, but starts again with
every new word of the message.
• Autokey24 [6]: After using the agreed key, use the message itself as a key.
See Table 2.14.
23. - CTO in the plugins “Vigenère,” “Autokey,” “Beaufort,” “Porta,” and “Trithemius.” In addition, CTO
contains an interactive analyzer to determine the key length and the smallest value of the autocorrelation:
https://www.cryptool.org/en/cto/vigenerebreak. For an automated analysis the autocorrelation is
used: https://www.cryptool.org/en/cto/autocorrelation.
- CT1 Encrypt/Decrypt F Symmetric (classic) F Vigenère
Visualized in CT1 Indiv. Procedures F Visualization of Algorithms F Vigenère...
- CT2 Templates F Cryptography F Classical F Vigenère. In addition, CT2 contains powerful ana-
lyzers for this cipher.
- JCT Default Perspective F Algorithms F Classic F Vigenère
24. Autokey can be found in the CT variants mainly the same way as Vigenère.
i i
i i
i i
• Progressive key [6]: The key changes during the process of encryption.
With every repetition, the characters of the keyword are shifted about one
position. KEY becomes LFZ.
• Gronsfeld [6]: Variant of Vigenère that uses a numeric key.
• Beaufort 25 [6]: Variant of Vigenère, the key is subtracted, not added. The
ciphertext alphabets may be written backwards.
• Porta [1]: Variant of Vigenère with only 13 alphabets. As a consequence,
two letters of the keyword are assigned the same ciphertext alphabet and
the first and the second half of the alphabet are reciprocal.
• Slidefair [1]: This method can be used as a variant of Vigenère, Gronsfeld, or
Beaufort. Slidefair does encrypt digraphs according to the following rules:
Look up the first letter in the plaintext alphabet above the tableau. Then
look up the second one in the row belonging to the corresponding keyword
letter. These two letters make up opposite corners of an imaginary rectangle.
The letters at the two remaining corners substitute the digraph.
One-time pad (OTP)26,27 : This is a major concept: A sequence of key bytes (pad)
is XORed byte-by-byte to the plaintext, or a sequence of key digits is added. OTP
was the first information theoretically secure scheme (see Section 1.8.3). This can
be considered as a generalization of Vigenère’s cipher. Vernam applied for a patent
for this process in 1918.
To fulfill this claim the pad must be random, and it must be used only once (to
eliminate any semblance of pattern from the ciphertext).
Reason to use the key pad only once: Given ciphertext C, plaintext P, pad K,
and two plaintexts encrypted with the same key: C1 = P1 ⊕ K; C2 = P2 ⊕ K;
thus, C1 ⊕ C2 = (P1 ⊕ K) ⊕ (P2 ⊕ K) = P1 ⊕ P2; which effectively could leak the
plaintexts.28
Superposition (some variants of the OTP)
• Running-key cipher: A key text (for example out of a book) is added to the
plaintext.
• Superposition with numbers: A sequence like Fibonacci or a number of
sufficient length (for example pi) is added.
25. - In CTO in the plugin “Beaufort”: https://www.cryptool.org/en/cto/beaufort
- In CT2 part of the Vigenère component and template (including the autokey variant).
26. On a big scale OTPs have been successfully broken by Americans and British during the “Venona” project
because of wrong usage by the Soviet spies.
27. Implementations of the OTP can be found in:
- CTO in the plugins “Vernam” and “XOR”: https://www.cryptool.org/en/cto/vernam,
https://www.cryptool.org/en/cto/xor
- CT1 Encrypt/Decrypt F Symmetric (classic) F Vernam / OTP
CT1 Encrypt/Decrypt F Symmetric (classic) F XOR
- Two templates, one for Vernam and one for XOR, can be found at CT2 F Cryptography F Classical
- JCT Default Perspective F Algorithms F Classic F XOR
- Section 9.3.1 contains a detailed description of the OTP as bitstream cipher and its implementation in
SageMath.
28. Via JCT Default Perspective F Analysis F Viterbi Analysis you can play with an automatic
cryptanalysis of running-key ciphertexts. You can see how astonishing it is, if you get little by little—from
XORed ciphertexts or from XORed plaintexts—both original plaintexts. See Figure 2.4.
i i
i i
i i
Figure 2.4 Viterbi analysis of an XOR cipher (like in the OTP) in JCT.
Phillips cipher [1]: The alphabet is filled into a square table with five columns. Seven
more tables are generated by first shifting the first row one position toward the
bottom, then shifting the second row toward the bottom. The plaintext is divided
into blocks of five that are encrypted with one matrix each. Letters are substituted
by the ones on their right and underneath.
Ragbaby cipher [1]: Construct an alphabet with 24 characters. Then number
the plaintext characters, starting the numeration of the first word with “1,” the
numeration of the second one with “2,” and so forth. Number 25 corresponds to
number 1. Each letter of the message is encrypted by shifting it the corresponding
positions to the right.
See Table 2.15.
Alphabet: KEYWORDABCFGHILMNPSTUVXZ
In the history of cryptography one often comes across combinations of the previ-
ously mentioned methods. These have become—on average—proven to be safer
than procedures that are based only on one of the principles of transposition or
i i
i i
i i
substitution. However, cascades29 do not have to be safer (e.g., the sequential exe-
cution of two Caesar ciphers with different shift values is simpler than the unique
executing of Caesar with a third shift value), so that’s not at all a security gain. On
the other hand, executing two column transpositions one after the other can lead to
a significant gain in security; it is equivalent to a column transposition in which the
key is as long as the product of the two individual key lengths, provided the keys are
constructed correctly. See https://mysterytwister.org/challenges/level-
3/double-column-transposition-reloaded-part-1.
ADFG(V)X30 [4]: ADFG(V)X-encryption was developed in Germany during World
War I. The alphabet is filled into a 5 × 5 or 6 × 6 matrix, and columns and rows
are marked with the letters ADFGX and V, depending on the size of the grille. Each
plaintext character is substituted by the corresponding pair of letters. Finally, a
(row-) transposition cipher is performed on the resulting text.
Fractionation [6]: Generic term for all kinds of methods that encrypt one plaintext
character by several ciphertext characters and then apply a transposition cipher to
this intermediate ciphertext so that ciphertext characters originally belonging to
each other are separated.
29. Running the same cipher twice in a row is also called a cascade.
30. - CTO plugin “ADFG(V)X”: https://www.cryptool.org/en/cto/adfg-v-x
- CT1 Encrypt/Decrypt F Symmetric (classic) F ADFGVX
- CT2 Templates F Cryptography F Classical F ADFGVX. In addition, CT2 contains analyzers for this
cipher.
- JCT Default Perspective F Algorithms F Classic F ADFGVX
i i
i i
i i
Bazeries cipher [1]: The plaintext alphabet is filled into a 5 × 5-matrix column by
column, a second matrix is filled line by line with a keyword (a number smaller
than a million) followed by the remaining letters of the alphabet. Then the message
is divided into blocks of arbitrary length and their characters’ order is inverted.
Finally, each letter is substituted—according to its position in the original matrix—
by its counterpart in the second matrix.
See Table 2.17.
The second table in Table 2.17 has three lines: The first shows the plaintext split
into blocks, the second shows the inverted blocks, and the third the ciphertext. The
encryption is clear, but the decryption is only unique if the lengths of the blocks is
exchanged as an additional key parameter.
Digrafid cipher [1]: To explain the Digrafid substitution, Table 2.18 is used (to
simplify matters, the alphabet was left in its original order). Look up the first letter
(here c) of the first digraph in the horizontal alphabet and write down the column
number 3. Then look up the second letter o in the vertical alphabet and write down
the corresponding line number 6. Between these two numbers, the number 2 at the
intersection point is set. Afterward, the triples are written vertically underneath the
digraphs that are arranged in groups of three. The three-digit numbers 3,4,9 arising
horizontally are transformed back into digraphs LI.
i i
i i
i i
Note that for a complete description, it is necessary to explain how sender and
receiver handle texts that fill in the last block only 1–5 characters. The possibil-
ities range from ignoring a last and incomplete block to padding it with random
characters or with characters predefined in advance.
See Table 2.18.
Table 2.18 Digrafid Cipher
1 2 3 4 5 6 7 8 9
A B C D E F G H I 1 2 3
J K L M N O P Q R 4 5 6
S T U V W X Y Z . 7 8 9
A J S 1
B K T 2
C L U 3
D M V 4
E N W 5
F O X 6
G P Y 7
H Q Z 8
I R . 9
co mb in in gs ub st it ut io na nd tr an sp os it io
3 4 9 9 7 3 1 9 3 9 5 5 2 1 1 6 9 9
2 4 2 2 3 7 9 3 9 2 4 4 8 2 8 6 3 2
6 2 5 5 1 2 2 2 2 6 1 4 9 5 7 1 2 6
LI KB FN .C BY EB SU I. BK RN KD FD BA HQ RP X. FT AO
Nicodemus cipher [1]: First, a simple columnar transposition is carried out. Before
reading out the columns, the message is encrypted additionally by Vigenère (all
letters of a column are enciphered with the corresponding keyword letter). The
ciphertext is read out in vertical blocks.
See Table 2.19.
Table 2.19 Nicodemus Cipher
K E Y E K Y E K Y
c o m o c m S M K
b i n i b n M L L
i n g n i g R S E
s u b u s b Y C Z
s t i t s i X C G
t u t u z t Y J R
i o n o i n S S L
a n d n a d R K B
t r a r t a V D Y
n s p s n p W X N
o s i s o i W Y G
t i o i t o M D N
i i
i i
i i
The P&P procedures include both classic procedures and newer ones—which
should always be executable by hand and operate on a few printable characters.
The new methods include, for example, LC4 (2017) and Handycipher (2014).
Pinprick encryption [4]: For centuries, this simple encryption method has been
put into practice for different reasons (actually steganography). During the Victo-
rian Age, for example, small holes underneath letters in newspaper articles marked
the characters of a plaintext, as sending a newspaper was much cheaper than the
postage on a letter.
Stencil: Stencils (cardboard with holes) are also known as a Cardinal-Richelieu-Key.
Sender and receiver have to agree upon this stencil. The stencil is laid above a text
and the letters that remain visible make up the ciphertext. This is not to be confused
with the Grille of Section 2.1.1, because here not only the scrambled plaintext letters
are transmitted, but the entire text, most of whose letters are meaningless (called
nulls).
Card games [6]: The key is created by means of a pack of cards and rules that are
agreed upon in advance. All methods mentioned in this paragraph are designed as
paper-and-pencil methods (i.e., they are applicable without electronic aid). A pack
of cards is unsuspicious to outsiders, shuffling the deck provides a certain amount
of coincidence, and cards can be transformed into numbers easily to be used in a
substitution cipher without any further aid.
Solitaire cipher (Bruce Schneier)32 [11]: Sender and receiver have to own a deck of
cards shuffled in the same manner. A key stream is generated that has to consist of
as many characters as the message to be encrypted.
The algorithm to generate the key is based on a shuffled deck of 54 cards (ace,
2–10, jack, queen, king in four suits, and two jokers). The pack of cards is held
face up:
1. Swap the first joker with the card beneath it.
2. Move the second joker two cards down.
31. MTC3 offers a number of related challenges: If you enter in your browser at https://mysterytwister
.org/challenges/level-2/ the search item “Granit,” you’ll find six challenges about it.
A detailed 20-page description about the Granit cipher can be found at:
https://mysterytwister.org/media/challenges/pdf/mtc3-drobick-01-doppelwuerfel-01-en.pdf
32. - CT1 Encrypt/Decrypt F Symmetric (classic) F Solitaire (detailed GUI window);
- CT2 Templates F Cryptography F Classical F Solitaire. In addition, CT2 contains a brute-force
analyzer for this cipher.
i i
i i
i i
3. Now swap the cards above the first joker with those below the second one.
4. Look at the bottom card and convert it into a number from 1 to 53 (bridge
order of suits: clubs, diamonds, hearts, spades; joker = 53). Write down this
number and count down as many cards starting with the top card. These
cards are swapped with the remaining cards; only the bottom card remains
untouched.
5. Look at the top card and convert it into a number as well. Count down as
many cards starting with the top card.
6. Write down the number of the following card. This card is converted into
your first keystream character. As we need numbers from 1 to 26 to match
the letters of our alphabet, clubs and hearts correspond to the numbers 1 to
13, diamonds and spades to 14 to 26. If your output card is a joker, start
again.
For each keystream character you would like to generate, these six steps have
to be carried out. This procedure is—manually—very lengthy (4 hours for 300
characters, dependent on your exercise) and requires high concentration.
Encryption takes place by addition modulo 26. Encryption is relatively fast
compared to the key stream generation.
This P&P cipher creates a key stream that is so good, even today it is hard to
crack the cipher if you don’t know the originally sorted card deck (ciphertext-only
attack).
Mirdek cipher (Paul Crowley) [12]: Even though this method is quite complicated,
the author provides a good example to illustrate the procedure.
Playing card cipher (John Savard) [6]: This algorithm uses a shuffled deck of 52
cards (no joker). Separate rules describe how to shuffle the deck. A keystream is
created via the following steps:
1. The pack of cards lies in front of the user, top down. Cards are turned up
and dealt out in a row until the total of the cards is eight or more.
2. If the last card dealt out is a jack, queen, or king, write down its value;
otherwise write down the sum of the cards dealt out (a number between 8
and 17). In a second row, deal out that number of cards.
3. The remaining cards are dealt out in rows under the second row. The first
one ends under the lowest card of the top row, the second one under the
next lowest card, and so on. If there are two identical cards, red is lower
than black.
4. The cards dealt out under step 3 are collected column by column, starting
with the column under the lowest card. The first card that is picked up
becomes the bottom card (face up).
5. The cards dealt out in step 1 and 2 are picked up, beginning with the last
card.
6. The deck is turned over, the top card is now the bottom card (face down).
Afterward, steps 1 to 6 are repeated twice.
i i
i i
i i
To generate a keystream character, write down the first card not being a jack, queen,
or king. Count down that number of cards. The card selected has to be between 1
and 10. Now repeat these steps beginning with the last card. These two numbers
are added and the last digit of the sum is your keystream character.
Josse’s cipher33 [13]: Josse’s cipher was invented by the French major H. D. Josse
(1852–1929). This method has only recently been rediscovered and was described
by Rémi Géraud-Stewart and David Naccache. It is a relatively simple substitution
cipher, but additional security features have been added. That includes that the first
letter is encrypted differently than the rest of the letters, and that there is some kind
of error propagation (autokey), so that an incorrect letter at any point makes the
entire following text unusable.
VIC cipher34 [6]: This is a highly complicated but relatively secure paper-and-pencil
method. It was developed and applied by Soviet spies. Among other things, the user
had to create 10 pseudorandom numbers out of a date, the first words of a sentence,
and any five-digit number. A straddling checkerboard is part of the encryption, too.
A detailed description can be found in [6].
Handycipher35 [14]: Handycipher is a homophonic substitution cipher, which
inserts randomly chosen null characters. The cipher was improved several times
using the feedback of the solvers in MTC3.
ElsieFour cipher36 [15]: ElsieFour (shortened LC4) combines ideas of modern
RC4 stream cipher, historical Playfair cipher, and plaintext-dependent keystreams
(autokey). It can be computed manually.
Hutton cipher37 : Hutton is a polyalphabetic substitution using a password, build-
ing a keyed alphabet from a keyword, and then dynamically mix the alphabets
during the encryption/decryption process. Hutton was invented in 2018, and
i i
i i
i i
refined with version 2 in 2019. It is similar to the Quagmire III cipher defined
by ACA.
So far, in this chapter, we discussed the encryption methods that can be easily used
by anyone who has just a pencil and a piece of paper. However, such methods are
very slow when larger amounts of text have to be encrypted. They also are not
secure enough, especially in the scenarios when someone who wants to break the
encryption can collect a relatively large amount of ciphertext that was the result of
encryption with the same key.
At the beginning of the 20th century, with the development of radio the vol-
ume of information that was transmitted vastly increased. As before, the military
and diplomatic information was often sensitive and needed to be confidential. This
situation caused a need for fast, more secure, and more accurate encryption (and
decryption) methods. The problem was solved by rotor cipher machines, which
began to appear right after World War I [16]. It is believed that they were invented
by two Dutch navy officers, Theo A. van Hengel and R. P. C. Spengler [17], who
built the first machine for the Dutch Navy already in 1915 [18]. The rotor machines
were the state-of-the-art tools used for achieving confidentiality of data before they
were replaced by computers in the 1970s. Probably the most famous examples of
rotor machines are Enigma, Sigaba, Hebern, and Hagelin M-209 also known as
CSP-1500, C-38, and AM-1.
In the next sections, we discuss several Hagelin machines and show their usage
in CrypTool 2 (note that CrypTool 2 also includes the rotor machines Enigma,
Typex, SZ42, Sigaba, and Fialka).
i i
i i
i i
was the first fully mechanical pin-and-lug cipher machine and became the basic
design on which all Hagelin’s later machines would be based (see Section 2.5.2.2
for more information about the Hagelin machine). C-35 consisted of a drum with
25 bars, five pinwheels, and a type-wheel [21].
C-36 and C-362 were the next models of Hagelin machines, which had only
slight modifications as compared to C-35. These included protective casing, differ-
ent arrangements of the bar lugs, and later on, movable lugs on the drum (in C-336).
In the pre-war years, C-36 and C-362 models were purchased by France, Great
Britain, Italy, Germany, and some other European countries. C-37 is an extremely
rare successor of C-36 that was used by the French Navy and also for French-British
liaisons.
The next device developed by Hagelin was the C-38 machine, which had six
pinwheels as compared to five wheels in the previous models. Another change was
that the drum lugs of C-38 could slide in one of five active or in an inactive posi-
tion. These improvements considerably increased the key space and thus increased
the security of the machine. M-209 (Figure 2.7) was the U.S. Navy and the U.S.
military variant of the C-38 that served for the American Army during the period
i i
i i
i i
of time starting shortly before World War II and until after the Vietnam War [21].
About 140,000 units of this model were produced. This model and its implementa-
tion in CrypTool 2 are nicely presented on the YouTube channel Cryptography for
Everybody [22].
The BC-38 electromechanical cipher machine, as the name suggests, was an
improved model of the mechanical C-38. “B” was added as a prefix to the model
number to indicate the presence of a keyboard.
The latest Hagelin machines we discuss are the ones that refer to the model
range C-52/CX-52, which were developed in 1952. Information about the machines
that appeared later can be found in [19] and [21]. The C-52 had great success on the
market. This machine had six removable cipher wheels—the pinwheels—that could
be configured outside of the machine and installed in any order. A more advanced
and secure version was the CX-52 where the rotation of the pinwheels became
irregular. It is considered to be one of the most successful Hagelin mechanical cipher
machines, which made the encryption much more secure.
Before the CX-machines were invented, the United States and United Kingdom
were able to break the high-level cipher systems of most of the countries. The devel-
opment of the CX-52 model changed the situation, which resulted in the Rubicon
operation (see Section 2.5.2.4).
In the next section, the architecture of these latter machines is explained.
i i
i i
i i
In this equation Ind('Z') is the constant value that is the index of the character
'Z' in the alphabet and is equal to 25.
Let’s consider the following example. Suppose that we want to encrypt plain-
text P = ('K', 'C') and the 2 displacement values generated by a given Hagelin
machine are D = {d1 , d2 } = {4, 1}. Then the ciphertext is computed as follows:
i i
i i
i i
• The set of 6 pinwheels (also known as keywheels, pin disks, rotors, cipher
wheels or just wheels);
• Rotating cage (also known as drum) with 32 bars.
The pinwheels for each of the machine versions can be selected from a set of
12 with 25, 26, 29, 31, 34, 37, 38, 41, 42, 43, 46, and 47 pins. The wheels are
labeled with both letters and numbers. Next to each label there is a pin that can be
set to an active or nonactive state.
A printer located at the left of the machine (Figure 2.8) acts as the input/output
device. It has a double print head, where one letter ring contains the alphabet in the
regular order, and the rightmost ring—the alphabet in reversed order (Figure 2.9).
We call the former the input ring and the latter the output ring.
To encrypt each character pi the operator sets the input ring of the printwheel
to the position of this character. Then he turns the handle, and the drum makes a
complete revolution. Each of the 32 bars located in the drum can be affixed with the
small lugs at one or more of the six positions against each of the wheels [21]. During
the revolution of the drum all the lugs that are affixed to the bars will contact the
active guide arm of the wheel if the pin currently located against the drum is active.
All bars whose lugs had this contact will slide to the left. Each bar that is slid to
the left becomes an additional tooth on the drum, which will displace the output
ring by one extra position. That is, the total displacement value di is equal to the
i i
i i
i i
Figure 2.9 Double print head with two letter rings; in regular-alphabet and in reversed-alphabet
order [19].
number of bars that were slid to the left during the revolution of the drum. After
the displacement value di is computed, the encryption happens following (2.1).
To make sure that decryption is possible, both sender and receiver must set
their machines in the same way. The wheel pins and the lugs that form an internal
secret key were normally changed on a daily basis, according to the key lists that
were distributed periodically [24]. To keep the communication secure, the initial
position of the six wheels, which is called an external key, has to be changed for
each new message.
Advancement of the wheels. In the case of the C-52 model, all the pin wheels regu-
larly step by one position after each character encryption. However, in some of the
CX-52 versions, this advancement of the wheels happens irregularly, which makes
the encryption considerably more secure. This is realized by the special drum bars
which have cams that can advance the pinwheels, so that the next cycle starts with
a different pinwheel setting and thus another set of six active and inactive pins [23].
Those bars, which can influence the stepping of the wheels, are called advance bars.
If a bar is forced to the left by an active guide arm that contacts a lug, the wheel
that is commanded by that bar will move.
Key space size. Assuming that the pin wheels and bars are known and are not part
of the key, the whole key space of the machine is composed of the wheel settings key
space and the lug settings key space. The wheel settings key space depends on the
set of the selected pin wheels. Suppose that the selected machine pin wheels have
the sizes that form a set: L = {l1 , l2 , ..., l6 }. Then the number of all possible initial
positions of the wheels is given by:
Ki = l 1 · l 2 · l 3 · l 4 · l 5 · l 6
Moreover, each of the wheel pins can be active or not active. In total there are
l1 + l2 + l3 + l4 + l5 + l6 pins. Hence, the total number of possible pin settings is:
i i
i i
i i
In addition, the machine has 32 bars, where each bar has six positions where lugs
can be placed (against each of the pin wheels). Some of the bars cannot be lugged.
If such bars are used in the machine, they should not be included in the key space
size computation.
The total number of lugs is 32 · 6 = 192. Therefore the maximal number of all
possible lug settings is:
Kl = 2192
For example, if the selected wheel sizes are L = {l1 , l2 , ..., l6 } = {29, 31, 37, 41, 43,
47} and all the bars can be lugged then the total key space of such machine is:
i i
i i
i i
i i
i i
i i
agreement in which sales to certain listed countries were now prohibited legally.
Later, the company Crypto AG was bought by the German Bundesnachrichtendi-
enst (BND) and CIA, who used a complex scheme of companies and fiduciaries in
order to hide the actual ownership from public view [19].
i i
i i
i i
i i
i i
i i
attack. Because of this property, CX-52 was used as a backup cipher machine during
the Cold War. In some countries, such as Belgium, this was the case up to the
1990s [19].
In this section, we showed how the machine was constructed and demonstrated
how various C(X)-52 models work by implementing them in CT2.
i i
i i
i i
as Gromark. Variants can arise, for example, from how the ciphertext alphabet is
generated from the keyword in a monoalphabetic substitution or how the characters
are arranged in a Polybius square. These puzzles are good training for cryptanalytic
skills. In contrast to this, in the DECRYPT project or in the journal Cryptologia,
real methods actually used in history are described and examined.
All 55 ACA procedures can also be found in CT2 and in CTO,38 at Bion [2],
and many at Phil Pilcrow [3] and at Oliver Kuhlemann [28].
In addition, CTO has Neural Cipher Identifier39 (NCID), a plugin that can
identify via different neural networks the type of the ACA cipher using only a short
piece of ciphertext: With ciphertexts of a length of 100 characters, on average a
correct detection rate over 80% was achieved [29]. A similar implementation called
neural net ID test, but without a description of the internals, is also provided by
Bion [2]. From Q1/2024, the classifiers developed by Dalton/Stamp to differentiate
between five rotor machines will also be included in NCID [30].
This section can be read as a kind of chapter appendix, implementing several clas-
sic ciphers by using the open-source computer-algebra system SageMath.41 All the
following ciphers have been explained previously in this chapter.
i i
i i
i i
To make the sample code42 of the ciphers easier to understand, we used the
structure and processes shown in Figure 2.12 and the following naming conven-
tions: For practical reasons, most “plaintext” and “message” are not distinguished.
The input to the enciphering function is just called plaintext. (Using the term “clear-
text” instead of “plaintext” is wrong. Cleartext is used if an encrypted historical
document has some parts in natural language in between. See Section 3.1.)
Figure 2.12 Structure and naming convention of the SageMath code examples of this chapter.
42. Further examples with SageMath concerning classic crypto methods can be found, for example:
- As a PDF in the 240-page document (SageMath 10.0) https://doc.sagemath.org/pdf/en/reference/
cryptography/cryptography.pdf
- In the thesis of Minh Van Nguyen [39].
i i
i i
i i
The SageMath code samples (SageMath scripts) first contain the code, and
then as a comment the generated output at the end of each script. Note that
the printed listings mostly don’t show the comments from the end of the scripts.
All SageMath examples of this book can be found on the CrypTool website:
https://www.cryptool.org/en/documentation/ctbook/sagemath.
sage.crypto.classical.TranspositionCryptosystem
sage.monoids.string_monoid.AlphabeticStrings
We then need to decide on the block length of a permutation, which is the length
of the row vector to be used in the simple column transposition. This row vector is
our key, and it specifies a permutation of a plaintext.
The first example of the transposition ciphers (SageMath Example 2.1) has
block length 14, and the key is built in a way that every letter in the plaintext is
shifted to the right by two characters, with wraparound at the end of the block.
That is the encryption process. The decryption process is shifting each letter of the
ciphertext to the left by 14 − 2 = 12.
# given plaintext
P = "a b c d e f g h i j k l m n"; print ("P: ", P)
i i
i i
i i
# encode plaintext (get rid of non -alphabet chars , convert lower -case �
� into upper -case)
msg = T.encoding(P); print ("msg: ", msg)
#------------------------------------
# CHAP02 -- Sage -Script -SAMPLE 010: =========
# key: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1, 2] keylen: 14
# P: a b c d e f g h i j k l m n
# msg: ABCDEFGHIJKLMN
# C: CDEFGHIJKLMNAB
# DC: ABCDEFGHIJKLMN
# msg == DC: True
# encryption key
# key = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1, 2]
key = [(i+shift).mod(keylen) + 1 for i in range(keylen)]
print ("key: ", key , " keylen: ", len(key), sep ="")
i i
i i
i i
# decrypt by using the "deciphering method with key" (without the need �
� to calculate keyInv)
# Remark: Strangely , using the deciphering method requires to change �
� the type of the variable key
# The following does not work: DC = T.deciphering(key , C); �
� print ("2-DC:", DC)
DC = T.deciphering(T(key).key(), C); print ("2-DC:", DC)
blocklen = keylen = 14
T = TranspositionCryptosystem (AlphabeticStrings (), keylen);
P = "THECATINTHEHAT"
msg = T.encoding(P); print ("msg:", msg , " msglen:", len(msg))
C = T.enciphering(key , msg); print ("C: ", C)
DC = T.deciphering(T(key).key(), C); print ("DC: ", DC)
#------------------------------------
# CHAP02 -- Sage -Script -SAMPLE 030: =========
# key: [14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] keylen: 14
# msg: THECATINTHEHAT msglen: 14
# C: TAHEHTNITACEHT
# DC: THECATINTHEHAT
i i
i i
i i
blocklen = keylen = 14
A = AlphabeticStrings ()
T = TranspositionCryptosystem (A, blocklen);
P = "a b c d e f g h i j k l m n o p q r s t u v w x y z a b"
msg = T.encoding(P); print ("msg:", msg)
key = T.random_key (); print ("key: ", key)
Pkey = Permutation(key); print (" Pkey:", Pkey , "Pkeylen :", len(Pkey))
E = T(key)
C = E(msg); print ("2-C: ", C)
# deciphering
DC = T.deciphering(key , C); print ("DC: ", DC)
i i
i i
i i
keylen = 14
T = TranspositionCryptosystem (AlphabeticStrings (), keylen)
key = T.random_key (); print ("key: ", key , " keylen: ", keylen , sep ="")
i i
i i
i i
key = S.random_key (); print ("key: ", key , " keylen: ", len(key), sep �
� ="")
#------------------------------------
# CHAP02 -- Sage -Script -SAMPLE 060: =========
# key: ZMUPXCHBVGTIYLKDQOSENFWARJ keylen: 26
# P: MASC: Substitute this with something else using a random key �
� Plen: 60
# msg: MASCSUBSTITUTETHISWITHSOMETHINGELSEUSINGARANDOMKEY msglen �
� : 50
# C: YZSUSNMSEVENEXEBVSWVEBSKYXEBVLHXISXNSVLHZOZLPKYTXR
# DC: MASCSUBSTITUTETHISWITHSOMETHINGELSEUSINGARANDOMKEY
# msg == DC: True
# key = A([25-i for i in range(26)]); print ("key: ", key , sep ="")
lenA = len(A.alphabet ()) # lenA = 26
key = A([lenA -1-i for i in range(lenA)]); print ("key: ", key , sep ="")
#------------------------------------
# CHAP02 -- Sage -Script -SAMPLE 065: =========
# Free alphabetic string monoid on A-Z
# key: ZYXWVUTSRQPONMLKJIHGFEDCBA
# Substitution cryptosystem on Free alphabetic string monoid on A-Z
# msg: SUBSTITUTETHISWITHSOMETHINGELSE msglen: 31
# C: HFYHGRGFGVGSRHDRGSHLNVGSRMTVOHV
# DC: SUBSTITUTETHISWITHSOMETHINGELSE
# msg == DC: True
i i
i i
i i
S = SubstitutionCryptosystem (A)
sage.crypto.classical.ShiftCryptosystem
In SageMath Example 2.9, we construct a shift cipher over the capital letters
of the English alphabet. We then encrypt a plaintext P by shifting it key positions
along the alphabet. Finally, we decrypt the ciphertext C and check whether the
result (DC) is indeed the original plaintext.
Shifting is a special way of substitution. The original Caesar cipher is just simply
a shift cipher whose shifting key is 3.
i i
i i
i i
SageMath Example 2.9: Constructing the Caesar Cipher Using the Shift
Cipher
print ("\n# CHAP02 -- Sage -Script -SAMPLE 080: =========")
# Caesar cipher using the Shift cipher instead of the more general Substitution cipher
S = ShiftCryptosystem(AlphabeticStrings ()); print(S)
msg = S.encoding (" Shift me any number of positions ."); print ("msg:", msg , " msglen :", len �
� (msg))
sage: n=26
sage: n. coprime_integers (n)
[1, 3, 5, 7, 9, 11 , 15 , 17 , 19 , 21 , 23 , 25]
If a is not relatively prime to n, that is, gcd (a, n ) > 1, then the mapping cannot
be inverted, and the ciphertext cannot be uniquely deciphered. That would be the
case here with an even a and with a = 13.
i i
i i
i i
A = AlphabeticStrings ()
# int conversion needed: A.ngens () creates type <class 'int '>, but we need <class 'sage.rings. �
� integer.Integer '>
# via ngens () no hard coded "26" is needed.
n=Integer(A.ngens ()) # n = 26 = number of free alphabetic string monoid on A-Z.
# decrypt the ciphertext and make sure that it is equivalent to the original plaintext
DC = AS.deciphering(a, b, C); print ("DC: ", DC)
We can also construct a shift cipher using the affine cipher. To do so, we need
to restrict keys of the affine cipher to be of the form (a = 1, b) where b is any
nonnegative integer.
To create the Caesar cipher using the affine cipher, the encryption/decryption
key must be (1, 3). SageMath Example 2.9 works analogously with the affine cipher
in SageMath Example 2.12.
SageMath Example 2.12: Constructing the Caesar Cipher Using the Affine
Cipher
print ("\n# CHAP02 -- Sage -Script -SAMPLE 100: =========")
key = a, b = (1, 3); print (" affine key: ", key , sep ="")
i i
i i
i i
#------------------------------------
# CHAP02 -- Sage -Script -SAMPLE 100: =========
# affine key: (1, 3)
# msg: SHIFTTHEALPHABETBYTHREEPOSITIONSTOTHERIGHT msglen: 42
# C: VKLIWWKHDOSKDEHWEBWKUHHSRVLWLRQVWRWKHULJKW
# DC: SHIFTTHEALPHABETBYTHREEPOSITIONSTOTHERIGHT
# msg == DC: True
P = "The Vigenere cipher is polyalphabetic ."; print ("P: ", P, " Plen:", len(P))
msg = V.encoding(P); print ("msg:", msg , " msglen:", len(msg))
#------------------------------------
# CHAP02 -- Sage -Script -SAMPLE 110: =========
# key: OHZZMJTRCFOWKN keylen: 14
# P: The Vigenere cipher is polyalphabetic. Plen: 38
# msg: THEVIGENERECIPHERISPOLYALPHABETIC msglen: 33
# C: HODUUPXEGWSYSCVLQHEYHCAFZLRNPLSHO Clen: 33
# DC: THEVIGENERECIPHERISPOLYALPHABETIC
# msg == DC: True
i i
i i
i i
Figure 2.13 Hill dialog in CT1 showing the operations and options available.
operate on more than three symbols at once. The Hill cipher is not important from a
security point of view, but because it was the first cipher trying to apply mathematics
to cryptography. The encryption key of this cipher is an invertible square matrix
(here called key) whose determinant is relatively prime to 26. Originally, plaintext
and ciphertext are vectors (P and C). The encryption and decryption processes use
matrix operations modulo 26: C = P · key (mod 26).
The Hill cipher is implemented in the SageMath class
sage.crypto.classical.HillCryptosystem
In SageMath Example 2.14, our plaintext/ciphertext space is the capital letters
of the English alphabet. The Hill cipher assigns each letter of this alphabet a unique
integer modulo 26. The size of the key matrix (also called its dimension) is not
restricted by the cipher.
Comparing the Hill implementation in CrypTool v1.4.42 and in SageMath
version 9.3:
• SageMath offers fast command-line operations; CT1 offers its functionality
within a GUI.
• SageMath offers for the key matrix any dimension; CT1 is restricted to a
matrix size between 1 and 10.
i i
i i
i i
• SageMath allows negative numbers in the key matrix, and converts them
automatically into appropriate nonnegative numbers; CT1 doesn’t allow
negative numbers in the key matrix.
• SageMath always sets the first alphabet character to 0, only allows the 26
capital letters as an alphabet, and it uses only the multiplication variant
plaintext row vector · key matrix: C = P · key.
• CT1 offers to choose also 1 as value for the first alphabet character, you can
customize your alphabet within the text options dialog, and it also offers to
use a reverse multiplication variant: C = key ·P.
SageMath only provides the function for encryption and decryption for the
classic ciphers and usually with a very restrictive alphabet. You have to implement
methods for cryptanalysis yourself. A KPA against the Hill cipher is introduced
in Section 2.8.3.2.
While SageMath Example 2.14 calculates for the entered characters always
with their ASCII numerical values, SageMath Example 2.19 cannot only carry out
a KPA analysis, but also put the key matrix in front of the plaintext (order of the
multiplication) and the characters in the alphabet start from 0 or 1.44
Reference [43] is a very good article developing the formulas for how many
invertible Hill matrices there are for a given dimension (compared to the total
number of all matrices and to the number of involutory matrices).
keylen = 3 # Alternative key length: keylen=13 --- ensure msg length is a multiple of keylen
A = AlphabeticStrings ()
H = HillCryptosystem(A, keylen)
# Alternative 1: Non -random key creation (needs HKS; even H.key_space () is not enough)
HKS = H.key_space ()
key = HKS ([[1,0,1],[0,1,1],[2,2,3]]); print ("key: \n", key , sep ="")
# encryption
C = H.enciphering(key , msg); print ("C: ", C, " Clen: ", len(C))
# decryption
DC = H.deciphering(key , C); print ("DC: ", DC)
print ("msg == DC:", msg == DC) # Expect True
i i
i i
i i
print ("\n---Remark: Output C as a sequence of ASCII characters and their according numbers ")
# print (" type(C):", type(C)) # 'sage.monoids.string_monoid_element.StringMonoidElement '
# 'StringMonoidElement ' object has no attribute to directly convert to integer sequence
from sage.crypto.util import ascii_to_bin , ascii_integer
# print (" a_to_b: ", ascii_to_bin(str(C)))
print ("C[i]:", [C[i] for i in range(len(C))])
print (" binary C[i]:", [ascii_to_bin(str(C[i])) for i in range(len(C))])
print (" integer C[i]:", [ascii_integer(ascii_to_bin(str(C[i]))) for i in range(len(C))])
The following samples demonstrate that one can vary the alphabet. The first
two samples use the hexadecimal and the binary system. The last sample shows how
to define your own alphabet. This currently requires you to also write your own
cipher algorithm. We do this by defining an own MASC with a longer alphabet.
A = HexadecimalStrings ()
S = SubstitutionCryptosystem (A)
key = S.random_key (); print ("key: ", key , " keylen: ", len(key), sep ="")
print (" Number of possible keys: ", len(key), "! = ", factorial(len(key)), sep ="")
P = "Working with a larger alphabet ."; print ("P: ", P, " Plen:", len(P))
msg = A.encoding(P); print ("msg:", msg , " msglen:", len(msg))
i i
i i
i i
#------------------------------------
# CHAP02 -- Sage -Script -SAMPLE 130: =========
# key: c7834de0f1a65b29 keylen: 16
# Number of possible keys: 16! = 20922789888000
# P: Working with a larger alphabet. Plen: 31
# msg: 576f726b696e6720776974682061206c617267657220616c7068616265742e msglen: 62
# C: d0e908e6e1e2e08c00e104ef8ce78ce5e708e0ed088ce7e50 cefe7e8ed0482 Clen: 62
# DC: 576f726b696e6720776974682061206c617267657220616c7068616265742e
# msg == DC: True
# P == DDC: True
MASC with a binary alphabet. In SageMath Example 2.16 the three cipher types,
monoalphabetic substitution, shift, and Vigenère are used. The alphabet symbols
here are in each case from the binary number system.
Except for the Vigenère cipher, which can be enhanced as a one-time pad, these
variants are very unsecure. Because the plaintext/ciphertext alphabet has only the
two elements 0 and 1, there are—for example, with monoalphabetic substitution—
then only two possible keys: (0 1) and (1 0). The key of a monoalphabetic
substitution cipher must contain all symbols of the alphabet exactly once.
# Alternative: To get a substitute for each symbol , key has always the length of the alphabet
# key = S.random_key ()
key = B("10") # "10" inverts all bits , "01" leaves them unchanged; "0", "1", "00" and "11" �
� cause exception!
print ("key: ", key , " keylen: ", len(key))
# print ("## type key: ", type(key))
P = "MA -Substitution on binary alphabet is very unsecure (flip bit or not)."; print ("P: ", P, �
�" Plen:", len(P))
msg = B.encoding(P); print ("msg:", msg , " msglen:", len(msg))
S = ShiftCryptosystem(B) # Shift in the binary alphabet B which has only two elements.
print ("\n2. Shift: alphabet_size :", S.alphabet_size ())
i i
i i
i i
P = "Shift on binary alphabet offers only 2 possibilities: very unsecure ."; print ("P: ", P, " �
� Plen:", len(P))
msg = B.encoding(P); print ("msg:", msg , " msglen:", len(msg))
keylen = 14;
# Alternative settings for alphabet and using a given key
# B = AlphabeticStrings (); key = B('ABCDEFGHIJKLMN '); print ("key:", key , " keylen: ", len(key) �
�)
# B = BinaryStrings (); key = B('11111111111111 '); print ("key:", key , " keylen: ", len(key))
V = VigenereCryptosystem(B, keylen)
print ("\n3. Vigenere: alphabet_size :", V.alphabet_size ())
key = V.random_key (); print (" randkey :", key , " keylen: ", len(key))
msg = V.encoding (" Vigenere on binary alphabet with long key is close to OTP ."); print ("msg:", �
� msg , " msglen :", len(msg))
C = V.enciphering(key , msg); print ("C: ", C, " Clen: ", len(C))
DC = V.deciphering(key , C); # print ("DC: ", DC)
# Using own definitions for a classical cipher instead of the r2r Sage commands (r2r=ready -to - �
� run)
# An arbitrary alphabet made from A..Z, a..z, 0..9, and some symbols which are arranged in a �
� wished order.
import string
import random
# Determine the order of the elements of the alphabet by ordering the 4 parts
alphabet = alph1 Lower_string + alph2 Upper_string + alph4 Punctuation_string + alph3 Digits_string
print(alphabet)
# Shuffle rearranges the given object. As strings and tuples are immutable ,
# we have to use random.sample () instead of random.shuffle ().
random.seed(int(15)) # argument not necessary. Initialized the PRNG just to have always the �
� same to compare with.
# argument 15 without casting throws TypeError: The only supported seed types are: None , �
� int , float , str , bytes , and bytearray.
r_alphabet = ''.join(random.sample(alphabet , len(alphabet)))
i i
i i
i i
codetableC2P = str.maketrans(CA ,PA) # requires the 2 strings CA , PA to have the same len
codetableP2C = str.maketrans(PA ,CA) # requires the 2 strings CA , PA to have the same len
P1 = '''ATESTZtestTEST1234 '''
P2 = '''DWHVWCCNBCWHVWNOPQ '''
C1 = P1.translate(codetableP2C);
C2 = P2.translate(codetableP2C);
P1 _revealed = C1.translate(codetableC2P);
P2 _revealed = C2.translate(codetableC2P);
45. In SageMath 9.7, only the two classic cryptosystems ShiftCryptosystem and AffineCryptosystem
have this method built in. For example, SubstitutionCryptosystem does not have it because the
search space (26!) is too large. See https://doc.sagemath.org/html/en/reference/cryptography/
sage/crypto/classical.html.
i i
i i
i i
# Find the most likely plaintext of a ciphertext encrypted via a shift cipher
# - Instead of explicitely looping over all revealed plaintexts ,
# use the built -in brute -force method and apply a statistical measure
# - automated ciphertext -only attack against Caesar
S = AlphabeticStrings ()
E = ShiftCryptosystem(S)
i i
i i
i i
Figure 2.14 Increasing the readability of the decrypted text using the “Split a Text” template in CT2.
Example 2.14 in Section 2.8.2.6 could only encrypt and decrypt the data that was
hard-encoded in the program, SageMath Example 2.19 is more professional: It
contains different test data in a dictionary and can also read all necessary data and
options from the command line.
To do the KPA, the key matrix A is calculated from the ciphertext C and
the inverse of the plaintext P. The order of matrix multiplication in the analysis
depends on whether the key is multiplied with the plaintext from the left or from
the right during encryption:
or
It should be noted that the program first looks for the correct sections from the
given plaintext so that the matrix P is invertible. This happens in the function
PerformKPA in the for loop that determines the correct slices from P.
Since the entire SageMath Example 2.19 is over 700 lines long, only the file
header is listed here. The entire file is available on the CT server: see https://www
.cryptool.org/en/documentation/ctbook/sagemath.
i i
i i
i i
References
[1] ACA, Length and Standards for All ACA Ciphers, 2021, https://www.cryptogram.org/re-
sourc e-area/cipher-types/.
[2] Bion, Recreational Cryptography Programs, https://williammason.github.io/rec-crypt/.
[3] Pilcrow, P., CryptoPrograms, http://www.cryptoprograms.com.
[4] Singh, S., The Code Book: The Science of Secrecy from Ancient Egypt to Quantum
Cryptography, New York: Anchor Books, 1999.
[5] Goebel, G., Codes, Ciphers and Codebreaking, Version 2.3.2, 2014, http://web.archive
.org/web/20151027000247/http://www.vectorsite.net/ttcode.html.
[6] Savard, J. J. G., A Cryptographic Compendium, 1999, http://www.quadibloc.com/cryp-
to/jscrypt.htm.
[7] ThinkQuest Team 27158, Data Encryption, 1999.
[8] Knight, K., B. Megyesi, and C. Schaefer, Copiale Cipher; Scaled Page 16/17, Wikimedia
Commons, 2011, https://commons.wikimedia.org/wiki/File:Copial e-cipher09s.png.
[9] Sanguino, L. A. B., et al., “Analyzing the Spanish Strip Cipher by Combining Combinato-
rial and Statistical Methods,” in Cryptologia, Vol. 40, No. 3, 2016, pp. 261–284, https://
www.semanticscholar.org/paper/Analyzing-the-Spanish-strip-cipher-by-combining-and-
Sanguino-Leander/b4278e62c804ec0bf349a1e5c74a1b35bb276d83.
[10] Drobick, J., Abriss DDR-Chiffriergeschichte: SAS- und Chiffrierdienst, 2015, http://scz
.bpla ced.net/m.html#dwa.
[11] Schneier, B., The Solitaire Encryption Algorithm, v. 1.2, 1999, https://www.schneier
.com/ac ademic/solitaire/.
[12] Crowley, P., Mirdek: A Card Cipher Inspired by “Solitaire,” 2000, http://www.cipher-
goth.org/crypto/mirdek/.
[13] Géraud-Stewart, R., and D. Naccache, “A French Cipher from the Late 19th Century,”
Cryptologia, 2020, pp. 1–29, https://doi.org/10.1080/01611194.2020.1753265.
[14] Kallick, B., Handycipher: A Low-Tech, Randomized, Symmetric-key Cryptosystem,
Cryptology ePrint Archive, Report 2014/257, 2014, https://eprint.iacr.org/2014/257.
[15] Kaminsky, A., ElsieFour: A Low-Tech Authenticated Encryption Algorithm for Human-
to-Human Communication, Cryptology ePrint Archive, Report 2017/339, 2017,
https://eprint.iacr.org/2017/339.
i i
i i
i i
[16] Dooley, J. F., History of Cryptography and Cryptanalysis: Codes, Ciphers, and Their
Algorithms, Cham, Switzerland: Springer, 2018.
[17] De Leeuw, K., “The Dutch Invention of the Rotor Machine, 1915–1923,” Cryptologia,
Vol. 27, No. 1, 2003, pp. 73–94.
[18] Pommerening, K., Cryptology. Lecture Notes, Johannes Gutenberg Universität
Mainz, 2021, https://www.staff.uni-mainz.de/pommeren/Cryptology/Classic/5_Rotor/
HistRot.html.
[19] Crypto Museum Official Website, https://www.cryptomuseum.com/manuf/crypto/in-
dex.htm.
[20] Fridrih, T., Hagelin–A Genius of Scientific and Technological Thought, web blog post,
2019, https://habr.com/ru/company/ua-hosting/blog/271387/.
[21] Rijmenants, D., Cipher Machines and Cryptology. Technical and Historical Infor-
mation about Cipher Machines and the Fascinating World of Cryptology, 2022,
https://www.ciphermachinesandcryptology.com/.
[22] Kopal, N., “How Does the M-209 Cipher Machine Work? – A Brilliant Non-
Electrical Encryption Device,” 2020, YouTube channel Cryptography for Everybody,
https://www.youtube.com/watch?v=Nhf6kHGujQ4&t=56s.
[23] Wessel, B., The Hagelin Cryptographers C-52 and CX-52, February 2021,
https://www.cryptomuseum.com/pub/files/BW_C52_CX52.pdf.
[24] Lasry, G., N. Kopal, and A. Wacker, “Ciphertext-Only Cryptanalysis of Hagelin M-209
Pins and Lugs,” Cryptologia, Vol. 40, No. 2, 2016, pp. 141–176.
[25] Theveßen, E., P. F. Müller, and U. Stoll, Operation Rubikon. Wie BND und CIA die
Welt belauschten, German television station ZDF, February 2020, https://www.zdf.de/
politik/frontal/operation-rubi kon-100.html.
[26] Miller, G., “The Intelligence Coup of the Century,” The Washington Post, Febru-
ary 2020, https://www.washingtonpost.com/graphics/2020/world/national-security/cia-
crypto-encryption-machines-espionage/.
[27] CX-52, Wikipedia, German version, 2022, https://de.wikipedia.org/wiki/CX-52.
[28] Kuhlemann, O., Kryptografie.de., https://kryptografie.de.
[29] Leierzopf, E., et al., “Detection of Classical Cipher Types with Feature-Learning
Approaches,” in Data Mining: 19th Australian Conference on Data Mining, AusDM
2021, Brisbane, Australia, December 14–15, 2021, Springer Singapore, https://doi.org/
10.1007/978-981-16-8531-6_11.
[30] Dalton, B., and M. Stamp, “Classifying World War II Era Ciphers with Machine Learning,”
Cryptology ePrint Archive, 2023, https://arxiv.org/abs/2307.00501.
[31] Kopal, N., and M. Waldispühl, “Two Encrypted Diplomatic Letters Sent by Jan Chod-
kiewicz to Emperor Maximilian II in 1574–1575,” in Proceedings of the 4th International
Conference on Historical Cryptology, 2021, pp. 80–89, doi: https://doi.org/10.3384/
ecp188409.
[32] Dinnissen, J., and N. Kopal, “Island Ramanacoil a Bridge too Far. A Dutch Ciphertext
from 1674” in Proceedings of the 4th International Conference on Historical Cryptology,
2021, pp. 48–57, https://ecp.ep.liu.se/index.php/histocrypt/article/view/156.
[33] Lasry, G., B. Megyesi, and N. Kopal, “Deciphering Papal Ciphers from the 16th to the
18th Century,” Cryptologia, Vol. 45, No. 6, 2021, pp. 479–540, https://www.tandfonline
.com/doi/full/10.1080/01611194.2020.1755915.
[34] Lasry, G., N. Biermann, and S. Tomokiyo. “Deciphering Mary Stuart’s Lost Letters from
1578–1584,” Cryptologia, 2023, doi: 10.1080/01611194.2022.2160677.
[35] Megyesi, B., et al., “Decryption of Historical Manuscripts: The DECRYPT Project,”
Cryptologia, Vol. 44, No. 6, 2020, pp. 545–559, https://doi.org/10.1080/01611194
.2020.1716410.
i i
i i
i i
[36] Lasry, G., “Analysis of a Late 19th Century French Cipher Created by Major Josse,”
Cryptologia, 2021, pp. 1–15, https://www.tandfonline.com/doi/full/10.1080/01611194
.2021.1996484.
[37] Lasry, G., “Cracking SIGABA in Less than 24 Hours on a Consumer PC,” Cryptologia,
2021, pp. 1–37, https://www.tandfonline.com/doi/full/10.1080/01611194.2021.1989522.
[38] Madness, A Book on Classical Cryptography, https://github.com/themaddoctor/classi-
cal_crypto_book.
[39] Van Nguyen, M., Exploring Cryptography Using the Sage Computer Algebra System,
2009, https://www.sagemath.org/files/thesis/nguyen-thesis-2009.pdf, and https://www
.sagemath.org/library-publications.html.
[40] Hill, L. S., “Cryptography in an Algebraic Alphabet,” The American Mathematical
Monthly, Vol. 36, No. 6, 1929, pp. 306–312.
[41] Hill, L. S., “Concerning Certain Linear Transformation Apparatus of Cryptography,” The
American Mathematical Monthly, Vol. 38, No. 3, 1931, pp. 135–154.
[42] Wikipedia, Hill Cipher, https://en.wikipedia.org/wiki/Hill_cipher.
[43] Overbey, J. L., W. Traves, and J. Wojdylo, “On the Keyspace of the Hill Cipher,”
Cryptologia, Vol. 29, No. 1, 2005, pp. 59–72, doi: 10.1080/0161-110591893771, and
https://www.tandfonline.com/doi/abs/10.1080/0161-110591893771.
[44] Kohel, D. R., Cryptography, Creative Commons, 2008, https://www.sagemath.org/files/
kohel-book-2008.pdf.
[45] Stinson, D. R., Cryptography—Theory and Practice, 3rd ed., Chapman & Hall/CRC,
2006.
[46] Freiermuth, K., et al., Einführung in die Kryptologie, 1st ed., Vieweg+Teubner, 2010.
[47] OpenAI, ChatGPT, https://chat.openai.com.
[48] YOU.com, AI Chatbot to Search the Web, https://you.com.
i i
i i
i i
CHAPTER 3
CHAPTER 3
Historical Cryptology
3.1 Introduction
Historical cryptology deals with the encryption and decryption of historical, man-
ually constructed ciphers. An encrypted source usually counts as historical if it has
been produced no later than the mid-20th century. There is no exact break-even
point; however, the development of telegraphy (from the 1830s) led to more sophis-
ticated and complex mathematical methods applied to encryption requiring more
advanced cryptanalysis.
Historical cryptology involves the field of cryptography (the art and science of
code making and the encryption of messages), and the field of cryptanalysis (the
art and science of code breaking [1], i.e., the decipherment of messages without the
97
i i
i i
i i
98 Historical Cryptology
key). In everyday language, the terms “cryptography” and “cryptology” are often
used interchangeably.
As in all scientific fields, historical cryptology has its own terminology. We start
the chapter by introducing the most important terms and give a brief overview of
historical ciphers and keys before we move on to the components needed to process
and decipher historical ciphers. Given that historical cryptology as a scientific field
of study is rather new, the terminology standards and the usage of the terms are
still to be established and under discussion in the historical cryptology community
(see for example [2] and [3]). We summarize the important terms in Figure 3.6 and
Table 3.1, as well as illustrate the crypto process in Figure 3.7.
A cipher (sometimes also “cypher,” which is simply the old spelling) refers to an
algorithm that describes the procedure of encryption or decryption. The encrypted
source itself is called ciphertext, though the terms “code” and “cipher” are often
not distinguished from ciphertext in everyday language. A ciphertext consists of a
sequence of symbols from a ciphertext alphabet. The ciphertext alphabet can be
the same as the plaintext alphabet (e.g., the Latin letters), but often it consists of
different symbol systems and alphabets, such as Greek letters, digits, graphic signs
(e.g., alchemical or zodiac signs), or Chinese hieroglyphs. Figure 3.1 illustrates the
variation of the symbol systems from ciphertext alphabets in three ciphertexts. The
ciphertexts are extracts taken from the Borg cipher [4], a digit-based cipher from
the National Archives of Sweden [5], and the Copiale cipher [6].
In ciphertexts, we can find regular usage of space marking word boundaries
as in the Borg cipher (see Figure 3.1) even though most of the ciphertexts from
the past use continuous script (scriptio continua) without any spaces, as shown in
the examples from the Swedish National Archives and the Copiale cipher. Word
boundaries were often removed in historical ciphers to make codebreaking more
difficult. A ciphertext might also contain additional information such as accents
and other diacritics, or punctuation marks appearing more or less systematically in
connection to symbols, as in the example of the Copiale cipher. We can also find
overwritings for corrections, underlined sequences, and unintentional ink spots in
the manuscripts.
i i
i i
i i
3.1 Introduction 99
Figure 3.2 Ciphertext (underlined), cleartext (in red), and plaintext (in blue) in an encrypted
manuscript.
i i
i i
i i
In both keys, the letters of the plaintext alphabet (A–Z) are listed horizontally in
the first line of the key tables. Moreover, underneath each plaintext letter, we can
find either one (Figure 3.3) or several ciphertext symbols (Figure 3.4), henceforth
alphabet-code elements, assigned to each plaintext letter. In Figure 3.3 these single
ciphertext letters are taken from the plaintext alphabet but in a different position. In
Figure 3.4, on the other hand, the lengths of the alphabet-code elements vary; two-
digit code elements to encode the plaintext alphabet and three-digit code elements
to encode the words. Note that the most frequently occurring plaintext alphabet
letters have four alphabet-code elements, whereas the least frequent ones received
three code elements. Adding several code elements to the frequently occurring plain-
text elements leads to an increased difficulty of decipherment and renders a cipher
homophonic.
In the columns of both keys we find a shorter or longer list of plaintext elements
(names, content, and function words) with code elements assigned to each. Such
a list as part of the key is called nomenclature, sometimes also spelled nomencla-
tor. Sometimes the entire key that contains a nomenclature (i.e., a list of plaintext
elements) is called a nomenclator. Here, we make a distinction between the vari-
ous parts of the key. The nomenclature shown in Figure 3.3 consists of roughly 100
items in which we can see code elements using a single ciphertext symbol, for exam-
ple “A” for “Royne d’Angleterre” and others with multiple ciphertext symbols,
such as “12” for “Siuille.” Here, the various types of nomenclature elements receive
Figure 3.4 Cipher key: simple and homophonic substitution. (Hungary, 1703–1711 [8].)
i i
i i
i i
different cipher symbol types: Personal names are encoded by capital letters, place
names by numerals, military titles by other words, and dignitaries by graphic signs.
However, this assignment is not fully consistent: “Brazil” and “Mexico” are listed
among the personal names. Such inconsistencies are not uncommon in historical
encrypted sources. In the other key in Figure 3.4, the nomenclature is larger, con-
sisting of over 400 entities. Here, we can find syllables shown as section headings
(“Ba,” “Ca,” “Da,” . . .), function and content words, and names and phrases, all
in French. The last column contains additional information about the key to give
instructions or details about the cipher.
Historical cipher keys were typically structured as tables, in which the alpha-
bet elements and the nomenclature elements were graphically clearly separated; the
former horizontally as lines and the latter vertically as columns. Content-wise,
however, the boundary is not as clear-cut; double letters, syllables, or function
words might be listed as part of the alphabet line. It is also noteworthy that the
nomenclature tables usually have a certain structure in which plaintext elements
can be ordered alphabetically (see the key in Figure 3.4) or thematically (as shown
in Figure 3.3), or in a combination where the words in the themes can be alphabeti-
cally ordered. In turn, the code elements can be grouped thematically depending
on the type of plaintext element they encode (as in Figure 3.3), and/or numer-
ically when the code elements are represented by digits. The key creators often
assigned code elements to the alphabetically or thematically listed plaintext ele-
ments in some structure. Code elements of the nomenclature list were typically
numbered consecutively in increasing or decreasing order, either vertically follow-
ing the order of the columns or horizontally, following the lines across the columns.
The construction of the nomenclature list has an impact on the cryptanalysis (deci-
pherment)—alphabetical order of the plaintext elements with increasing order of
numbers can ease cryptanalysis as higher code numbers represent words starting
with letters at the end of the alphabet.
To make cryptanalysis more difficult, operational code elements (i.e., code ele-
ments that operate either on the plaintext or on other code elements) have been used.
A commonly occurring type are nulls, which can also be named in historical cipher
keys as nullities and called by the public as “blenders”—fake code elements that
encode an empty string in the plaintext. Note that keys might also contain code ele-
ments without any given plaintext in the nomenclature table treated as placeholders
to be filled in later, which are not defined as nulls but empty code elements. Other
types of operational code elements with special function on the plaintext include
cancellation signs (also called nullifiers or deleters) that mark the removal of a cer-
tain sequence of ciphertext, and repetition signs that repeat the preceding symbol
used for the reduplication of a plaintext letter.
Historical cipher keys changed and developed over time leading to the emer-
gence of new ciphers. In fact, all the historical ciphers discussed in this chapter are
variations of the substitution cipher. The specific substitution method was entirely
determined by the key type used with it. Therefore, when we discuss the develop-
ment of the keys, we also speak about the evolution of the ciphers. The earliest
keys in Europe were based on simple substitution, in which each plaintext element
is assigned to exactly one code element represented as a ciphertext symbol. An
example of a simple substitution cipher is shown in Figure 3.3. The top two lines
i i
i i
i i
of this document illustrate a nice example of the Caesar cipher (see Section 2.2.1),
in which the plaintext alphabet is also used for encryption but shifted (here by 11
positions). To complicate the cryptanalysis, a nomenclature table was added, which
became the norm in Europe in the 15th century [9]. Simple substitution ciphers
were then further developed into homophonic substitution ciphers, where the same
plaintext entities—often the most frequently occurring ones, such as vowels and
some consonants—could be encrypted with different code elements, as illustrated in
Figure 3.4. The nomenclature list evolved from the 17th century and onward from
several hundred elements to thick codebooks, in which not only content words but
also grammatical categories (e.g., singular, plural; grammatical cases) or inflected
word forms (e.g., “see, sees, saw, seen” for the verb “to see”) were listed with
their own code elements [9]. In some keys, different plaintext entities could also be
assigned to the same code element, intentionally or unintentionally. Ciphers with
one code element assigned to several plaintext symbols are called polyphonic substi-
tution ciphers. Figure 3.5 illustrates such a cipher key. Here, the ciphertext symbol
“3” can be decrypted as either “A” or “s,” and the symbol “6” as either “t” or “r.”
The three types of encryption methods—simple, homophonic, and polyphonic—
are the most frequently occurring types in European history [9]. The interested
reader can find more details about the structure and evolution of cipher keys
throughout the centuries in Europe in [9].
In addition, not only monoalphabetic substitution ciphers have been used
throughout history. After the early modern time, polyalphabetic substitution
ciphers became common, such as the Vigenère cipher (see Section 2.2.4). In these
ciphers, the plaintext alphabet is mapped to different ciphertext alphabets—see
Section 2.2.4. Transposition ciphers (Section 2.1) are another type, in which the
letters of the plaintext are switched around in some systematic way to form the
ciphertext. In later centuries, we can also find ciphers that are actually cascades
of different ciphers that we call composed ciphers. An example of such a cipher is
the ADFGVX cipher [10], which is a combination of substitution (using a Polybius
square—see Section 2.3) and (columnar) transposition.
In recent years, by far the greatest attention worldwide for historical cryp-
tology has been given to the successful cryptanalysis of over 50 newly discovered
letters written by Mary Stuart between 1578 and 1584. George Lasry, Norbert
Biermann, and Satoshi Tomokiyo worked for over one year to transcribe, decipher,
and place these letters containing over 150,000 symbols in their proper historical
context [11]. Mary Stuart’s letters were classified under Italian letters in the French
National Library, without telling sender or recipient or the actual language used
(French). The procedure used by Mary Stuart was a difficult cipher because she
used a nomenclature with 191 different characters, which included well over 100
words in addition to the 26 letters of the alphabet, but also homophones (several
symbols representing the same letter), symbols without meaning (nulls or blenders),
Figure 3.5 Cipher key example: polyphonic substitution from the 16th century.
i i
i i
i i
Figure 3.7 The crypto process: Components of encryption and decryption of historical sources.
symbols that cancel the previous symbol (nullifier), and symbols that repeat the
previous symbol.
i i
i i
i i
i i
i i
i i
Figure 3.8 TranscriptTool for creating transcriptions of scanned historical manuscripts, offered as part of the
DECRYPT pipeline.
i i
i i
i i
and CT2) are released as open-source and are under continued development (as of
2023). The DECODE database and the two tools are included into a framework
as a pipeline for processing the historical encrypted manuscripts to allow feedback
loops and error reduction between the various steps in the pipeline. In addition
to the TranscriptTool in the pipeline on the web, there is a standalone offline tool
called CTTS. See Section 3.4.2. For ciphers that do not consist of numbers, CTTS
or TranscriptTool are currently the best choice. For numeric ciphers, Transkribus.ai
can be an alternative.
The steps for breaking a cipher need careful combination and cooperation of
experts from different fields. Computational linguists provide the database with
keys and ciphers, define transcription schemes for various symbol sets, and build
and evaluate historical language models generated from historical texts. Historical
linguists and philologists collect and analyze historical texts to develop models for
language variation and language change. Cryptanalysts develop efficient algorithms
for the cryptanalysis of various cipher types, and computer vision scientists provide
a typology of symbol transcription and models to turn images into a machine-
readable format. Historians contribute to the collection, contextualization, and
interpretation of the hidden sources. By doing so the encrypted sources can be
systematically handled, studied in large scale, and made available to the public.
The following sections describe the main parts shown in the pipeline and
highlight the challenges in each step.
A general experience of experts looking for handwritten cipher keys and encrypted
documents is that they are easy to recognize but hard to find (see Section 3.2).
It is easy to recognize the keys because they have a typical structure: A plaintext
alphabet and a ciphertext alphabet are written next to each other, often followed
i i
i i
i i
by a nomenclature table where words and corresponding code elements are listed.
A typical historical key usually looks like a short note on a piece of paper (if it is a
monoalphabetic cipher) or a large table on one or two approximately A4-measure
pages. They are either separate sheets or part of an extensive collection, with pages
in a book entirely dedicated to cipher keys. The encrypted documents are usually
easy to recognize because they are text-like documents partially or entirely com-
posed of numbers, letters, or graphic signs, often separated by dots. Even though
sometimes inventories are mistaken for encrypted documents, and there might be
some uncertainty about whether a text is encrypted or written in an unknown
writing system or language, most of the time these documents are recognized with-
out any problem. They might be only a few words, a paragraph-long ciphertext
in an otherwise readable message, or a several-page (even a book-length) entirely
encrypted document.
However, it is not easy to find the encrypted sources. Cipher keys and encrypted
documents are found in two different places: in the archives and the manuscript
collections of libraries. Imagine that a crypto-history expert pays a visit in a for-
eign country wishing to study that area’s cryptology. Such a research trip should
be thoroughly prepared because entering an archive and asking for cipher keys
without any preparation rarely leads to success. This preparation includes consult-
ing the secondary literature using that specific manuscript collection and writing
directly to the archivists/librarians. Asking for advice from historians dealing with
the period (but not necessarily with encrypted documents) might also be of con-
siderable help. The importance of personal contacts is not to be underestimated.
Finally, precious input can also arrive from blog authors, including the portal
about the Voynich manuscript by René Zandbergen [16], Nick Pelling’s Cipher
Mysteries [17], or Klaus Schmeh’s science blog [18] with a wide range of encrypted
sources.
Manuscript collections in libraries usually have proper catalogs, but the refer-
ence materials of archives do not always specify that a given source is encrypted.
Even when thoroughly cataloged, their description is rarely on document-level; they
remain more frequently on a higher collection level, and thus individual documents
remain invisible. Archives usually have boxes with a lot of documents in them.
Often, the box is described (e.g., political documents from this or that war), but
the individual letters, or documents, are not described one by one. However, even
in those rare cases when the indexes list each individual record, a further problem
arises: which search word to look for? “encrypted,” “cipher,” “in cifra” (or ciffra),
“enchiffré,” “crypté,” and “chiffriert” are certainly good choices, but following
the results of “en chiffre” in the Bibliothèque Nationale de Paris might be problem-
atic, because one gets thousands of documents, the description of which involves
“number” (chiffre).
Usually, it is easier to find the keys because they are often stored together in
thematic collections. The two most frequent cases are (1) a whole handwritten book
(either in a library or an archive) in which cipher keys are copied, contains one key
per page, and (2) a folder (usually in an archive) stores separate sheets of various
sizes, one key being on each sheet. Catalogs and reference books usually mention
such collections. However, when an individual key occurs somewhere alone, it is
hardly mentioned and can only be found by chance.
i i
i i
i i
Encrypted documents are harder to find because the catalogs (of the libraries)
and the reference books (of the archives) often do not specify in the indices that they
are entirely or partially encrypted. In such cases, the crypto historian can ask for
diplomatic or military correspondences of a specific period in general. Diplomatic
letters (particularly ambassadors’ letters and intelligence reports) and military mes-
sages will include encrypted messages with high probability. Even family collections
(the kind of sources that make up a large portion of the totality of archival collec-
tions) might also contain encrypted documents, not to mention personal diaries and
scientific and religious books. There is no systematic way to find them; one has to
ask for whole folders and leaf them through. According to the conjecture of a crypto
historian, one percent of the archival material is partly or entirely encrypted [19].
There is also a problem of matching the encrypted document with the corre-
sponding key. Even if the collectors found both, it is not evident that they recognize
the relationship between the two. This task gets harder as the collections grow. It is
tough to index the records in a way that corresponding sources become identifiable.
Once crypto historians find cipher keys and encrypted documents, they face
several further difficulties. First, the attached metadata might not be correct. The
collections are dated, and the origins of the sources are also indicated in the archival
folders; however, this information is usually too broad, and the documents and the
keys are not dated separately. Some of the records contain dates and names, and
in those cases when these are not later additions (by 19th-century archivists and
librarians, for example) but historical data, they are reliable. In other cases, they
are not always trustworthy, or just contain information that is too unspecific.
Describing a manuscript in terms of its location, structure, origin, and content
is invaluable for research. Such descriptions are called metadata, which help us to
interpret the manuscript. The more robust and detailed the description is the more
accurate analysis we can carry out. Metadata of historical encrypted sources might
include—albeit not limited to—information about:
1. The current location of the manuscript (index number in the archive/library,
place, city, country).
2. The origin of the document including information about the place and dat-
ing, the sender and the receiver of the source, or the creator and/or the user
of the cipher key.
3. The content of the document including its type (e.g., a ciphertext, a cipher
key, or a manual about cryptology), and the language(s) involved.
4. Additional information might describe the symbol set of the ciphertext
alphabet (e.g., digits, alphabets, graphic signs), the cipher type (sim-
ple, homophonic, or polyphonic substitution), the nature of nomenclature
elements, or instructions.
Unfortunately, such metadata for encrypted sources is difficult to find in the
archives and libraries, as they are hardly indexed and only a few know about their
whereabouts. As a result of this—hardly operationalizable—process several online
collections are available that also offer digital scans. Besides the blog authors already
mentioned, Satoshi Tomokiyo’s private homepage Cryptiana [20] contains original
ciphers and keys from the 15th to the 20th centuries and also helpful material on the
i i
i i
i i
cryptanalysis of historical ciphers. Eugen Antal and Pavol Zajac’s Portal of Historical
Ciphers [21] hosts a yet small but growing database of original historical ciphers from
the 17th up to the 20th century focusing on Central-European encrypted sources
released with a nice graphical interface. And finally, being part of the DECRYPT
project, the DECODE database [13] is the largest source for historical ciphers and
keys today. At the time of writing (November 2023), the database contains over 7,000
historical encrypted sources, all stored with their original image(s) and annotated with
metadata along with related documents such as transcriptions.
All collections of encrypted sources face two difficulties, one legal and one
technical. First, the owner of the given records (let them be archives or libraries)
usually does not allow making public high-resolution images in the online collec-
tion for copyright reasons. Thus, often only a low-resolution reproduction can be
shared with the public. Second, visual recognition software requires good quality
high-resolution (at least 300 DPI) copies. However, there has been considerable
improvement in this second field, and thus sufficiently readable documents can be
offered to the transcription tool, the next phase of the pipeline.
3.4 Transcription
Once collected, the images of the encrypted source must be turned into some
computer-readable text format needed for the cryptanalysis part of the process. The
digitization involves the conversion of the ciphertext as well as cleartext and/or
plaintext passages appearing in the manuscript into a text representation. This
means in particular that the symbols of the ciphertext in the images are replaced
by machine-readable symbols and the cleartext and plaintext sequences are inter-
preted and transcribed. There are different methods and approaches how this can
be done. In the following, we focus on the transcription of ciphertext and describe
two methods: a manual option and a semiautomatic option. While the manual
option relies entirely on human effort, the semiautomatic option uses computer-
vision technology based on artificial intelligence (AI) methods followed by manual
postcorrection of the AI output. We show the challenges with both methods and
discuss their advantages and disadvantages in the last section.
i i
i i
i i
Handwriting styles vary across individuals, and some writing is more clear than
others. But it also changed across time periods and geographic areas. However, for
these script types scholar descriptions can be found in handbooks of paleography.
Script models in tables can serve as support. Also, abbreviations commonly used in
historical texts changed over time.
Manual transcription of historical texts in general and probably historical
ciphertexts in particular is laborious and time-consuming. It requires a high level
of concentration and despite all efforts it is prone to inconsistencies and mistakes.
In addition, the personnel needed causes expenses.
Even if the transcription should be as accurate as possible, the transcriber has
to make decisions with regard to how detailed a transcription should be. In general,
we can differentiate between two different levels of granularity. Either we transcribe
very close to the historical writing and represent all word boundaries, all punctu-
ation, all line and page breaks, and give spelling and abbreviations exactly as they
appear in the original text (diplomatic transcription), or we modernize for instance
punctuation and spelling, correct obvious mistakes, and dissolve abbreviations to
help the modern reader (normalized transcription).
For historical ciphertext, we apply a high degree of granularity and aim to
capture as many details as possible, for instance spacing, diacritics, and punctuation
marks (i.e., everything that might be of relevance to be able to recover the plaintext).
In the DECRYPT project, diplomatic transcription is applied.
One of the first tasks of the transcription process is to identify and segment each
symbol in the ciphertext. Sometimes it is straightforward, as in the case of the clearly
segmented digit-based cipher or the eclectic collection of symbols in the Copiale
cipher, shown in Figure 3.1. Sometimes symbol segmentation is rather difficult,
especially when the scribe used connected handwriting style with touching sym-
bols, as in the case of the Borg cipher in Figure 3.1. To segment symbols correctly,
it is helpful to look at highly similar symbols as they occur in the manuscript, espe-
cially in connection to other symbols to see where the symbol boundaries should be
drawn. Spaces as shown in the original should not be left out from the observation.
Spaces in ciphertexts can be intentional, often marking symbol boundaries and also
word boundaries from the plaintext. However, spaces are sometimes just added to
make decipherment harder. Spaces can also be unintentional where the scribe hap-
pened to put a space during writing that actually can reveal an actual word bound-
ary in the plaintext. Therefore, spaces should be carefully observed and transcribed.
At the same time or as a next step, it is natural to group the similar symbols
into a type and assign a unique letter or symbol to each symbol type to be used for
transcription. The main difficulty at this step lies in the definition of a group. How
similar shall the symbols be in order to be clustered into one group? Should a, a.,
á, à, å, and ä be one or several groups? How many? Investigating what types of
symbols the ciphertext alphabet consists of and how frequent specific symbols are
and in what context of other symbols (n-grams) they appear in can be of help. For
example, if we can find some digits (1–3), then it is probable that we can find all
digits (0–9). Similarly, if we can find some zodiac symbols, we can expect to find
more of them, or even all 12. If a symbol with a dot appears only in one or a few
cases, the dot could be an ink spot; but if it appears and is used systematically, it
should be treated as a symbol type.
i i
i i
i i
A big challenge for the transcription of ciphertexts is with eclectic symbol sets
using a large variation of graphic signs; see examples of the Borg and Copiale
ciphers in Figure 3.1. Many symbols look similar making it unclear whether we
have to do with two distinct cipher symbols or the same symbol with some graphic
variation due to the handwriting. For example, the zodiac signs ` and b (UTF-8
char: U+264D and U+264F, respectively), look similar at the first sight but if we
are familiar with zodiac signs, we can easily distinguish between the two. Human
creativity many times invented their own signs with tiny differences between some
symbol types, representing different plaintext entities. The challenge of identifying
the unique ciphertext alphabet can often be only solved together with the following
decipherment process.
To be able to study ciphers and compare them over time and across geographic
areas, it is an advantage to have a transcription standard for encrypted sources so
that the same symbol types are transcribed similarly across ciphertexts as well as
cipher keys. A standardized transcription of all encrypted sources allows match-
ing of ciphertexts with their corresponding key, which makes both decryption and
historical contextualization more straightforward.
Within the DECRYPT project, transcription guidelines were developed; see [22]
and [23]. The guidelines deal with the systematic transcription of ciphertext images,
cipher-key images, and cleartext images.
The basic principle of the transcription is to transcribe the manuscript as close
to the original as possible with a special attention directed on the ciphertext itself.
Each line is transcribed symbol by symbol with line breaks, spaces, punctuation
marks (periods, commas, question marks), diacritics, and underlined sequences
marked. Symbols are represented in Unicode using the UTF-8 encoding scheme
[24]. Uncertain symbols are transcribed with the guessed symbol followed by a
question mark. Unknown letters are marked with an asterisk (*). Figure 3.10 shows
Figure 3.10 Transcription of the Borg cipher [4] represented as Unicode names, converted to Unicode codes,
and visualized as original symbols.
i i
i i
i i
a transcription of the Borg cipher with its eclectic symbol set using Unicode names
that can be automatically converted to the actual Unicode codes, and finally repre-
sented graphically as icons. It is up to the transcriber’s preference to use the Unicode
names, which are easier to memorize, or to transcribe graphic signs directly as Uni-
code codes. Either way, using the keyboard for digits, punctuation marks, and the
Latin letters is always preferable for faster progress.
To make the process of decipherment easier, transcription does not always keep
to the original image. Instead, the transcription in some cases needs to reflect the
intention of the encoder. This means that corrections in the manuscript are tran-
scribed as was presumably intended by the scribe. For example, notes in the margin
denoting corrections are transcribed and added to the place as indicated by the given
mark in the original, as illustrated in Figure 3.11. Crossed-off symbols in the orig-
inal are not transcribed but should be added as a comment in the metadata of the
transcription file.
Like ciphertexts, cipher keys are transcribed using UTF-8 encoding. However,
since cipher keys can be structured in many ways, we do some generalization in the
representation of the layout. We separate the plaintext and the code elements onto
two sides (different columns), showing this by adding “code” or “plaintext.” Each
pair is written in a separate line. In cases where several code elements (in the case of
homophonic ciphers) or plaintext elements (in the case of polyphonic ciphers) are
listed, the alternative elements are transcribed sequentially separated by a bar (“|”),
followed by “ – ” and the plaintext unit(s), regardless of whether the alternatives
are written on several lines in the original or not. Special functions in keys (called
“operational code elements” in Table 3.1) are also transcribed. A transcription of
the cipher key in Figure 3.5 is illustrated in Table 3.2.
The transcription of cleartexts and plaintexts also should represent the original
text shown in the image. To be able to distinguish between ciphertext and cleartext
sequences, the latter is marked in brackets with a description of the language, as
h CLEARTEXT LANG-ID Letter_sequence i. The language ID is a two-letter code
defined by ISO 639-1. In addition, catchwords (i.e., a sequence of symbols antici-
pated as the first symbol(s) of the following page, served to mark page order), are
written in brackets. These are marked as h CATCHWORD Symbol_sequence i.
Some documents are damaged and the readability of cipher symbols and other
text passages are therefore limited. In these cases, a transcriber marks insecurities
in the transcription with a question mark or an asterisk for missing elements. The
type of material damage causing the insecurity is described in the metadata, which
should be part of the transcription file, and/or as a comment in the transcription.
A similar problem might occur when the image quality provided by the archive or
library is too poor. Problems caused by low resolution can to some extent be solved
i i
i i
i i
i i
i i
i i
1. https://www.cryptool.org/en/ctts.
i i
i i
i i
Figure 3.12 Ciphertext transcribed with the program CrypTool Transcriber and Solver.
i i
i i
i i
Figure 3.13 Ciphertext cryptanalyzed with the program CrypTool Transcriber and Solver.
i i
i i
i i
Figure 3.15 Example of symbol segmentation and transcription; segmentation shown in red, transcription
in blue.
i i
i i
i i
2. Cuneiform is a logosyllabic script used to write several languages of the ancient Near East (from around
3500 BC).
i i
i i
i i
learn how to transcribe symbols from one alphabet, and then use this knowledge
when transcribing symbols from an unseen new alphabet. Secondly, semi- and self-
supervised learning aim to learn representations from few or no labeled data, which
can transfer well to recognition tasks. These types of methods can also be combined
with few-shot learning. For example, in [32] a few-shot learning method incremen-
tally transcribes the symbols with a higher confidence rate (namely pseudolabels),
assuming that their labels are correct, and uses these pseudolabels as training data
for the next iterations, as shown in Figure 3.16. It must be noted that all these types
of approaches require only a few annotated examples compared to standard deep
learning methods, while reaching a performance only slightly below the typical deep
learning-based ones.
Figure 3.16 Example of incremental transcription by pseudolabeling. At each iteration, the method
transcribes the symbols with higher confidence. Each color corresponds to one label. (From: [32].
Reprinted with permission.)
i i
i i
i i
3.5 Cryptanalysis
3.5.1 Tokenization
Tokenization in the context of historical ciphers is defined as the separation of
ciphertext into single code elements, be it alphabet or nomenclature codes. Tok-
enization can be straightforward if the code elements are clearly segmented from
each other by separators like a space. Tokenizing a ciphertext that consists of
i i
i i
i i
graphic symbols (e.g., alchemical or zodiac symbols) is often also easy as each sym-
bol being regarded as one token (i.e., one alphabet-code element). However, the
tokenization of graphic ciphers sometimes has to be refined or corrected during the
cryptanalysis because the creator of a transcription of a ciphertext falsely regarded
two symbols as one token.
In contrast, tokenizing digit-based ciphers that are written in a continuous
script (scriptio continua), without segmentation between the code elements, is chal-
lenging. So far, no solution has been found that allows the generally automated
tokenization of such ciphertexts. At the time of writing, tokenizers need to be
developed and adapted to individual ciphertexts.
Before attempting to develop a new tokenizer, we can start by applying the
most trivial one—tokenizing the ciphertext into two-digit alphabet-code elements,
which occur commonly in early modern ciphers. We can also apply already exist-
ing tokenizers developed for particular sets of ciphers originating from the same
source to new ciphertext of the same collection, such as the papal ciphers from the
Vatican or diplomatic correspondence between two sources. If the abovementioned
alternatives do not lead to a correctly tokenized ciphertext, a new tokenizer has
to be developed. To do so, the ciphers and the corresponding ciphertexts have to
be statistically analyzed to find a set of rules the tokenizer is based on. Counting
and analyzing unigram, bigram, and trigram frequencies of single digits, two-digit
codes, three-digit-codes, and so forth are normally performed. Analysis contains
to discover various structures in the code system. For example, if we see that the
digit “2” is always in front of an odd digit, it may indicate that the combinations
“21,” “23,” “25,” “27,” and “29” are valid tokens and may represent alphabet-
code elements. In the end, one has to manually look for such peculiarities in the
frequencies. The tokenizer can then be applied to the ciphertext and its output be
run by the cryptanalysis algorithm(s) of choice (e.g., CT2) to recover the key. If
cryptanalysis fails, the tokenizer is probably incorrect and needs adjustment. In the
end, the process of tokenization of the ciphertext and the development of a valid
tokenizer is a trial-and-error but inevitable process for successful cryptanalysis.
i i
i i
i i
The five steps of the hill-climbing algorithm can be clustered into two parts: The
first part is the initialization, which is steps (1) to (3). It first generates a random
start key and rates its “cost” using a cost (or fitness) function. The higher the cost
value, the closer the decrypted plaintext is to real text. In the second part, the
algorithm incrementally improves the key. To do so, it generates in step (4a) a
slightly modified key, which it then rates in step (4c) using the same cost function
as in the initialization part. When the cost value is higher than the previous one it
keeps the new cost value as well as the new key. The algorithm loops as long as
a defined termination criterion is not met. Finally, in step (5) it outputs the key k,
which is with high probability the correct key kc .
The algorithm can be visualized in a two-dimensional graph as shown in
Figure 3.17. Here, the keys are drawn at the x-axis, and the corresponding cost
values at the y-axis. The hill-climbing algorithm follows the cost function to find
the global maximum (= the key kc ). The figure shows a potential problem of the
hill-climbing algorithm, namely local maxima where the algorithm might get stuck
(sitting stick figure). Later in this section, we will discuss how to mitigate the effects
of local maxima on the success rate of cryptanalysis. Also, keep in mind that while
the algorithm can be nicely drawn in a two-dimensional manner, the real problem
is a multidimensional problem with, for example, 26 dimensions in the case of the
simple substitution cipher with a 26-letter alphabet.
i i
i i
i i
In the following, we discuss different aspects and design ideas of the hill-
climbing algorithm to break simple substitution ciphers.
Decrypt function and key representation. For the simple substitution cipher, our
decryption function requires both the ciphertext and a key as input. The key is
represented by a string or array of characters with the same length as the plain-
text alphabet. For example, the key “WDNBZCJHOKQRPEISFTUGVXYALM”
means that the “W” is decrypted to “A,” the “D” is decrypted to “B,” ..., and the
“M” is decrypted to “Z.” The actual decryption is performed by walking letter
by letter through the ciphertext and replacing the ciphertext letters with plaintext
letters as described before.
Start key. The generation of the start key can be crucial for the success of a hill-
climbing algorithm. For some ciphers, a “good” start key is needed to allow the
algorithm to converge to the correct solution. With the simple substitution cipher,
the start key can just be chosen at random. To do so, we take the alphabet of
the assumed plaintext language (e.g., the Latin 26-letter alphabet for the English
language) and create a key by shuffling it:
ABCDEFGHIJKLMNOPQRSTUVWXYZ → WDNBZCJHOKQRPEISFTUGVXYALM
With historical encrypted manuscripts, the used alphabet can differ from the alpha-
bet we use today. Some letters may be represented by the same single letter (e.g.,
“I”=“J” and “U”=“V”). This depends on the plaintext language and the time of
the creation of the manuscript. Sometimes, letters may be intentionally omitted for
security purposes, such as by writing a single “L” instead of “LL” or “VV” instead
of “W.” Sometimes, the alphabets are extended, for example, by adding a symbol
for double letters (“LL”), “SCH,” or letters with diacritics (“á”). This all has to
be taken into account when generating an alphabet and keys with an automated
heuristic-based analyzer.
Cost function. The cost or fitness function evaluates the quality (cost or fitness
value) of a supposedly decrypted plaintext. Depending on the problem (the cipher),
a special cost function may have to be implemented. For the simple substitution
i i
i i
i i
Key modification. The next important part of the hill-climbing algorithm is how
to modify the key k to obtain a new key k 0 during a single iteration. Only a small
change in the key allows the algorithm to smoothly follow the curvature of the
graph of the cost function to potentially reach its global maximum.
Figure 3.18 shows how the key k is modified to create a new key k 0 during hill
climbing by swapping only two letters (here “C” and “F”) at the same time. There
are different strategies how to choose which two letters should be swapped:
1. Perform a single random swap: In every iteration of the hill-climbing algo-
rithm, use two random indices i and j with i 6= j. The two letters at position
i and j are swapped. Clearly, only “good” swaps are kept and “bad” swaps
are discarded.
2. Take only the “best” swap: In every iteration of the hill-climbing algorithm,
all indices i and j with i 6= j are tested. The “best” swap of all possible
letter swaps is kept. The “best” swap of all possible swaps is the “good”
swap, that increases the cost value the most.
3. Take all “good” swaps: In every iteration of the hill-climbing algorithm, all
indices i and j with i 6= j are tested. Every time a “good” swap occurs,
the swap is kept. This means, that during a test of all indices i and j in an
iteration, multiple consecutive “good” swaps may occur.
The classical hill-climbing algorithm as described in the literature uses random
swaps of two letters—the strategy (1) above. While this works well in most cases,
the two other strategies may improve the success rate as well and reduce the com-
putational time needed by the cryptanalysis algorithm. With strategy (2), we test
all possible swaps and only take the “best” possible “good” swap. A “good” swap
increases the current best cost value while a “bad” swap leads to the same or even
a worse cost value. With a 26-letter alphabet, there are 262·25 = 325 different swaps
that need to be tested in every iteration. Clearly, this slows down the algorithm
and increases the needed computation time in the worst case by a factor of 325.
To mitigate the effect of testing all possible two-letter-swaps, there is strategy (3)
that allows already to keep a “good” swap while all remaining swaps still need to
be tested. For example, the Vigenère analyzer component of CT2 uses strategy (3),
which allows solving really short Vigenère ciphertexts with high success rate in very
short times [34].
i i
i i
i i
Strategies to counter getting stuck. There are different strategies to counter getting
stuck with hill climbing in a local maximum:
1. Better start keys. With some ciphers, it is possible to already generate
“good” start keys that are close to the global maximum. In the case of
the simple substitution cipher, this is not needed, since any randomly cre-
ated start key can be used and will lead to the correct solution in nearly all
cases. In contrast, with homophonic substitution ciphers, a good start key
improves the success rate and performance of the algorithm. We describe
this later in Section 3.5.2.2.
2. Better key modification(s). For example, instead of swapping only two ele-
ments of the key at the same time, one could perform a triple swap, where
element i becomes j, j becomes k, and k becomes i while i 6= j 6= k. With
the simple substitution cipher and with the homophonic substitution cipher,
swapping only two letters at the same time is good enough.
3. Better cost function. When hill climbing does not find the correct key, it
is probably a good idea to change the cost function. For example, instead
of using n-gram models with n = 2, we could increase the dimension of the
language model to n = 3. With simple and homophonic substitution ciphers,
n = 5 works very well. Sometimes, it can also be useful to change to a lower
n, especially with bad transcriptions or many errors in the ciphertext. See
Section 3.5.3.
4. Shotgun hill climbing/random restarts. Another idea of improving the algo-
rithm is to restart it several times (e.g., 100 times) with different randomly
chosen start keys. This is also referred to as shotgun hill climbing, since the
start keys are distributed over the key space like shotgun shrapnels. With
the simple substitution cipher, this strategy is very effective.
5. Use of simulated annealing. This algorithm is an alternative to hill climbing.
See Section 3.5.2.2.
When working on a historical ciphertext, all the aforementioned improvements
have usually to be tested individually. For example, evaluations with different key
modifications and cost functions have to be performed to test the impact of the
changes on the cryptanalysis success rates. For CT2, the implemented cryptanaly-
sis algorithms were tested and tweaked with millions of artificially generated test
records until sufficient success rates were achieved. Additionally, all CT2 cryptanal-
ysis components allow exchanging the language model or set different parameters in
i i
i i
i i
Figure 3.19 The CT2 homophonic substitution analyzer solving an encrypted letter from Maximilian II.
i i
i i
i i
physical properties of the material. While in physical annealing, the real temper-
ature is slowly decreased; with simulated annealing a virtual temperature value is
used. The basic simulated-annealing algorithm consists of six steps:
In step (2) a start temperature is set. The start temperature, among other new
values needed for simulated annealing, has to be tweaked for each type of cipher
and often also for each individual ciphertext, which you want to cryptanalyze. The
termination criterion in step (5) now checks if the temperature t is still higher than
0. Inside the main loop of the algorithm, when a key k 0 is not accepted in step (5d),
a probability p based on the degradation value is computed and a random value r is
chosen. If r is smaller than the computed probability and the computed probability
is greater than a minimum probability pmin , the bad key is kept. In practice, we
set the minimum probability to pmin = 0.85%, which gave us good results. This
allows the simulated-annealing algorithm to jump away from local maxima. While
the algorithm is being executed, the temperature value t is reduced by a step size
ss. The value of s is predefined and can be determined, for example, by dividing
the start temperature by the number of wanted steps s, and then the algorithm
should perform. So ss := tstart s . Other temperature reduction strategies are also
possible. For example, instead of reducing the temperature by the same value ss all
the time, it could also be reduced by a percentage value of t with t := t − 0.01 · t.
The different strategies have to be evaluated to find the best one for the specific
case. Figure 3.20 shows a simulation of the key acceptance probability of simulated
annealing over time with a fixed temperature step size and Figure 3.21 shows a
simulation of simulated annealing with a percentage-based temperature step size.
i i
i i
i i
Figure 3.20 Key acceptance probability of simulated annealing with linear decreased temperature
over time.
Figure 3.21 Key acceptance probability of simulated annealing with percentage decreased tem-
perature over time.
i i
i i
i i
way that reflects the distribution of letter frequencies of the language. For
example, it is better to assign more homophones to more frequent plaintext
letters (e.g., the “E” with English) than to less frequent letters (e.g., the “X”
with English). Therefore, the Homophonic Substitution Analyzer of CT2
allows distributing the letters among the homophones based on probabilities
that are based on the original text frequencies of the language.
2. Homophone locking (manual). When analyzing homophonic substitution
ciphers, it may improve the cryptanalysis if already correctly assigned let-
ters can be fixed by the user. The Homophonic Substitution Analyzer of CT2
allows this in the semiautomatic mode. Here, the user may pause the analysis
and lock homophones, meaning the corresponding assignment of plaintext
letters to the homophones cannot be changed anymore by the cryptanaly-
sis algorithm during the further iterations. Also, the user may change and
correct the already made assignments.
3. Homophone locking (automatic with a dictionary). Besides manually lock-
ing homophones as described above, it is possible to automatically lock
homophones based on words found in a dictionary. Therefore, the Homo-
phonic Substitution Analyzer of CT2 provides a dictionary to the cryptanal-
ysis algorithm. Every time a new global best value (best key) is found, the
analyzer searches for words with a minimum and maximum length. If it finds
more words than a specified threshold value, it automatically locks all corre-
sponding homophones to their corresponding plaintext letters. This can also
be combined with the manual method for homophone locking described in
the second adaption.
i i
i i
i i
A language model file starts with the four ASCII characters “CTLM” (CrypTool
Language Model) to identify the file type. The “LanguageCode” string identifies the
language model. The “GramLength” defines the size of the n-gram model. The “Alpha-
bet” defines the used alphabet. In the data section, the actual language model data is
stored as 4-byte float values containing the logarithmic values computed using a text
corpus. The sizes of the n-gram models increase quickly with n, so the models are com-
pressed using the gzip algorithm. For the English language with 26 characters the file
4. See https://www.cryptool.org/en/cto/frequency-analysis.
5. See http://practicalcryptography.com/cryptanalysis/letter-frequencies-various-languages/.
i i
i i
i i
sizes on disc are (rounded): 1-gram: 1 kB, 2-gram: 3 kB, 3-gram: 50 kB, 4-gram:
800 kB, 5-gram: 8500 kB. Decompressed in RAM (rounded on 1 kB): 1-gram: 1 kB,
2-gram: 3 kB, 3-gram: 71 kB, 4-gram: 1828 kB, 5-gram: 47526 kB. One observation
here is that the more data (texts) are used to create these language models, the smaller
the amount of file size reduction achieved by compressing the models. The reason for
this is that the increase in entropy (aka amount of information) of the data used leads
to lower compressibility.
Once we have managed to reveal (parts of) the plaintext, we aim to set the manuscript
in a historical context to recover what was written, by whom, to whom, and why. Such
a contextualization concerns historical and philological interpretation, which will be
the topic of this section. These approaches involve a broader type of analysis than
cryptanalysis described above, because they do not primarily restitute the message,
but rather investigate the linguistic and historical context in which the message was
written, encrypted, and sent. Linguistic analysis involves the contextualization of the
given ciphertext into the contemporary language usage, which presupposes that we have
sufficient knowledge about how languages were used in the given time period and geo-
graphical area. Historical analyses do not only involves the identification of the sender
and receiver (and perhaps the code-breaker) of the ciphertext, and the political context,
but also the transfer of knowledge in the field of cryptology, as well as the social history
of those who applied this technology of secrecy.
i i
i i
i i
i i
i i
i i
keys consist of an alphabet part and a nomenclature table. One needs mathematical
and linguistic knowledge to analyze the alphabet, but reconstructing the nomenclature
table requires a deep knowledge of the historical context. In this second type of case,
history is an auxiliary science of the crypto-historian.
In the following, we provide a—by no means exhaustive—typology of the differ-
ent (sometimes contradictory, sometimes complementary) approaches when historical
analysis comes to the picture, and we exemplify each approach with a corresponding
publication.
1. One typical research path aims at getting new, previously unknown knowledge
by solving a given encrypted source. This approach enriches our picture of a particular
historical period and becomes useful for traditional history writing, but the emphasis is
more on cryptanalysis, the solution of a riddle [46].
2. A second typical research path follows the agenda of political history. Ciphers
were primarily used in diplomacy. The analysis of the correspondences of political cen-
ters with their ambassadors, messengers, and spies can provide new insight into the
history of a given era even if the exchanged letters had always been readable because
the historical addressee wrote the solution above the ciphertext characters. Examples
for this category include studies on diplomatic history [47–49], analyses on the earliest
black chambers, such as codebreaking offices [50], and the reconstruction of particular
encryption practices (polyphonic and fixed length ciphers) used in the 16th century in
the Vatican [51].
3. It is not the aim but the scope of the microhistory approach that makes it different
from the previous ones. In this case, a temporarily limited series of events (a few years
or a few exchanged letters) is analyzed with a variety of tools in order to have better
insight into one particular historical event, such as the study on encrypted letters sent
by and to the Habsburg Emperor Maximilian II in 1574–1575 [39, 52, 53].
4. The previous approach might be enriched with a linguistic analysis of the sources,
as described in the previous section. The two fields have always been close: study of
languages and cryptology have walked hand in hand from the earliest times.
5. An opposite approach is followed by those who perform large-scale statistical
analyses of cipher keys and/or encrypted documents. The emphasis is not on particular
sources but on conclusions, tendencies, and correlations that can be pointed out on the
basis of relatively big data. An example for this approach are the studies on the typology
and change of early modern cipher key documents [9, 54, 55].
6. Cryptology is both a technology and a scientific endeavor neighboring mathe-
matics; thus, it is a genuine topic for a history of science approach. Basic issues include
knowledge transfer (the ways this secretive knowledge is transferred from one genera-
tion to another, from one political center to another), the relations of cryptology to other
scientific fields (statistics, algebra, poetics, etc.), its technology use, and the evolution
of encrypting and codebreaking practices over time [19].
7. A separate category is populated by articles and book-length studies on spe-
cific famous ciphers, solved or unsolved, such as the Voynich manuscript [56, 57], the
Copiale manuscript [6], the Borg cipher [4], or the Beale ciphers [58].
8. Sometimes it is not the ciphers and keys but the social background of the users
that is under study. A social history of cryptology relies on the same sources but attempts
to answer different questions: Who are the human actors of crypto-history, what are
their attitudes to the technology they are using, what do they wish to keep as a secret,
and so forth [19].
9. And, finally, further approaches are conceivable and can be exemplified by the
continuously growing number of publications, including studies on personal diaries,
private ciphers, and so forth.
i i
i i
i i
3.7 Conclusion
i i
i i
i i
humanities to image processing and cryptology. The most well-known scientific pub-
lication sources for historical cryptology are, however, the proceedings of the annual
International Conference on Historical Cryptology (HistoCrypt) [61] and the journal
Cryptologia [62]. The community of historical cryptology has also a network called
HICRYPT that can be reached through the email address [email protected].
The work of this chapter was supported by the Swedish Research Council, grant
2018-06074, DECRYPT – Decryption of Historical Manuscripts https://de-crypt.org/.
References
[1] Friedman, W. F. D., and L. Callimahos, “Military Cryptanalytics, Part I,” National Security
Agency, United States Government, Washington, DC, 1959 (available through Aegean Park
Press, Laguna Hills, CA).
[2] Schmeh, K., Revisited: A Terminology for Codes and Nomenclators, 2018, https://
scienceblogs.de/klausis-krypto-kolumne/2018/10/07/revisited-a-terminology-for-codes-and
-nomenclators/.
[3] Mikhalev, V., et al., “What is the Code for the Code? Historical Cryptology Terminol-
ogy,” in Proceedings of the 6th International Conference on Historical Cryptology, 2023,
pp. 130–138, https://ecp.ep.liu.se/index.php/histocrypt/article/view/702.
[4] Aldarrab, N., Kevin Knight, and Beáta Megyesi, The Borg Cipher, https://cl.lingfil.uu.se
/∼bea/borg.
[5] Cipher ID-3816,reproduced image from the Swedish National Archive Riksarkivet 1637,
https://de-crypt.org/decrypt-web/RecordsView/189.
[6] Knight, K., B. Megyesi, and C. Schaefer, “The Copiale Cipher,” invited talk at ACL Work-
shop on Building and Using Comparable Corpora (BUCC), Association for Computational
Linguistics, 2011.
[7] Key ID-345, Reproduced image from the National Archives in Kew, State Papers.
TNA_SP106/2_ElizabethI_f58(0069). 1596. url: https://de-crypt.org/decrypt-web/
RecordsView/345.
[8] Key ID-633, Reproduced image from the National Archives in Hungary, G15
Caps. C. Fasc. 44. 01, DECODE ID 633, 1703–1711, https://de-crypt.org/decrypt-
web/RecordsView/633.
[9] Megyesi, B., et al. “Keys with Nomenclatures in the Early Modern Europe,” Cryptologia,
2022, doi: 10.1080/01611194.2022.2113185.
[10] Lasry, G., et al., “Deciphering ADFGVX Messages from the Eastern Front of World War I,”
Cryptologia, Vol. 41, No. 2, 2017, pp. 101–136.
[11] Lasry, G., N. Biermann, and S. Tomokiyo, “Deciphering Mary Stuart’s Lost Letters from
1578–1584,” Cryptologia, 2023, doi: 10.1080/01611194.2022.2160677.
[12] Megyesi, B., et al., “Decryption of Historical Manuscripts: The DECRYPT Project,”
Cryptologia, Vol. 44, No. 6, 2020, pp. 545–559, https://doi.org/10.1080/01611194.2020
.1716410.
[13] Megyesi, B., N. Blomqvist, and E. Pettersson, “The DECODE Database: Collection of
Ciphers and Keys,” in Proceedings of the 2nd International Conference on Historical
Cryptology, 2019.
[14] Szigeti, F., and M. Héder, “The TRANSCRIPT Tool for Historical Ciphers by
the DECRYPT Project,” in Proceedings of the 5th International Conference on
Historical Cryptology, 2022, pp. 208–211, https://ecp.ep.liu.se/index.php/histocrypt/
article/view/409/367.
[15] Kopal, N., and B. Esslinger, “New Ciphers and Cryptanalysis Components in CrypTool
2,” in Proceedings of the 5th International Conference on Historical Cryptology, 2022,
pp. 127–136.
i i
i i
i i
i i
i i
i i
[38] Pettersson, E., and B. Megyesi, “The HistCorp Collection of Historical Corpora and
Resources,” in Proceedings of the Digital Humanities in the Nordic Countries 3rd
Conference, March 2018.
[39] Kopal, N., and M. Waldispühl, “Two Encrypted Diplomatic Letters Sent by Jan Chod-
kiewicz to Emperor Maximilian II in 1574–1575,” in Proceedings of the 4th International
Conference on Historical Cryptology, 2021, pp. 80–89, doi: https://doi.org/10.3384
/ecp188409.
[40] Pettersson, E., and B. Megyesi, “Matching Keys and Encrypted Manuscript,” in Pro-
ceedings of the 22nd Nordic Conference on Computational Linguistics, October 2019,
pp. 253–261.
[41] Gambardella, M.-E., B. Megyesi, and E. Pettersson. “Identifying Cleartext in Historical
Ciphers,” in Proceedings of the Workshop on Language Technologies for Historical and
Ancient Languages, LT4HALA 2022, 2022.
[42] Waldispühl, M., and B. Megyesi, “Language Choice in Eighteenth-Century Diplomatic
Ciphers from Europe,” in Languages of Diplomacy in the Eighteenth Century (V. Rjéoutski
and G. Kazakov, eds.), Amsterdam University Press, 2023.
[43] Waldispühl, M., “Verschlüsselte Briefe: Mehrsprachigkeit und Geheimschrift im Schwedis-
chen Reich,” in Praktiken der Mehrsprachigkeit im Schwedischen Reich (1611–1721)
(M. Prinz and D. Stoeva-Holm, eds.), Harrassowitz, 2023.
[44] Kahn, D., “The Future of the Past—Questions in Cryptologic History,” Cryptologia,
Vol. 32, 2008, pp. 56–61.
[45] Mrayati, M., Y. MeerAlam, and M. Hassan at-Tayyan, eds., The Arabic Origins of
Cryptology, Volumes 1–6, KFCRIS & KACST, 2003–2006.
[46] Lasry, G., “Deciphering a Letter from the French Wars of Religion,” in Proceedings of the
5th International Conference on Historical Cryptology, 2022, pp. 147–152.
[47] Braun, G., and S. Lachenicht, eds, Spies, Espionage and Secret Diplomacy in the Early
Modern Period, Kohlhammer, 2021.
[48] Bullard, M. M., “Secrecy, Diplomacy and Language in the Renaissance,” in Das Geheimnis
am Beginn der europäischen Moderne, G. Engel, et al. (eds.), Klostermann, 2002, pp.
77–97.
[49] Desenclos, C., “Unsealing the Secret: Rebuilding the Renaissance French Cryptographic
Sources (1530–1630),” in Proceedings of the 1st International Conference on Historical
Cryptology, 2018, pp. 9–17.
[50] De Leeuw, K., “The Black Chamber in the Dutch Republic During the War of the Spanish
Succession and Its Aftermath, 1707–1715,” The Historical Journal, Vol. 42, No. 1, 1999,
pp. 133–156.
[51] Lasry, G., B. Megyesi, and N. Kopal. “Deciphering Papal Ciphers from the 16th to the
18th Century,” Cryptologia, 2020, pp. 479–540, https://www.tandfonline.com/doi/full
/10.1080/01611194.2020.1755915.
[52] Kopal, N., and M. Waldispühl, “Deciphering Three Diplomatic Letters sent by Maximilian
II in1575,” Cryptologia, Vol. 46, No. 2, 2022, pp. 103–127, doi: 10.1080/01611194
.2020.1858370.
[53] Dinnissen, J., and N. Kopal, “Island Ramanacoil a Bridge too Far. A Dutch Ciphertext
from 1674,” in Proceedings of the 4th International Conference on Historical Cryptology,
2021, pp. 48–57, https://ecp.ep.liu.se/index.php/histocrypt/article/view/156.
[54] Megyesi, B., et al. “Key Design in the Early Modern Era in Europe,” in Proceedings of the
4th International Conference on Historical Cryptology, 2021.
[55] Megyesi, B., et al. “What Was Encoded in Historical Cipher Keys in the Early Modern
Era?” in Proceedings of the 5th International Conference on Historical Cryptology, 2022.
[56] Pelling, N., The Curse of the Voynich: The Secret History of the World’s Most Mysterious
Manuscript; The Intriguing Story of the People, Places, and Politics Behind the Enigmatic
“Voynich Manuscript,” Compelling Press, 2006.
i i
i i
i i
[57] Kennedy, G., and R. Churchill, The Voynich Manuscript: The Mysterious Code that Has
Defied Interpretation for Centuries, Rochester, VT: Inner Traditions, 2006.
[58] Kruh, L., “A Basic Probe of the Beale Cipher as a Bamboozlement,” Cryptologia, Vol. 6,
No. 4, 1982, pp. 378–382.
[59] DECODE Records, https://de-crypt.org/decrypt-web.
[60] Tomokiyo, S., Confederate Ciphers During the Civil War: Various Vigenère Keywords,
2022, http://cryptiana.web.fc2.com/code/civilwar4.htm.
[61] HistoCrypt–International Conference on Historical Cryptology, https://histocrypt.org/.
[62] Cryptologia, https://www.tandfonline.com/journals/ucry20.
i i
i i
i i
CHAPTER 4
CHAPTER 4
Prime Numbers
This chapter introduces prime numbers (primes) and corresponding results from
number theory by asking and answering questions. It provides lots of examples
and is not as rigorous as mathematical textbooks usually are. At the end, you will
have a good understanding what primes are, what their distribution is like, and
why they are very useful in cryptography.
Prime numbers are integers greater than or equal to 2 that can only be divided by 1
and themselves. All other natural numbers that are not primes and greater or equal
to 4 are composite, they can be created by multiplying prime numbers.
The natural numbers N = {1, 2, 3, 4, . . .} thus comprise
Many people have been fascinated by prime numbers over the past two millen-
nia. Ambition to make new discoveries about prime numbers has often resulted in
brilliant ideas and conclusions. The following section provides an easily compre-
hensible introduction to the basics of prime numbers. We will also explain what
is known about the distribution of prime numbers (i.e., density, number of prime
numbers; intervals in particular intervals), and how prime number tests work.
139
i i
i i
i i
Each integer number has a factor. Only the number 1 has one factor, itself, whereas
the number 12 has the six factors 1, 2, 3, 4, 6, 12. Many numbers can only be divided
by themselves and by 1. With respect to multiplication, these are the atoms in the
area of numbers. Such numbers are called prime numbers.
In mathematics, a slightly different (but equivalent) definition is used.
Definition 4.1 An integer p ∈ N is called prime if p > 1 and p only possesses the
trivial factors ±1 and ± p.
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97, . . .
The first 100 numbers include precisely 25 prime numbers. After this, the
percentage of primes constantly decreases. Prime numbers can be factorized in a
uniquely trivial way: p = 1 · p
All numbers that have 2 or more factors not equal to 1 are called composite
numbers. These include
4 = 2 · 2, 6 = 2 · 3
as well as numbers that look like primes, but are in fact composite:
Figure 4.1 gives a first impression of how primes are distributed between
natural numbers. There are many graphical forms of representation (the most well-
known is the Ulam spiral; see Figures 4.2 and 4.3). However, until now, these
graphical forms gained no new insights, but for some people they created the
impression that there are at least local patterns within the random distribution.
Theorem 4.1 Each integer m greater than 1 possesses a lowest factor greater than
1. This is a prime number p. Unless m is a prime number itself, then: p is less than
or equal to the square root of m.
√
Sample: 6 = 2 · 3 and 2 < 6 = 2.45
All integers greater than 1 can be expressed as a product of prime numbers—
uniquely. This is the claim of the first fundamental theorem of number theory (=
fundamental theorem of arithmetic = fundamental building block of all positive
integers).
i i
i i
i i
Figure 4.1 Primes within the first 390 integers in a (30 · 13) rectangle—marked with color.
Figure 4.2 Primes within the first 999 integers in a (33 · 33) rectangle as Ulam spiral (graphics from CT2
Crypto Tutorials F World of Primes F Distribution of primes F Ulam's spiral).
i i
i i
i i
Figure 4.3 Primes within the first 40,000 integers in a (200 · 200) rectangle as Ulam spiral.
Theorem 4.2 Each element n of the natural numbers greater than 1 can be written
as the product n = p1 · p2 . . . pm of prime numbers ( p1 , p2 , . . . , pm are called the
prime factors of n). If two such factorizations
n = p1 · p2 · · · pm = p10 · p20 · · · pm
0
0
are given, then they can be reordered such that m = m 0 and for all i: pi = pi0 .
In other words, each natural number other than 1 can be written as a product
of prime numbers in precisely one way, if we ignore the order of the factors. The
factors are therefore unique (or you can say: the expression as a product of factors
is unique). For example,
60 = 2 · 2 · 3 · 5 = 22 · 31 · 51 .
And this—other than changing the order of the factors—is the only way in which
the number 60 can be factorized. If you allow numbers other than primes as factors,
there are several ways of factorizing integers and the uniqueness is lost:
60 = 1 · 60 = 2 · 30 = 4 · 15 = 5 · 12 = 6 · 10 = 2 · 3 · 10 = 2 · 5 · 6 = 3 · 4 · 5 = · · · .
This paragraph is for those familiar with mathematical logic: The first funda-
mental theorem may appear to be obvious, but we can construct numerous other
sets of numbers (i.e., other than positive integers greater than 1), for which num-
bers in the set cannot be expressed uniquely as a product of the prime numbers of
the set: In the set M = {1, 5, 10, 15, 20, . . .} there is no equivalent to the fundamen-
tal theorem under multiplication. The first five prime numbers of this sequence are
i i
i i
i i
5, 10, 15, 20, 30 (note: 10 is prime, because 5 is not a factor of 10 in this set—the
result is not an element of the given basic set M). As the following applies in M:
100 = 5 · 20 = 10 · 10
and 5, 10, 20 are all prime numbers in this set, the expression as a product of prime
factors is not unique here.
For the natural numbers, the primes can be compared to elements in chemistry
or the elementary particles in physics (see [2, p. 22]) as their building blocks.
Although there are only 92 natural chemical elements, the number of prime numbers
is unlimited.
Even the Greeks knew this in the third century B.C.; the theorem of the infinite-
ness of the primes had already been distinguished and proven in Euclid’s Elements
(Book IX, theorem 20). Euclid was a Greek mathematician in fourth and third
century B.C. who worked at the Egyptian academy of Alexandria and wrote The
Elements, the most well known systematic textbook of the Greek mathematics.
The following theorem of Euclid does not denote Euclid as the inventor of
the theorem; rather the true inventor is not known. The phraseology in the Greek
original is remarkable due to the fact that the word infinite is not used. The text
reads as follows:
O ί π%ω̃τ oι ὰ%ιϑµoὶ πλε ίoυς εὶσ ὶ π αντ òς τ oυ̃ π %oτ εϑ έντ oς π λήϑ oυς
π%ώτ ων ὰ%ιϑµω̃ν
The English translation is: The prime numbers are more than any previously existing
amount of prime numbers.
Or in a less literal translation:
Theorem 4.3 (Euclid). The sequence of prime numbers does not discontinue.
Therefore, the quantity of prime numbers is infinite.
His proof that there is an infinite number of primes is still considered to be
a brilliant mathematical consideration and conclusion today (proof by contradic-
tion). He assumed that there is only a finite number of primes and therefore there
exists a largest prime number. Based on this assumption, he drew logical conclu-
sions until he obtained an obvious contradiction. This meant that something must
be wrong. As there were no mistakes in the chain of conclusions, it could only be the
assumption that was wrong. Therefore, there must be an infinite number of primes!
i i
i i
i i
The largest prime numbers known today have several million digits.1 This is too big
for us to imagine. The number of elementary particles in the universe is estimated
to be “only” a 80-digit decimal number (see the overview in Section 4.12 about
various orders of magnitude / dimensions).
1. Using CT1 Indiv. Procedures F Number Theory Interactive F Compute Mersenne Numbers you
can calculate all digits of such a big number very quickly.
i i
i i
i i
Table 4.1 The 20+ Largest Known Primes and Their Particular Number Types∗
Definition Decimal Digits Year Description
1 282589933 − 1 24862048 2018 Mersenne, 51st known
2 277232917 − 1 23249425 2018 Mersenne, 50th known
3 274207281 − 1 22338618 2016 Mersenne, 49th known
4 257885161 − 1 17425170 2013 Mersenne, M-48
5 243112609 − 1 12978189 2008 Mersenne, M-47
6 242643801 − 1 12837064 2009 Mersenne, M-46
7 237156667 − 1 11185272 2008 Mersenne, M-45
8 232582657 − 1 9808358 2006 Mersenne, M-44
9 10223 · 231172165 + 1 9383761 2016 Generalized Mersenne
10 230402457 − 1 9152052 2005 Mersenne, M-43
11 225964951 − 1 7816230 2005 Mersenne, M-42
12 224036583 − 1 7235733 2004 Mersenne, M-41
13 202705 · 221320516 + 1 6418121 2021 Generalized Mersenne
14 220996011 − 1 6320430 2003 Mersenne, M-40
15 10590941048576 + 1 6317602 2018 Generalized Fermat1
16 9194441048576 + 1 6253210 2017 Generalized Fermat
17 168451 · 219375200 + 1 5832522 2017 Generalized Mersenne
18 3 · 218924988 + 1 5696990 2022 Generalized Mersenne
19 69 · 218831865 − 1 5668959 2021 Generalized Mersenne
20 7 · 218233956 + 1 5488969 2020 Generalized Mersenne2
…
42 213466917 − 1 4053946 2001 Mersenne, M-39
…
46 19249 · 213018586 + 1 3918990 2007 Generalized Mersenne
…
152 26972593 − 1 2098960 1999 Mersenne, M-38
…
2115 1372930131072 + 1 804474 2003 Generalized Fermat3
…
2152 342673 · 22639439 − 1 794556 2007 Generalized Mersenne
∗ As of April 2022.
1 Generalized Fermat number: 10590941048576 + 1 = 1059094(220 ) + 1.
2 Generalized Mersenne number: As 18233956 is no power of 2 it is no Fermat number.
3 Generalized Fermat number: 1372930131072 + 1 = 1372930(217 ) + 1.
Written out in binary form, a Mersenne number consists only of 1s. M (2) = 3,
or in binary digits 11. M (3) = 7, or 111. M (4) = 15, or 1111. M (5) = 31, or
11111.
Almost all of the biggest known prime numbers are special candidates of the
form 2 p − 1, where the exponent p is a prime. Not all Mersenne numbers of this
form are prime:
M (2) : 22 − 1 = 3 ⇒ prime
M (3) : 23 − 1 = 7 ⇒ prime
M (5) : 25 − 1 = 31 ⇒ prime
M (7) : 27 − 1 = 127 ⇒ prime
M (11) : 211 − 1 = 2047 = 23 · 89 ⇒ NOT prime !
Even Mersenne knew already that not all Mersenne numbers are prime (see
exponent p = 11). A prime Mersenne number is called Mersenne prime number.
i i
i i
i i
Figure 4.4 Number of digits of largest known prime by year (as of April 2022) (own plot, thanks
to data from Chris Caldwell [3]).
[ M (n ) is prime ⇒ n is prime ]
From
we conclude
i i
i i
i i
Because 2n − 1 is a prime number, one of the above two factors on the right-
hand side must be equal to 1. This is the case if and only if n 1 = 1 or n 2 = 1.
But this contradicts our assumption. Therefore, the assumption is false. This means
that there is no composite number n, such that 2n − 1 is a prime.
Notes:
The following two statements are equivalent because from A ⇒ B follows ¬B ⇒
¬A:
Unfortunately, Theorem 4.4 only applies in one direction (the inverse statement
does not apply, no equivalence): That means that there are prime exponents for
which the Mersenne number is not prime (see the above example 211 − 1, where 11
is prime, but 211 − 1 is not).
Mersenne claimed that 267 − 1 is a prime number. There is also a mathematical
history behind this claim: It took over 200 years before Edouard Lucas (1842–1891)
proved that this number is composite. However, he argued indirectly and did not
name any of the factors. In 1903, Frank Nelson Cole showed which factors make
up this composite number:
i i
i i
i i
As of May 1, 2023 all prime exponents smaller than 63,589,987 have been
tested and double-checked. So we can be certain that M-48 is really the 48th
Mersenne prime number, and that there are no smaller undiscovered Mersenne
primes (it is common not to use the notation M-nn until it is proven that the nn-th
“known” Mersenne prime is really the nn-th Mersenne prime).
Here are some examples in more detail:
23021377 − 1
has 909,526 digits in the decimal system, which are equivalent to 33 pages of a
newspaper.
26972593 − 1
has 2,098,960 digits in the decimal system (that are equivalent to around 77 pages
of a newspaper).
213466917 − 1,
i i
i i
i i
(924947738006701322247758 · · · 1130073855470256259071)
GIMPS
The GIMPS project (Great Internet Mersenne Prime Search) was founded
in 1996 by George Woltman to search for new largest Mersenne primes
(https://www.mersenne.org). Further explanations about this number type can be
found in the Sections Mersenne numbers and Mersenne primes.
So far, the GIMPS project has discovered 17 largest Mersenne primes, including
the largest known prime number ever. Table 4.3 contains these Mersenne record
primes.
Richard Crandall discovered the advanced transform algorithm used by the
GIMPS program. George Woltman implemented Crandall’s algorithm in machine
language, thereby producing a prime-search program that has unprecedented
efficiency.
On June 1st, 2003 a possible Mersenne prime was reported to the GIMPS server
that was checked afterward as usual, before it was to be published. Unfortunately,
mid-June the initiator and GIMPS project leader George Woltman had to announce
that two independent verification runs proved the number was composite. This was
the first false-positive report of a client in 7 years. Since the end of 2020 new proofs
are used that eliminate the need for double checks.
As of May 2023, more than 250,000 volunteers, amateurs and experts have
participated in the GIMPS project. They connect their computers into the PrimeNet,
originally organized by the company Entropia.
i i
i i
i i
3. - Using CT1 Indiv. Procedures F RSA Cryptosystem F Prime Number Test the following tests can be
performed: Miller-Rabin, Fermat, Solovay-Strassen und AKS. The first three are probabilistic tests.
- With the educational tool for number theory NT you can apply the tests of Fermat and of Miller-Rabin: See
in there the NT learning units 3.2 and 3.3, pages 3-11/11. NT can be called via CT1 Indiv. Procedures
F Number Theory Interactive F Learning Tool for Number Theory.
- Using CT2 Templates F Mathematics F Primes Test a brute-force test with small factors and the
Miller-Rabin test is performed.
- In CT2 Crypto Tutorials F World of Primes F Primality test the following methods are visu-
alized and their single steps can be reproduced: Sieve of Eratosthenes, Miller-Rabin test and Sieve of
Atkin.
i i
i i
i i
We will not go into the various test methods here, but show the most important
property of prime numbers and which numbers are false witnesses in this context
(i.e., they fulfill the primality property even though they are composite). Primality
tests only answer the primality property of a number, but cannot determine the
prime factors of composite numbers. Small implementations for this can also be
found in the supplied Python and SageMath programs.
Obviously, determining primality cannot be harder than factoring: If we know
how to factor, we have a test for primality. But it is surprising and fundamental for
some asymmetric algorithms that primality testing is so much easier than factoring.
If an a exists where the congruence from Theorem 4.5 is not met, we say a
is a “Fermat witness” to the composite nature of p. So witnesses can very quickly
inform us that a number p is not prime.
One can also say that Fermat’s prime property is a necessary but not a sufficient
condition for the number p to be prime.
i i
i i
i i
2n ≡ 2 mod n
but are not prime are called pseudoprime numbers for the basis 2 (i.e., the exponent
and the modulus n are not prime). The first pseudoprime number for the basis 2 is
341 = 11 · 31
In SageMath4 you can easily verify that 341 satisfies the negative test 2341 ≡ 2
mod 341, which is derived from Theorem 4.5:
SageMath Example 4.1: Find on the Sage Command Line Nonprimes That
Pass the Fermat Test
# Calculate pseudoprimes for base a = 2 (which pass the Fermat �
� primality test)
# Note: 2.powermod(n,n) is circa 3 times faster than power_mod(2,n,n) �
� cause usage of gmp
sage: a=2; count=0
....: for n in range(1,4000):
....: if n not in Primes () and a.powermod(n,n) == 2:
....: print ("%
....: print ("How many numbers found with this property :", count)
....:
2^n mod n == n for n = 341
2^n mod n == n for n = 561
2^n mod n == n for n = 645
2^n mod n == n for n = 1105
2^n mod n == n for n = 1387
2^n mod n == n for n = 1729
2^n mod n == n for n = 1905
2^n mod n == n for n = 2047
2^n mod n == n for n = 2465
2^n mod n == n for n = 2701
2^n mod n == n for n = 2821
2^n mod n == n for n = 3277
How many numbers found with this property: 12
i i
i i
i i
2. Carmichael Numbers. There are pseudoprime numbers n that pass the Fermat
test
a n−1 ≡ 1 mod n
with all bases a that are relatively prime to n [gcd (a, n ) = 1], even though the
numbers n tested are not prime. These numbers are called Carmichael numbers.
So the set of powers to be tested is restricted to those where a and n are relatively
prime. For an n now it is not enough to test just an arbitrarily chosen a, but all a < n
that are coprime to n. The first of these is
561 = 3 · 11 · 17
# Calculate the Carmichael numbers n (composite numbers with a prime property) up to upper=1000 �
�0
# Like primes they fulfill the Fermat congruence a^n = a mod n,
# plus: for them the congruence is valid for all a with gcd(a,n)=1
# Remarks:
# - With "for a in range(2, 4000):" a's type is <class 'int '>. Using then
# "a.powermod(n,n)" causes AttributeError: 'int ' object has no attribute 'powermod '
# Therefore , the range over Sage integers (class Integer) is used.
# - It 's good enough to test "a" up to the given "n" (must not always go to "upper ")
# - This is a very straightforward implementation. It could be made quicker :-)
i i
i i
i i
def print_carmichael(maximum):
for n in range(3, maximum+1, 2): # consider only odd numbers >= 3
if is_carmichael(n):
print(n)
print_carmichael(upper)
For some composite numbers it’s hard to find a witness with the Fermat test.
With Carmichael numbers the Fermat test actually always fails. They are “liars”
for all coprime bases.
The first 16 Carmichael numbers are 561, 1105, 1729, 2465, 2821, 6601,
8911, 10585, 15841, 29341, 41041, 46657, 52633, 62745, 63973, and 75361.
They start to become increasingly rare after that.
There are 2,0138,200 Carmichael numbers between 1 and 1021 . This is
approximately one in 50 trillion (50 · 1012 ) numbers [5].
The largest known Carmichael number has almost 300 · 109 digits [6]. This
number is much greater than the largest known prime (see Table 4.1).
In 1992, Carl Pomerance proved that there are infinitely many Carmichael
numbers. Carmichael numbers have at least three prime factors, none of which are
duplicates. So they are square free.
The Carmichael numbers are sequence A002997 at OEIS. This list contains
all Carmichael numbers up to 1, 713, 045, 574, 801 ≈ 1.7 · 1012 (these are the first
10,000 ones).
i i
i i
i i
4.6 Special Types of Numbers and the Search for a Formula for Primes 155
either bm ≡ 1 mod n
i
or ∃ i ∈ {0, 1, . . . , s − 1} : b2 m ≡ −1 mod n
15841 = 7 · 31 · 73
If you test all four bases, 2, 3, 5, and 7, you will find only one strong pseudoprime
number up to 25 · 109 (i.e., a number that passes the test and yet is not a prime
number).
More extensive mathematics behind the Rabin test delivers the probability that
the number examined is nonprime (such probabilities are currently around 10−60 ).
Detailed descriptions of tests for finding out whether a number is prime can be
found at [8, 9].
i i
i i
i i
n
4.6.4 Fermat Numbers Fn = f (n) = 22 + 1
In the seventeenth century, Pierre de Fermat wrote to Mersenne that he presumed
that all numbers of the form
n
f (n ) = 22 + 1
are prime for all integers n ≥ 0.
The first 5 numbers F0 = 3, F1 = 5, F2 = 17, F3 = 257, F4 = 65537 are
all prime (see Table 4.4). As mentioned, Fermat wrote to Mersenne regarding his
assumption that all numbers of this type are primes. This assumption was already
disproved by Euler in 1732. The prime number 641 divides F5 = f (5).
And as early as in the 19th century, it was discovered that the 39-digit number
7
f (7) = 22 + 1 (27 = 128)
is not prime. However, it was not until 1970 that Morrison/Billhart managed to
factorize it.
f (7) = 340282366920938463463374607431768211457
= 59649589127497217 · 5704689200685129054721
The project Distributed Search for Fermat Number Dividers [14] finds both new
compound Fermat numbers and new monster primes.
Example: On February 22, 2003, John Cosgrave discovered:
i i
i i
i i
4.6 Special Types of Numbers and the Search for a Formula for Primes 157
Table 4.4 List of the First Eight Fermat Numbers and Their Factorization
f(n) Value Prime?
0
f (0) = 22 + 1 = 21 + 1 =3 Prime
1
f (1) = 22 + 1 = 22 + 1 =5 Prime
2
f (2) = 22 + 1 = 24 + 1 = 17 Prime
3
f (3) = 22 + 1 = 28 + 1 = 257 Prime
4
f (4) = 22 + 1 = 216 + 1 = 65537 Prime
5
f (5) = 22 + 1 = 232 + 1 = 4294967297 = 641 · 6700417 Not prime !
6
f (6) = 22 + 1 = 264 + 1 = 18446744073709551617
= 274177 · 67280421310721 Not prime !
7
f (7) = 22 + 1 = 2128 + 1 = (see Section 4.6.4) Not prime !
• The largest prime nonsimple Mersenne number so far with 645,817 decimal
digits.
At that time this prime p was the largest known prime generalized Mersenne
number and the fifth largest known prime number of all.
f (18233954) is the biggest Fermat number of which a factor is known (as of
July 2023).
It is assumed that f (4) = 65, 537 is the last (and thus also the largest) Fermat
prime.
n
4.6.5 Generalized Fermat Numbers f (b, n) = b2 + 1
With generalized Fermat numbers, the base of the power is no longer restricted to
2. Generalized Fermat numbers are more numerous than Mersenne numbers of an
equal size and many of them are waiting to be discovered to fill the big gaps between
the Mersenne primes already found or still undiscovered. Progress in number theory
made it possible that numbers, where the representation is not limited to the base
2, can be tested at almost the same speed as Mersenne numbers.
The program Proth.exe was widely used to investigate generalized Fermat num-
bers. Proth.exe was created by Yves Gallot in 1998 as a single-threaded CPU
program that found many prime number records more than 20 years ago. The
successor genefer is a highly optimized GPU application, created in 2022 [12].
Using the original program, on February 16, 2003, Michael Angel discovered
the largest of them with 628,808 digits, which at that time became the fifth largest
known prime number:
17
b2 + 1 = 62722131072 + 1
i i
i i
i i
e1 =1+1 =2 7→ Prime
e2 = e1 + 1 =3 7 → Prime
e3 = e1 · e2 + 1 =7 7 → Prime
e4 = e1 · e2 · e3 + 1 = 43 7 → Prime
e5 = e1 · . . . · e4 + 1 = 13 · 139 7 → Not prime!
e6 = e1 · . . . · e5 + 1 = 3263443 7 → Prime
e7 = e1 · . . . · e6 + 1 = 547 · 607 · 1033 · 31051 7 → Not prime!
e8 = e1 · . . . · e7 + 1 = 29881 · 67003 · 9119521 · 6212157481 7 → Not prime!
Also, e9 , . . . , e17 are composite, which means that this formula is not particu-
larly useful.
Comment:
However, it is very particular that no pair of any of these numbers does have a
common factor other than 1. Therefore, they are relatively prime.
SageMath Example 4.4 calculates the Euclid numbers with +1 and −1.
i i
i i
i i
4.6 Special Types of Numbers and the Search for a Formula for Primes 159
# Initialization
e1 = 2; En=e1; print(1, En , is_prime(En))
e2 = 3; En=e2; print(2, En , is_prime(En))
Prod = e1 * e2
#------------------------------------
# CHAP04 -- Sage -Script -SAMPLE 015: =========
# Euclid numbers with +1 (and a variant with -1
# 1 2 True
# 2 3 True
# --Variant with +1:
# 3 7 True
# 4 43 True
# 5 1807 False
# 6 3263443 True
# 7 10650056950807 False
# 8 113423713055421844361000443 False
# 9 12864938683278671740537145998360961546653259485195807 False
# --Variant with -1:
# 3 5 True
# 4 29 True
# 5 869 False
# 6 756029 False
# 7 571580604869 False
# 8 326704387862983487112029 False
# 9 106735757048926752040856495274871386126283608869 False
4.6.9 f (n) = n 2 + n + 41
This sequence starts off promisingly, but that is by no means proof that things will
continue like this:
f (0) = 41 7→ Prime
f (1) = 43 7→ Prime
f (2) = 47 7→ Prime
f (3) = 53 7→ Prime
f (4) = 61 7→ Prime
f (5) = 71 7→ Prime
f (6) = 83 7→ Prime
f (7) = 97 7→ Prime
..
.
f (33) = 1163 7→ Prime
f (34) = 1231 7→ Prime
i i
i i
i i
The first 40 sequence values are different prime numbers (which have the obvi-
ous regularity that their difference starts with 2 and increases by 2 each time). Of
the 240 possible prime numbers p with 41 ≤ p ≤ 1601, there are 40 that occur in
the sequence.5
But the 41st and 42nd values are not prime numbers. It is easy to recognize
that f (41) cannot be a prime number:
The Euler polynomial f (n ) = n 2 + n +41 can be made visible in the Ulam spiral
(antidiagonal) by setting 41 as the starting value in the center. See Figure 4.5.6
5. How many prime numbers are really in a range can be easily determined with SageMath. Here, for example,
with len(list(primes(41,1602)))) or with pari(1601).primepi() - pari(40).primepi() = 252-
12 = 240.
6. Graphics from CT2 Crypto Tutorials F World of Primes F Distribution of primes F Ulam's
spiral.
i i
i i
i i
4.6 Special Types of Numbers and the Search for a Formula for Primes 161
Figure 4.5 Ulam’s prime spiral for the Euler polynomial f (n ) = n 2 + n + 41, starting with 41 in the
center.
C 0 = 2,
C1 = 2C0 − 1,
C2 = 2C1 − 1,
C3 = 2C2 − 1,
C4 = 2C3 − 1, . . .
i i
i i
i i
This sequence is defined recursively and increases extremely fast (much quicker
than the Mersenne prime numbers). Does this sequence consist only of primes?
C0 =2 7→ Prime
C1 = 22 − 1 =3 7 → Prime
C2 = 23 − 1 =7 7 → Prime
C3 = 27 − 1 = 127 7 → Prime
C4 = 2127 − 1 = 170141183460469231731687303715884105727 7 → Prime
It is not (yet) known whether C5 = 2C4 − 1 and all higher elements are prime.
In any case, it has not been proved that this formula delivers only primes.
It seems very unlikely that C5 (or many of the larger terms) would be prime. So
this could be another example of Guy’s law of small numbers.
i i
i i
i i
The first values of p for which M p is prime are p = 2, 3, 5, 7, 13, 17, 19, 31,
61, 89, 107, 127, 521, ... (see above).
M M p is known to be prime for p = 2, 3, 5, 7, and has the appropriate values:
for p in (2,3,5,7):
Mp=2^p-1
MMp=2^Mp -1
B=is_prime(MMp)
print(p,Mp ,MMp ,B);
#------------------------------------
# CHAP04 -- Sage -Script -SAMPLE 010: =========
# 2 3 7 True
# 3 7 127 True
# 5 31 2147483647 True
# 7 127 170141183460469231731687303715884105727 True
For p = 11, 13, 17, 19, and 31, the corresponding double Mersenne numbers
are not prime. The next candidate for the next double Mersenne prime is M M61 =
22305843009213693951 − 1.
Being approximately 1695 · 10694127911065419641 this number—like C5 (see
Section 4.6.12)—is far too large for any currently known primality test to be
successfully applied.
As Euclid proved, there is an infinite number of primes. However, some infinite sets
are denser than others.
Within the set of natural numbers, there is an infinite number of even, uneven,
and square numbers. How to compare the density of two infinite sets is shown with
the sets of even and square numbers.
Whereas in colloquial language you can often hear that “there are more” even
numbers than square ones, mathematicians say that from both there are infinitely
many that their sets are equivalent to N (so both are infinite and countable; i.e., one
can assign an integer to each even number and to each square number). However,
the set of even numbers is denser than the set of square numbers. The following
proves that the even numbers are distributed more densely than square ones:
i i
i i
i i
numbers is n 2 . Because for all n > 2: 2n < n 2 , the nth even number occurs
much earlier than the nth square number.
• The numbers of values that are less than or equal to a certain maximum
value x in R are:
√
There are bx /2c such even numbers and b xc square numbers. Because
for all x > 6 the value bx /2c is greater than the largest integer smaller or
equal to the square root of x, the even numbers are distributed more densely.
The number of prime numbers P I (x ). The definition for the number P I (x )—also
conventionally written as Π(x ), is similar: It is the number of all primes that does
not exceed the maximum value x.
Theorem 4.7 P I (x ) is asymptotic to x / ln(x ).
This is the famous prime number theorem. It was put forward by Adrien-Marie
Legendre and Carl Friedrich Gauss but not proved until over 100 years later.
Alternative ways of expressing this are:
P I → x / ln(x )
ln(x )
lim P I · =1
x→∞ x
x
lim ln(x ) =
x→∞ PI
For a binary number (these consist only of the digits 0 and 1) x of length of 250
bits (2250 is approximately 1.81 · 1075 ) and because the quotient P I (x )/(x / ln(x ))
i i
i i
i i
We can therefore expect that the set of numbers with a bit length of less than 250
contains approximately 1073 primes—a reassuring result!
We can also express this as follows: Let us consider a random natural number
n. Then the probability that this number is prime is around 1/ ln(n ). For example,
let us take numbers in the range of 1016 . Then we must consider 16 · ln 10 = 36.8
numbers (on average) until we find a prime. A precise count shows that there are
10 prime numbers between 1016 − 370 and 1016 − 1.
Another way to express this is: The average gap between two consecutive
primes near the number n is close to the natural logarithm of n. For example, for
a number n close to 100, ln(n ) ≈ 4.6, so roughly every fifth number in this range
should be prime. Further details about prime gaps can be found on [18] and in
Section 4.9.5.
Under the heading How Many Primes Are There in [19], you can find numerous
other details. Using the website in [20] you can easily determine P (n ) and P I (x ).
The distribution of primes displays several irregularities for which no system
has been found yet. On the one hand, many occur closely together, like 2 and 3, 11
and 13, 809 and 811, on the other hand large gaps containing no primes also occur.
For example, no primes lie between 113 and 127, 293 and 307, 317 and 331, 523
and 541, 773 and 787, 839 and 853 as well as between 887 and 907. Discovering
the secrets of these irregularities is precisely part of what motivates mathematicians.
Some visualizations (plots) of the quantity of primes in different number dimensions
can be found in Section 4.14.
4.8 Outlook
Currently, you can find large databases that contain either many primes or the fac-
torization of numerous composite numbers. The fastest factorizers on the internet
are FactorDB by Markus Tervooren [23] and Alpertron, the integer factorization
7. CT2 Crypto Tutorials F World of Primes also contains a visualization of this method.
i i
i i
i i
Figure 4.6 The sieve of Eratosthenes, applied to the first 120 numbers [21].
calculator by Dario Alpern [24]. Sometimes they just look in their databases to
see if they already know how to factor the entered number; then it is particularly
quick. Alpertron has implemented the two algorithms elliptic curve method (ECM)
and self-initializing quadratic sieve (SIQS) with WebAssembly so that they can run
purely locally in the browser. Another factorizer that runs purely locally in the
browser uses the Msieve library (https://www.cryptool.org/en/cto/msieve).
The following lists some interesting theorems, conjectures, and open questions
about primes, as well as some peculiar things and overviews.
i i
i i
i i
• Paul Erdös proved that between each random number not equal to 1 and its
double, there is at least one prime. He was not the first to prove this theorem,
but he proved it in a much simpler manner than those before him.
n
• There is a real number a such that the function f : N → Z where n 7→ ba 3 c
only delivers primes for all n (see [17, p. 82]). The Gauss bracket bxc of a real
number x is defined via: bxc is the next integer less or equal x. Unfortunately,
problems arise when we try to determine a (see Section 4.9.3).
i i
i i
i i
i i
i i
i i
Green and Tao intended to prove that there are infinitely many arithmetic
sequences of length four. For this purpose they considered sets of numbers con-
sisting of primes and near primes. These are numbers with a small set of divisors
like numbers that are the product of exactly two primes—these numbers are called
half primes. Thus, they managed to considerably simplify their work because there
were already a lot of useful theorems about near primes. Finally, they discovered
that the results of their theorem were far more reaching than they had assumed.
Therefore, they were able to prove Hardy’s conjecture.
Anyone who believes that it is easy to use Green’s and Tao’s 49-page proof to
compute arithmetic prime number sequences of arbitrary length will soon become
disappointed, because the proof is nonconstructive. It is a proof of existence. This
means that these mathematicians have shown “only” that these sequences exist, but
not how to find them in practice.
This indicates that in the set of the natural numbers there is, for example,
a sequence of one billion primes that all have the same distance; and there are
infinitely many of them. However, these sequences lie extremely far beyond the
numbers we usually use (far outside).
The length of a sequence determines the minimal distance between the single
primes of the sequence. Given a sequence with n = 6 elements the distance between
them has to be 30 or a multiple of 30. More precisely: If a PAP-k does not begin
with the prime k, then the common difference is a multiple of the primorial k#.
The number 30 results from the product of all primes smaller than the length of
the sequence (here 6): 6# = 5# = 2 · 3 · 5 = 30. Another example: 10# = 7# =
2 · 3 · 5 · 7 = 210. If you look for a sequence with 15 elements, then the common
distance is at least 15# = 13# = 2 · 3 · 5 · 7 · 11 · 13 = 30030. The primorial notation
starts with k = 2: 2# = 2, 3# = 2 · 3 = 6, 5# = 2 · 3 · 5 = 30.
This signals that the length of an arithmetic prime sequence can be arbitrary
big, but the distance between the elements cannot be any arbitrary number. For
example, there is no arithmetic prime sequence with the distance 100 because 100
cannot be divided by 3.
The minimal distances for sequences of length n are multiples of k# with k =
n − 1. The k-primorials (prime factorials) are shown in Table 4.7—the values were
calculated by SageMath Example 4.6.
i i
i i
i i
SageMath Example 4.6: Calculate the k Primorials (k#) for Table 4.7
print ("\n# CHAP04 -- Sage -Script -SAMPLE 060: =========")
print('\nGet k# = primorial numbers from OEIS Integer Sequence for Table 4.8:')
n=33; print(' Upper border for prime k (k<n): n =', n)
i i
i i
i i
Table 5.13 shows the different orders of magnitude up to which the current
algorithms for primality testing and for factorization deliver good results.
i i
i i
i i
Samples: 7 = 3 + 2 + 2 or 27 = 19 + 5 + 3 or 27 = 17 + 5 + 5.
The weak Goldbach conjecture was proven by the Peruvian mathematician
Harald Helfgott—more than 250 years after the original conjecture was stated.
Previous results had proved that the weak Goldbach conjecture is true for all odd
integers larger e3100 ≈ 2 · 101346 . In another preliminary work [28], Terence Tao
from the University of California proved that every odd natural number greater
than 1 can be represented as the sum of at most five prime numbers.
Before Helfgott’s proof (rigorous result), people tried to find out with the assis-
tance of computers for as many numbers as possible, whether the conjecture is
true or not. Computers verified the weak Goldbach conjecture for all odd natural
numbers up to: 4 · 1018 (simple check April 2012) and 4 · 1017 (double check May
2013).
The lower limit set by Helfgott’s proof in 2013 was 1030 . This was small enough
to handle the remaining cases by computer (which he did with David Platt, and thus
checked the validity for all numbers below 8.875 · 1030 with computer help) [29].
i i
i i
i i
i i
i i
i i
In order to approach such questions, one can take different paths and ask
different leading questions.
One was asked by the Norwegian mathematician Viggo Brun (1885–1978),
who looked at the sum of the reciprocals of successive twin primes. In 1919, he
proved that this sum converges to a specific numerical value (≈ 1.90216), which
is now called Brun’s constant. The fact that this sum converges shows that twin
primes are relatively rare, even though there might be infinitely many of them. In
contrast, the sum of the reciprocals of all primes diverges.
It’s interesting that the Pentium FDIV bug was found in 1994 by Thomas Nicely
when he used massive computing power to calculate Brun’s constant. The flaw in the
Pentium microprocessor caused only certain types of arithmetic errors. However,
his discovery forced the chip’s manufacturer to replace about one million faulty
processors (costing Intel about half a billion dollars).
In the following subsections, two major milestones are explained that may
allow us to come closer to the riddle of the number of twin primes.
i i
i i
i i
is good progress compared to 70 million, but far away from 2. H then has been
reduced to 6 (but only on the assumption of the Elliott-Halberstam conjecture).
Those results could be the basis for a final proof that infinitely many twin
primes exist.
1. Factorial N = n !
This is technically the easiest way to prove it. Then the considered N + k in
the sequence N + 2, N + 3, N + 4, . . . , N + n are each divisible by the k.
2. N = lcm (2, . . . , n )
You can also choose the least common multiple of the numbers from 2 to n.
3. Primorial N = n#
The smallest possible candidate for N is found through the primorial. If pm
is the smallest prime number greater than n, then n# = ( pm−1 )# applies.
This method of constructing such n-gaps (prime number gaps of length n)
uses primorials: n# = product of all primes ≤ n. See the introduction to
primorials in Section 4.9.2.
Although N was chosen as small as possible in the last case, it is still not guar-
anteed that the gap found is always the first gap of the required length n. In this
respect, all of these methods provide solid evidence and a specific gap. However,
they are only of limited use when searching for the first occurrence of large gaps.
i i
i i
i i
The first prime number gap of length n usually occurs well before n !+2, respectively,
N + 2.
Examples:
1. For example, to find a gap of at least length 4 (4-gap); that is, having at least
a triple of composite numbers in the gap, you set n = 4 and get the sequence
4! + 2, 4! + 3, 4! + 4, where 4! = 24. So a triple of composite numbers inside
the gap is (26, 27, 28). The first occurrence of such a triple is already before
4! at (8, 9, 10).
2. With n = 6 one finds a prime number gap of at least length 6 between the
following prime number candidates:
• Via factorial: N = 6! = 720 ⇒ N + 2 = 722; N + 6 = 726.
Since 721 is not prime, the gap is even larger. It is framed by the prime
numbers [719 and 727] and thus has the length 8.
• Via lcm: N = lcm (1, . . . , 6) = 60 ⇒ N + 2 = 62; N + 6 = 66.
Since both borders in [61,67] happen to be prime, the length is also
exactly 6.
• Via primorial: N = 6# = 2 · 3 · 5 = 30 ⇒ N + 2 = 32; N + 6 = 36.
The gap found [31, 37] has exactly the length 6 since both are prime
numbers.
• First gap of length 6: [23, 29] with g9 = 6. The index 9 means that it is
the gap between the 9th and the 10th prime number.
3. The factorial is the fastest growing function among the three functions
considered.
• For n = 6 this was: n ! = 720, lcm (2, . . . , 6) = 60, and n# = 30.
The first gap of exactly length 6 is [23,29] with g9 = 6.
You can calculate this with SageMath:
sage: n=6; factorial(n); lcm(2..n);
primorial=sloane.A002110; primorial(int(pari(n).primepi()))
• For n = 10 the following applies: n ! = 3628800, lcm (2, . . . , 10) =
2520, and n# = 210.
The first gap of exactly length 10 is [139,149] with g34 = 10.
• For n = 14 the following applies:
n ! = 87178291200, lcm (2, . . . , 14) = 360360, and n# = 30030.
The first gap of exactly length 14 is [113,127] with g30 = 14.
Gaps of lengths 10 and 12 follow after the first occurrence of the gap
of length 14.
• For n = 20 the following applies:
n ! = 2432902008176640000, lcm (2, . . . , 20) = 232792560, and n# =
9699690.
The first gap of exactly length 20 is [887,907] with g154 = 20.
You can get the gap index via SageMath: pari(887).primepi() -->
154.
i i
i i
i i
Table 4.8 shows the prime number gaps for the first prime numbers, whether
the gap is maximal and the values of the functions the factorial, lcm, and primorial
for the respective gap length.
i i
i i
i i
Table 4.8 was completely created with the SageMath script chap04_sample100
.sage (this script is not printed here, but can be downloaded from the CT website).
Table 4.9 shows the maximal prime number gaps for the first prime numbers.
The first six maximum gaps occur after one of the first 30 prime numbers. Column
gi again contains the length n of the gap. The last three columns again show the
values N of the functions factorial, lcm, and primorial mentioned in Section 4.9.6.
After these candidates, at the latest, a gap of this length is to be expected or can be
constructed in this way. The specific gap, its actual length, and its merit value are
output for each candidate.
Table 4.9 has the same content as the website of Jens Kruse Andersen [33].
Table 4.9 was completely created with the SageMath Example 4.7.
Since the entire SageMath Example 4.7 is over 100 lines long, only the file
header is listed here. The entire file is available on the CT server: see https://www
.cryptool.org/en/documentation/ctbook/sagemath.
SageMath Example 4.7: List of First Maximal Prime Gaps with Merits
print ("\n# CHAP04 -- Sage -Script -SAMPLE 110: =========")
# Calculate table with details for the maximal prime gaps (starting with p_1 = 2)
# - plus some candidate gaps starting with N+2 according to three formulas
# - plus the latex code for the table used in the CTB (currently commented out)
i i
i i
i i
Table 4.9 List of First Maximal Prime Gaps with Merits Plus Additional Information
No i gi Gap[] Merit n! candidate lcm candidate n# candidate
ith real gap real gap real gap
prime real len/merit real len/merit real len/merit
1 1 1 [2, 3] 1.443 1 1 1
[2, 3] [2, 3] [2, 3]
1 // 1.443 1 // 1.443 1 // 1.443
2 2 2 [3, 5] 1.820 2 2 2
[3, 5] [3, 5] [3, 5]
2 // 1.820 2 // 1.820 2 // 1.820
3 4 4 [7, 11] 2.056 24 12 6
[23, 29] [13, 17] [7, 11]
6 // 1.914 4 // 1.559 4 // 2.056
4 9 6 [23, 29] 1.914 720 60 30
[719, 727] [61, 67] [31, 37]
8 // 1.216 6 // 1.460 6 // 1.747
5 24 8 [89, 97] 1.782 40320 840 210
[40289, 40343] [839, 853] [211, 223]
54 // 5.092 14 // 2.080 12 // 2.242
6 30 14 [113, 127] 2.961 87178291200 360360 30030
[87178291199, 87178291219] [360337, 360391] [30029, 30047]
20 // 0.7939 54 // 4.220 18 // 1.746
7427466391
i i
i i
i i
Tables 4.10 and 4.11 show the number of primes within different intervals.
A visualization of the number of primes in higher intervals of powers of 10 can
be found in Section 4.14.
i i
i i
i i
Table 4.10 How Many Primes Exist within the First Intervals of Tens, Hundreds,
and Thousands?
Ten-Sized Intervals Hundred-Sized Intervals Thousand-Sized Intervals
Interval Number Interval Number Interval Number
1-10 4 1-100 25 1-1000 168
11-20 4 101-200 21 1001-2000 135
21-30 2 201-300 16 2001-3000 127
31-40 2 301-400 16 3001-4000 120
41-50 3 401-500 17 4001-5000 119
51-60 2 501-600 14 5001-6000 114
61-70 2 601-700 16 6001-7000 117
71-80 3 701-800 14 7001-8000 107
81-90 2 801-900 15 8001-9000 110
91-100 1 901-1000 14 9001-10000 112
Table 4.11 How Many Primes Exist within the First Intervals of Dimensions?
Dimension Interval Number Average Number per 1000
4 1 - 10000 1229 122.90
5 1 - 100000 9592 95.92
6 1 - 1000000 78498 78.50
7 1 - 10000000 664579 66.46
8 1 - 100000000 5761455 57.62
9 1 - 1000000000 50847534 50.85
10 1 - 10000000000 455052512 45.51
Table 4.12 shows the index for a few selected prime numbers. The index in the first
column starts with 1.
It is very easy to calculate the nth prime if the given n is not too big. For exam-
ple, SageMath responds almost instantaneously (30 µsec) to get the billionth prime
with the unrank function. As this function starts indexing from 0 (so the index of
the first prime 2 is 0), we have to reduce the index in SageMath Example 4.8 by 1.
However, to find the trillionth prime number, SageMath did not come back even
after 2 days.
SageMath Example 4.8: Get the nth Prime Number with SageMath
sage: P=Primes (); P.unrank(10^9-1)
22801763489
Does the opposite work too, given a prime p get its index or position? Above,
with Primes().unrank(n) we got a prime p. For example, Primes().unrank(
999) delivers 7919. Now we want something like Primes().ununrank(7919) to
get n = 999, but Primes() doesn’t have such a method. However, there is the
prime counting function prime_pi to determine the number of primes up to a given
number (and this upper number may also be a prime): This n is then the position
of a prime p; that is, to find the n when p is the nth prime. So prime_ pi (7919)
delivers 1000. See SageMath Example 4.9.
i i
i i
i i
Note that with gaps, extremely large prime numbers were discovered at an early
stage. However, for the biggest ones like the Mersenne primes we don’t know their
concrete index number [3, 20].
Special values of the binary and decimal systems like in Table 4.14 can be used to
conclude from a key length in bits to the corresponding decimal number of possible
i i
i i
i i
Table 4.13 Likelihoods and Dimensions from Physics and Everyday Life
Probability that you will be hijacked on your next flight 5.5 · 10−6
Annual probability of being hit by lightning 10−7
Probability of 6 correct numbers in the lottery 7.1 · 10−8
Risk of being hit by a meteorite 1.6 · 10−12
Time until the next ice age (in years) 14000 = (214 )
Time until the sun dies (in years) 109 = (230 )
Age of the earth (in years) 109 = (230 )
Age of the universe (in years) 1010 = (234 )
Number of molecules within one water drop 1020 = (263 )
Number of bacteria living on earth 1030.7 = (2102 )
Number of the earth’s atoms 1051 = (2170 )
Number of the sun’s atoms 1057 = (2190 )
Number of atoms in the universe (without dark material) 1077 = (2265 )
Volume of the universe (in cm 3 ) 1084 = (2280 )
keys and the search effort. This can be done provided that, for example, one million
keys can be tested within one second.
Such tables can easily be generated using computer algebra systems (CAS) as
here with SageMath Example 4.10.
SageMath Example 4.10: Special Values of the Binary and Decimal Systems
print ("\n# CHAP04 -- Sage -Script -SAMPLE 020: =========")
E = [10,40,56,64,80,90,112,128,150,160,192,256,1024,2048,4096]
for e in E:
print( '2^%4d --- ' % e, RR(2^e).n(24) )
i i
i i
i i
primes.
x
P I (x ) ∼
ln x
Note that this formula only gives an approximation of the number of primes
smaller or equal to x. It becomes more exact as the number x increases. In the
following we are using the prime number theorem to examine the distribution of
primes.
In order to understand why the number of primes is growing so rapidly,
although the boundaries of the intervals only differ by the exponent 1. Let’s have a
closer look at both components of the right side of the formula: x and ln x.
i i
i i
i i
the number x itself, the number of primes less or equal to x is small. But still, x
ln x
is an increasing function as you can see in Figure 4.9.
i i
i i
i i
Figure 4.8 Graph of the function ln x (a) up to 100 and (b) up to 1010 .
clear that the number of primes in intervals of higher exponents keeps growing quite
fast.
A table containing the number of primes in some dedicated intervals can be
found in Section 4.10. For example, within the interval [1, 104 ] there are 1229
primes; thereof are in the interval [103 , 104 ] 1229 - 168 = 1061 primes.
More theory about the prime number theorem and the function PI(x) can be
found in Section 4.7.
SageMath Example 4.11 creates the graphs for the three functions x, log(x),
and x/log(x), shown in Figures 4.7 to 4.9. It also calculates values for the bars in
Figure 4.10.
i i
i i
i i
Figure 4.10 Numbers of primes in the interval [1, 10x ] (blue) and in the interval [10x−1 , 10x ] (red)
for different exponents x.
i i
i i
i i
def Display(F,fname):
# parameter 'fname ' should contain no blanks
### The following commands work in Sage CLI for all OS , but not when called from script
# F.show () # Alternative , also working in Sage CLI: F.plot ()
# CLI outputs: 'Launched png viewer for Graphics object consisting of 1 graphics �
� primitive '
# This automatically comes with annotated axes / Achsen sind automatisch beschriftet
### This works from a Sage script under Ubuntu (adapt path and viewer name for other OS)
pngfile ='/tmp/'+fname+'.png '; # print (" pngfile =", pngfile)
F.save(pngfile ,axes=True)
imv = 'feh ' # 'okular ' # 'gwenview ' # 'eog ' ## image viewer to start from the �
� terminal under Linux
# imv = 'open -a preview ' ## image viewer to start from the terminal under macOS
oscommand = imv + pngfile + ' &'; # print (" oscommand =", oscommand)
os.system(oscommand) # With Ubuntu: eog = Eye of GNOME file viewer
## os.system('display /tmp/F.png &') # Alternative: The display command needs 'imagemagick �
� ' to be installed.
return
# Definition of function f(x)=x and plots for the domains 0 to 100 and 0 to 10^10
def f(x):return x
F1=plot(f,(0,100)); Display(F1, "F1") # it doesn 't matter whether range starts from 0 or 1
F2=plot(f,(0,10^10)); Display(F2, "F2")
# Definition of function h(x)=log(x) and plots for the domains 1 to 100 and 1 to 10^10
def h(x): return log(x)
H1=plot(h,(1,100),color ="red"); Display(H1, "H1")
H2=plot(h,(1,10^10),color ="red"); Display(H2, "H2")
i i
i i
i i
sage: P.next(5)
7
sage: P[5]
13
• start — An integer that is the lower bound for integers in the sequence
start, start + 1, start + 2, . . . , end − 1, end.
• end — An integer that is the upper bound for the integers in this sequence.
i i
i i
i i
Since the output of SageMath Example 4.13 has many lines, only the beginning
and the end of the output are listed here.
With the function call at the end of the code sample we compute the values of
f (n ) = n 2 − 9n +61 for n = 0, 1, 2, . . . , 50 and verify the primality of the generated
integers.
The last two lines of the output contain a small statistics. You can see that f (n )
generates 48 primes when 0 ≤ n ≤ 50, which is approximately 94% of the values
generated by f (n ).
A modification of this code is in SageMath Example 4.14: There, the function
values of other functions f (n ) are checked for their primality.
For larger sequences, it is impractical to print all single messages indicating the
primality of integers. Therefore, SageMath Example 4.14 sets the verbose param-
eter of the function to False. So only the statistics at the end are printed: the
i i
i i
i i
Punique = len(set(a_list))
a_range = end - start + 1
print (" Number of primes in f(n): %d in n-range (%d, %d) [n takes %d diff. values as both �
� borders are included ]" % (P, start ,end , end -start+1))
print (" Number of unique primes: %d in the list of found primes (%d)" % (Punique , len(a_list)) �
�)
print (" Percentage of primes: %.2f" % float ((P * 100) / a_range))
print (" Percentage of unique primes: %.2f" % float (( Punique * 100) / a_range))
if Pneg > 0:
if countNegativePrimeToo:
print (" Number of negative primes found: %d. These are counted as primes ." % Pneg)
else:
print (" Number of negative primes found: %d. These are not counted as primes ." % Pneg)
i i
i i
i i
#------------------------------------
# CHAP04 -- Sage -Script -SAMPLE 050: =========
# N -- N^2 - 79*N + 1601 .........
# Number of primes in f(n): 602 in n-range (0, 1000) [n takes 1001 diff. values as both borders �
� are included]
# Number of unique primes: 562 in the list of found primes (602)
# Percentage of primes: 60.14
# Percentage of unique primes: 56.14
References
i i
i i
i i
[22] Tietze, H., Gelöste und ungelöste mathematische Probleme, Sixth Edition, C.H. Beck,
1973.
[23] Tervooren, M., FactorDB, http://factordb.com/.
[24] Alpern, D., Alpertron, the Integer Factorization Calculator, https://www.alpertron.com.ar/
ecm.htm.
[25] Andersen, J. K., Primes in Arithmetic Progression Records, http://primerecords.dk/aprec
ords.htm.
[26] Andersen, J. K., and N. Luh, Primes in Arithmetic Progression Records, https://www.pzk-
tupel.de/JensKruseAndersen/aprecords.php.
[27] Klee, V., and S. Wagon, Ungelöste Probleme in der Zahlentheorie und der Geometrie der
Ebene, Birkhäuser Verlag, 1997.
[28] Tao, T., Every Odd Number Greater Than 1 is the Sum of at Most Five Primes, 2012,
https://arxiv.org/abs/1201.6656.
[29] Helfgott, H. A., and D. J. Platt, Numerical Verification of the Ternary Goldbach Conjecture
Up to 8.875e30, 2014, https://arxiv.org/abs/1305.3062.
[30] Chen, J., On the Representation of a Larger Even Integer as the Sum of a Prime and the
Product of at Most Two Primes, in The Goldbach Conjecture (Y. Wang, ed.), Singapore:
World Scientific, 2002.
[31] Nicely, T. R., “New Maximal Prime Gaps and First Occurrences,” Mathematics of
Computation, Vol. 68, No. 227, 1999, pp. 1311–1315, https://www.ams.org/jour-
nals/mcom/1999-68-227/S0025-5718-99-01065-0/S0025-5718-99-01065-0.pdf, and
https://faculty.lynchburg.edu/∼nicely/gaps/gaps.html.
[32] Kourbatov, A., and M. Wolf, “On the First Occurrences of Gaps Between Primes in
a Residue Class,” Journal of Integer Sequences, Vol. 23, 2020, https://arxiv.org/abs/
2002.02115.
[33] Kruse Andersen, J., Maximal Prime Gaps, http://primerecords.dk/primegaps/maxi-
mal.htm.
[34] Caldwell, C., Prime Number Listening Guide, https://t5k.org/programs/music/listen/.
[35] Schwenk, J., “Conditional Access,” in taschenbuch der telekom praxis, B. Seiler (ed.),
1996.
[36] Schneier, B., Applied Cryptography, Protocols, Algorithms, and Source Code in C, Second
Edition, Wiley, 1996.
i i
i i
i i
i i
i i
i i
CHAPTER 5
CHAPTER 5
Introduction to Elementary Number
Theory with Examples
• Group theory;
• Combination theory;
• Complexity theory;
• Stochastic (ergodic theory);
• Information theory.
Number theory or arithmetic (the emphasis here is more on the aspect of per-
forming calculations with numbers) was established by Carl Friedrich Gauss as a
special mathematical discipline. Its elementary features include the greatest com-
mon divisor (gcd), congruences (remainder classes), factorization, the Euler-Fermat
theorem, and primitive roots. However, the most important aspect is prime numbers
and their multiplicative operation.
For a long time, number theory was considered to be the epitome of pure
research, the ideal example of research in the ivory tower. It delved into the
195
i i
i i
i i
i i
i i
i i
All the different areas are concerned with questions regarding integers (both
positive and negative whole numbers plus zero). However, they each have different
methods to deal with them.
This chapter mainly deals with the area of elementary number theory.
Often instead of Zn the notation Z/nZ is used. However, we use the first nota-
tion here, as it is easier to write and as there is no danger of confusion with the
i i
i i
i i
so-called p-adic numbers Z p for n = p. The * representation also exists for integers
(that is, compound n and not only prime p), see Definition 5.9.
The following list shows the SageMath commands to call the three impor-
tant structures Z, Zn , and Z∗n – these commands are applied in the SageMath
Example 5.1:
• Z: IntegerRing() or ZZ
• Zn : Integers(n) or Zmod(n) or IntegerModRing(n)
• Z∗n : [a for a in Integers(n) if gcd(a,n) == 1] or
Zmod(n).list_of_elements_of_multiplicative_group() or Zmod(n).
unit_group()
n = 10 # n = 17
print("- n: ", n, " type(n): ", type(n))
R3 = Zmod(n)
i i
i i
i i
5.3 Prime Numbers and the First Fundamental Theorem of Elementary Number Theory 199
R4 = IntegerModRing(n)
print("- R4 = IntegerModRing(n): ", R4)
print (" list(R4): ", list(R4))
print (" R4.order (): ", R4.order ())
G3 = R3.unit_group ()
print("- G3 (via Zmod.unit_group): ", G3)
print (" list(G3): ", list(G3))
print (" G3.order (): ", G3.order ())
Many of the problems in elementary number theory are concerned with prime
numbers (see Chapter 4).
Every integer has divisors or factors. The number 1 has just one—itself, whereas
the number 12 has the six factors 1, 2, 3, 4, 6, and 12.
The SageMath method divisors() gives a list of all divisors of a number n.
For instance of n = 12 in the SageMath Example 5.2.
i i
i i
i i
SageMath Example 5.2: Edit all Divisors of an Integer a and the Number of
Divisors τ (a )
sage: a=12; a.divisors (); number_of_divisors(a)
[1, 2, 3, 4, 6, 12]
6
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
71, 73, 79, 83, 89, 97, · · ·
The first 100 numbers include precisely 25 prime numbers. After this, the
percentage of primes decreases, but never reaches zero. See Tables 4.10 and 4.11.
We come across integers that are prime fairly often. In the last decade of the
20th century, only three years were prime: 1993, 1997, and 1999. If they were rare,
cryptography would not be able to work with them to the extent it does.
Prime numbers can be factorized in a unique (trivial) way:
5=1·5
17 = 1 · 17
1013 = 1 · 1013
1296409 = 1 · 1296409
Definition 5.2 Natural numbers greater than 1 that are not prime are called
composite numbers. These have at least two factors other than 1.
The dissection of a number into its prime factors is called (complete) factor-
ization. Examples of the unique decomposition of composite numbers into prime
factors:
4=2·2
6=2·3
91 = 7 · 13
161 = 7 · 23
767 = 13 · 59
1029 = 3 · 73
5324 = 22 · 113
i i
i i
i i
Theorem 5.1 Each composite number a has a lowest factor greater than 1. This
factor is a prime number p and is less than or equal to the square root of a.
All integers greater than 1 can be expressed as a product of prime numbers—in
a unique way.
This is the claim of the first fundamental theorem of number theory (= funda-
mental theorem of arithmetic = fundamental building block of all positive integers).
It was formulated precisely for the first time by Carl Friedrich Gauss in his
Disquisitiones Arithmeticae (1801).
Theorem 5.2 Gauss 1801 Every even natural number greater than 1 can be written
as the product of prime numbers. Given two such decompositions a = p1 · p2 · . . . ·
pn = q1 · q2 · . . . · qm , these can be resorted such that n = m and for all i, pi = qi .
In other words, each natural number other than 1 can be written as a product
of prime numbers in precisely one way (if we ignore the order of the factors). The
factors are therefore unique (the expression as a product of factors is unique).
For example, 60 = 2 · 2 · 3 · 5 = 22 · 3 · 5. And this—other than changing the
order of the factors—is the only way in which the number 60 can be factorized.
If you allow numbers other than primes as factors, there are several ways of
factorizing integers and the uniqueness is lost:
60 = 1 · 60 = 2 · 30 = 4 · 15 = 5 · 12 = 6 · 10 = 2 · 3 · 10 = 2 · 5 · 6 = 3 · 4 · 5 = · · ·
In mathematics one also studies sets of numbers where the factorization into
primes (or objects that have prime properties inside those sets) is not unique. An
example for this (see Theorem 4.2) and further details on prime numbers (e.g., how
Fermat’s little theorem can be used to test extremely large numbers to determine
whether they are prime) can be found in Chapter 4 of this book.
5.4.1 Divisibility
If integers are added, subtracted, or multiplied, the result is always another integer.
However, the division of two integers does not always result in an integer. For
example, if we divide 158 by 10 the result is the decimal number 15.8, which is not
an integer.
If, however, we divide 158 by 2 the result 79 is an integer. In number theory we
express this by saying that 158 is divisible by 2 but not by 10. In general, we say:
Definition 5.3 An integer n is divisible by another integer d if the quotient n /d is
an integer c such that n = c · d.
In other words: An integer d divides an integer n, if n = c · d for some c ∈ Z.
n is called a multiple of d, whereas d is called a divisor or factor of n.
i i
i i
i i
The mathematical notation for this is d|n (read “d divides n”). The notation
d6 |n means that d does not divide the number n. It is:
[ d | n ] ⇔ [ n is a multiple of d ]
Two further important definitions are those of the greatest common divisor
(gcd) and the least common multiple (lcm) of two integers.
Definition 5.4 The gcd (a, b) is the largest integer dividing both a and b.
Definition 5.5 The lcm (a, b) is the smallest positive integer divisible by both a
and b.
Two numbers are called relatively prime or coprime, if their greatest common
divisor equals 1. For example, 9 = 3 · 3 and 28 = 2 · 2 · 7 are coprime. The following
equivalence holds:
i i
i i
i i
Example:
2, 3, 6 are relatively prime, because gcd(2, 3, 6) = 1. They are not pairwise relatively
prime because gcd(2, 6) = 2 > 1.
As with the divisors, the integers coprime to a given integer a can also be cal-
culated. There are different ways to do so in SageMath. The direct way is to use
the method coprime_integers(). It requires an argument up to that the coprimes
are calculated. Giving a as argument ensures to look only within {1, . . . , a − 1}. See
SageMath Example 5.5.
Another way is to build the ring of integers modulo a, then list the multiplicative
group of that ring. As this returns Python integers and we want Sage integers, we
can convert them to SageMath integers via ZZ.
i i
i i
i i
Example:
19 5
=2+ (m = 7, c = 2, r = 5)
7 7
What do the numbers 5, 12, 19, 26, · · · have in common for division by 7? The
remainder is always r = 5.
Dividing arbitrary integers by 7, only the following remainders are possible:
r = 0, 1, 2, · · · , 6
Example:
19 ≡ 12 (mod 7), because the remainders are equal: 19/7 = 2 remainder 5 and
12/7 = 1 remainder 5.
23103 ≡ 0 (mod 453), because 23103/453 = 51 remainder 0 and 0/453 = 0
remainder 0.
Theorem 5.3 a ≡ b (mod m) if and only if the difference (a − b) is divisible by m;
that is, if q ∈ Z exists with (a − b) = q · m.
In other words: a ≡ b (mod m ) ⇐⇒ m|(a − b) ⇐⇒ (a − b) ≡ 0
(mod m ).
i i
i i
i i
We can apply the equivalence in Theorem 5.3 if we need a quick and easy
method for determining whether large numbers are divisible by a certain number.
Example: Is 69993 divisible by 7?
The number can be written in the form of a difference in which it is clear that each
operand is divisible by 7: 69993 = 70000 − 7. Therefore, the difference is also
divisible by 7.
Although these considerations and definitions may seem to be rather theoret-
ical, we are so familiar with them in everyday life that we no longer think about
i i
i i
i i
the formal procedure. For example, the 24 hours on a clock are represented by
the numbers 1, 2, · · · , 12. We obtain the hours after 12 noon as the remainder of a
division by 12 and know immediately that 2 o’clock in the afternoon is the same as
14:00.
The modular arithmetic (based on division remainders) forms the basis of asym-
metric encryption procedures. Cryptographic calculations are therefore not based
on real numbers like the calculations mostly performed at school, but rather on
number sets with a limited length (finite sets), like on positive integers that cannot
exceed a certain value.
So we choose a large number m and calculate modulo m. That is, we ignore
integer multiples of m and, rather than working with a number, we only work with
the remainder when this number is divided by m. The result is that all results are in
the range 0 to m − 1.
Since m is really large in practice, the set is also significantly larger than in our
examples and cannot be completely stored in the computer’s memory. But it has the
advantages and properties of modular computing.
1. Associative law
((a + b) + c) (mod m ) ≡ (a + (b + c)) (mod m )
((a · b) · c) (mod m ) ≡ (a · (b · c)) (mod m )
2. Commutative law
(a + b) (mod m ) ≡ (b + a ) (mod m )
(a · b) (mod m ) ≡ (b · a ) (mod m )
The associative law and the commutative law apply to both addition and
multiplication.
3. Distributive law
(a · (b + c)) (mod m ) ≡ (a · b + a · c) (mod m )
4. Reducibility
(a + b) (mod m ) ≡ (a (mod m ) + b (mod m )) (mod m )
(a · b) (mod m ) ≡ (a (mod m ) · b (mod m )) (mod m )
When adding or multiplying the order in which the modulo operation is
performed does not matter.
i i
i i
i i
If k −1 does not exist, the term x : k is not defined. See also Table 5.3.
• For two natural numbers a and m, a mod m denotes the remainder obtained
when we divide a by m. This means that a (mod m ) is always a number
between 0 and m − 1.
• For example, 1 ≡ 6 ≡ 41 (mod 5) because the remainder is always 1.
Another example is: 2000 ≡ 0 (mod 4) because 4 divides 2000 with no
remainder.
i i
i i
i i
16 − 5 = 11; 11 − 5 = 6; 6 − 5 = 1
4 + 1 = 5 ≡ 0 (mod 5);
4 · 4 = 16 ≡ 1 (mod 5).
i i
i i
i i
Example:
In the set Z5 = {0, 1, 2, 3, 4} for the addition, and in the set Z∗5 = Z5 \ {0} for
the multiplication, all numbers have a unique inverse modulo 5.
In the case of modular addition, this is true for every integer used as modulus
(not just for 5).
However, this is not the case for modular multiplication (important theorem):
Theorem 5.4 A natural number a from the set {1, · · · , m − 1} has one modular
multiplicative inverse if and only if this number and the modulus m are coprime, in
other words if a and m have no common prime factors.
i i
i i
i i
The number of numbers that are relatively prime to the modulus m is the same
as the number of numbers that have a multiplicative inverse (see the Euler function
φ (m ) in Section 5.8.2).
For the two moduli 5 and 6 used in the multiplication tables, this means the
modulus 5 is a prime number itself. In mod 5, therefore, there are exactly φ (5) =
5 − 1 = 4 numbers that are relatively prime to the modulus, which is all numbers
from 1 to 4.
Since 6 is not a prime number, we write it as a product of its factors: 6 = 2 · 3.
In mod 6, therefore, there are exactly φ (6) = (2 − 1) · (3 − 1) = 1 · 2 = 2 numbers
that have a multiplicative inverse; that is 1 and 5.
Although it may seem difficult to calculate the table of multiplicative inverses
for large moduli, we can use Fermat’s little theorem to create a simple algorithm
for this [6, p. 80]. Quicker algorithms are described, for instance, in [7].
Cryptographically not only the unique nature of the inverse is important, but
also that the set of possible values has been exhausted.
We need to find the i for which the product remainder a · i modulo 17 with
a = 5 or a = 6 has the value 1 (i.e., i is the multiplicative inverse of a (mod 17)).
Between i = 1, . . . , m all values between 0, . . . , m − 1 occur for the remainders,
because both 5 and 6 are also relatively prime to the modulus m = 17.
The multiplicative inverse of 5 (mod 17) is 7, while the inverse of 6 (mod 17)
is 3.
Table 5.5 (multiplication table mod 13) calculates the remainders of the
products 5 · i and 6 · i.
Between i = 1, . . . , m, all values between 0, . . . , m − 1 occur for the remainders,
because both 5 and 6 are relatively prime to the modulus m = 13.
Table 5.4 Multiplication Table Modulo 17 for a = 5 and a = 6 Generated with SageMath Example 5.15
i⇒ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
5·i 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90
remainder 5 10 15 3 8 13 1 6 11 16 4 9 14 2 7 12 0 5
6·i 6 12 18 24 30 36 42 48 54 60 66 72 78 84 90 96 102 108
remainder 6 12 1 7 13 2 8 14 3 9 15 4 10 16 5 11 0 6
i i
i i
i i
The multiplicative inverse of 5 (mod 13) is 8, while the inverse of 6 (mod 13)
is 11.
Table 5.6 contains an example where the modulus m and the number a = 6 are
not relatively prime.
We calculated 5 · i (mod 12) and 6 · i (mod 12). Between i = 1, . . . , m, not all
values between 0, . . . , m − 1 occur and 6 does not have an inverse mod 12, because
6 and the modulus m = 12 are not coprime.
The multiplicative inverse of 5 (mod 12) is 5. The number 6 has no inverse
(mod 12).
a b+c = a b · a c
(a b )c = a b·c = a c·b = (a c )b
Modular powers work in the same way as modular addition and modular
multiplication:
32 = 9 ≡ 4 (mod 5)
i i
i i
i i
≡ 42 (mod 5)
≡ 16 ≡ 1 (mod 5)
This delivers the correct result for m = 5, but there are cases where it can’t
be done like that. For example if m = 12 we have φ (m ) = 4. The element 2
divides m, and if we calculate the 9th power, we get 29 (mod 12) = 8, but
(mod φ (12)) (mod 4)
29 = 29 = 21 = 2 6= 8.
This is a consequence of the theorem of Euler and Fermat (see Theorem 5.13).
Assume bc = r + kφ (m ) with r < m and r, k ∈ N0 , then
a bc = a r · a k·φ (m ) = a r · ( a| φ{z
(m ) k
} ) ≡a
r
(mod m ).
≡1(mod m )
Example 2:
(mod 10)
328 = 34 · 7 ≡ 34 · 7 ≡ 38 ≡ 6561 ≡ 5 (mod 11)
i i
i i
i i
We can generalize this by representing the exponent as a binary number. For exam-
ple, the naive method would require 36 multiplications in order to calculate a n for
n = 37. However, if we write n in the binary representation as 100101 = 1 · 25 + 1 ·
5 2 0 5 2
22 + 1 · 20 , then we can rewrite the expression as: a 37 = a 2 +2 +2 = a 2 · a 2 · a 1 .
i i
i i
i i
case, it now only needs to multiply those (a 2 )k for which there is a one in the kth
position of the binary representation of n. The typical effort is then reduced from
2600 to 2 · 600 multiplications! This frequently used algorithm is called square and
multiply.
SageMath Example 5.8 contains source code implementing the square-and-
multiply method in SageMath manually. It outputs the intermediate results, so you
can reproduce the calculations above. See also Section 5.17.2 for a sample using
the function power_mod built in SageMath.
i i
i i
i i
i i
i i
i i
then the set Zn together with the relation mod+ is a group because the following
properties of a group are valid for all elements in Zn :
a mod* b := (a · b) (mod n ),
then Zn together with this operation is usually not a group because not all properties
are fulfilled for each n.
Example:
a. In Z15 , for example, the element 5 does not have an inverse. That is to say,
there is no a with 5 · a ≡ 1 (mod 15). Each modulo product with 5 on this
set gives 5, 10, or 0.
b. In Z55 \ {0}, for example, the elements 5 and 11 do not have multiplicative
inverses. That is to say, there is no a ∈ Z55 such that 5 · a ≡ 1 (mod 55) and
no a such that 11·a ≡ 1 (mod 55). This is because 5 and 11 are not relatively
prime to 55. Each modulo product with 5 on this set gives 5, 10, 15, . . . , 50
or 0. Each modulo product with 11 on this set gives 11, 22, 33, 44, or 0.
On the other hand, there are subsets of Zn that form a group with the operation
mod*. If we choose all elements in Zn that are relatively prime to n, then this set
forms a group with the operation mod*. We call this set Z∗n .
SageMath Example 5.7 calculates the residue set R 0 and the Euler φ function
of n = 10.
i i
i i
i i
Comment:
R 0 or Z∗n is always a genuine subset of R or Zn because 0 is always an element of R
but never an element of R 0 . Since 1 and n − 1 are always relatively prime to n, they
are always elements of both sets.
If we select a random element in Z∗n and multiply it by every other element in
Zn , then the products are all in Z∗n . This is due to the fact that Z∗n is closed with
∗
3 ≡ 3 · 1 (mod 10)
9 ≡ 3 · 3 (mod 10)
1 ≡ 3 · 7 (mod 10)
7 ≡ 3 · 9 (mod 10)
Euler’s phi function is an important function in number theory. Likewise, the Euler-
Fermat theorem is of great importance for RSA.
i i
i i
i i
a fixpoint). Compare the multiplicative order in Section 5.9 and the RSA fixed
points in Section 5.17.7.
φ ( p · q ) = ( p − 1) · (q − 1) or φ ( p · q ) = φ ( p ) · φ (q ).
Theorem 5.11 In general, the following is true for every prime number p and every
n in N:
1. φ ( p n ) = p n−1 · ( p − 1).
2. If n = p1e1 · p2e2 · . . . · pkek , where p1 to pk are distinct prime numbers, then:
φ (n ) = [( p1e1 −1 )·( p1 −1)]·. . .·[( pkek −1 )·( pk −1)] = n·([( p1 −1)/ p1 ]·. . .·[( pk −1)/ pk ]).
Example:
• n = 70 = 2 · 5 · 7 ⇒ using Theorem 5.10: φ (n ) = 1 · 4 · 6 = 24.
• n = 9 = 32 ⇒ using Theorem 5.11: φ (n ) = 31 · 2 = 6, because Z∗9 =
{1, 2, 4, 5, 7, 8}.
• n = 2701125 = 32 · 53 · 74 ⇒ using Theorem 5.11:
i i
i i
i i
numbers. In Figure 5.1 the phi function is highlighted for the number 24.
Navigate to there in CT2 from CT2 Crypto Tutorials F World of Primes F
Distribution of primes F Number line.
ap ≡ a (mod p)
a p−1 ≡ 1 (mod p )
i i
i i
i i
Because if a and p are relatively prime (or coprime), an inverse a −1 (mod p ) always
exists. Multiply the first congruence with a −1 (mod p ) from the left as well as from
the right and the second congruence follows.
See also Section 4.5. Theorem 4.5 corresponds to Theorem 5.12 here.
Theorem 5.13 Euler-Fermat theorem (generalization of fermat’s little theorem) For
all elements a in the group Z∗n (i.e., a and n are natural numbers that are coprime):
a φ (n ) ≡ 1 (mod n )
This theorem states that if we raise a group element (here a) to the power
of the order of the group (here φ (n )), we always obtain the neutral element for
multiplication (the number 1).
See for example [8, S. 94 ff] in the literature for a proof of this theorem.
The second formulation of Fermat’s little theorem is derived directly from
Euler’s theorem if n is a prime number.
If n is not a prime number, then in most cases there do not exist primitive roots
modulo n and the exponent φ (n ) in Theorem 5.13 is not sharp; that is, can be
replaced by a proper divisor of φ (n ). The following formulation of the theorem is
taken from an unpublished handout of Professor Geyer; see [9]. Alternatively this
can be found in the famous classic of Hardy and Wright [10], on page 63 ff. There
you can also find the proofs.
Theorem 5.14 Sharper Euler-Fermat theorem Let n not be divisible by 8 and not
of the form 2u with u ≡ 1 mod 2.
1. If n = pr is a prime power, then there does exist a primitive root modulo n
with order φ (n ) = pr −1 ( p − 1) and the exponent φ (n ) in 5.13 can not be
replaced by a smaller one.
2. If n is not a prime power (and not a prime), then there exists no primitive
root modulo n of order φ (n ). If
a (n ) ≡ 1 mod n
for a, n coprime.
Remarks:
1. For numbers divisible by 8, (n ) must be divided by 2 for getting the best
exponent because a 2 ≡ 1 mod 8 for all odd a.
i i
i i
i i
2. The condition that the number n is not of the form 2u is needed because for
∼ Z∗ .
n = 2u with odd u we have Z∗2u = u
3. The SageMath Example 5.28 shows how such an element of maximal order
can be constructed.
Example:
Find the multiplicative inverse of 1579 modulo 7351.
According to Euler-Fermat: a φ (n ) = 1 (mod n ) for all a in Z∗n . If we divide both
sides by a, we get: a φ (n )−1 ≡ a −1 (mod n ). For the special case that the modulus is
prime, we have φ (n ) = p − 1. Therefore, the modular inverse is
By cleverly breaking down the exponent, we can calculate this power relatively easy
(see Section 5.6.4):
i i
i i
i i
print ("\ nSecond , calculate power a^e manually via square & multiply :")
b = ZZ(e).bits (); print ("b:", b, " len(b):", len(b), " e:", e); # b=b[::-1]; print(b);
i i
i i
i i
SageMath Example 5.9 considered the case for n = 26. With SageMath
Example 5.34 you can consider the general case, where n can be any integer. See
Section 5.17.6. The SageMath program delivers the number of all values d.
For all e that are coprime φ (n ) we can calculate d as follows using the Euler-
Fermat theorem:
d ≡ e−1 (mod φ (n ))
≡ eφ (φ (n ))−1 (mod φ (n )),
because a φ (n ) ≡ 1 (mod n ) matches a φ (n )−1 ≡ a −1 (mod n )
i i
i i
i i
The multiplicative order (see Definition 5.10) and the primitive root are two useful
constructs (concepts) in elementary number theory.
Mathematicians often ask under which conditions the repeated application of
an operation results in the neutral element (compare Section 5.8.1).
For the i-times successive modular multiplication of a number a by itself there
is an i from {1, . . . , m − 1} where the power a i (mod m ) is the neutral element of
the multiplication if and only if a and m are relatively prime.
Example 1:
Table 5.7 shows the values a i mod 11 for the exponents i = 1, 2, . . . , 10, and for
the bases a = 1, 2, . . . , 10 as well as the resulting value or d11 (a ) for each a.
Table 5.7 also shows, for example, that the order of 3 modulo 11 has the value
5. SageMath Example 5.17 contains the source code to generate the entries. See
Section 5.17.3.
In a multiplicative group (here Z∗11 ) not all numbers necessarily have the same
order. The different orders in this case are 1, 2, 5, and 10, and we notice that:
Table 5.7 Values of a i (mod 11), 1 ≤ a, i < 11 and Corresponding Order of a (mod 11)
i=1 i=2 i=3 i=4 i=5 i=6 i=7 i=8 i=9 i=10 or d11 (a )
a=1 1 1 1 1 1 1 1 1 1 1 1
a=2 2 4 8 5 10 9 7 3 6 1 10
a=3 3 9 5 4 1 3 9 5 4 1 5
a=4 4 5 9 3 1 4 5 9 3 1 5
a=5 5 3 4 9 1 5 3 4 9 1 5
a=6 6 3 7 9 10 5 8 4 2 1 10
a=7 7 5 2 3 10 4 6 9 8 1 10
a=8 8 9 6 4 10 3 2 5 7 1 10
a=9 9 4 3 5 1 9 4 3 5 1 5
a=10 10 1 10 1 10 1 10 1 10 1 2
i i
i i
i i
i i
i i
i i
Table 5.8 Values of a i (mod 45), 1 ≤ a, i < 13 and Corresponding Order of a (mod 45)
a\i 1 2 3 4 5 6 7 8 9 10 11 12 or d45 (a ) φ (45)
1 1 1 1 1 1 1 1 1 1 1 1 1 1 24
2 2 4 8 16 32 19 38 31 17 34 23 1 12 24
3 3 9 27 36 18 9 27 36 18 9 27 36 — 24
4 4 16 19 31 34 1 4 16 19 31 34 1 6 24
5 5 25 35 40 20 10 5 25 35 40 20 10 — 24
6 6 36 36 36 36 36 36 36 36 36 36 36 — 24
7 7 4 28 16 22 19 43 31 37 34 13 1 12 24
8 8 19 17 1 8 19 17 1 8 19 17 1 4 24
9 9 36 9 36 9 36 9 36 9 36 9 36 — 24
10 10 10 10 10 10 10 10 10 10 10 10 10 — 24
11 11 31 26 16 41 1 11 31 26 16 41 1 6 24
12 12 9 18 36 27 9 18 36 27 9 18 36 — 24
Table 5.9 Values of a i (mod 46), 1 ≤ a, i < 24 and Corresponding Order of a (mod 46)
a\i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ord
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 4 8 16 32 18 36 26 6 12 24 2 4 8 16 32 18 36 26 6 12 24 2 –
3 3 9 27 35 13 39 25 29 41 31 1 3 9 27 35 13 39 25 29 41 31 1 3 11
4 4 16 18 26 12 2 8 32 36 6 24 4 16 18 26 12 2 8 32 36 6 24 4 –
5 5 25 33 27 43 31 17 39 11 9 45 41 21 13 19 3 15 29 7 35 37 1 5 22
6 6 36 32 8 2 12 26 18 16 4 24 6 36 32 8 2 12 26 18 16 4 24 6 –
7 7 3 21 9 17 27 5 35 15 13 45 39 43 25 37 29 19 41 11 31 33 1 7 22
8 8 18 6 2 16 36 12 4 32 26 24 8 18 6 2 16 36 12 4 32 26 24 8 –
9 9 35 39 29 31 3 27 13 25 41 1 9 35 39 29 31 3 27 13 25 41 1 9 11
10 10 8 34 18 42 6 14 2 20 16 22 36 38 12 28 4 40 32 44 26 30 24 10 –
11 11 29 43 13 5 9 7 31 19 25 45 35 17 3 33 41 37 39 15 27 21 1 11 22
12 12 6 26 36 18 32 16 8 4 2 24 12 6 26 36 18 32 16 8 4 2 24 12 –
13 13 31 35 41 27 29 9 25 3 39 1 13 31 35 41 27 29 9 25 3 39 1 13 11
14 14 12 30 6 38 26 42 36 44 18 22 32 34 16 40 8 20 4 10 2 28 24 14 –
15 15 41 17 25 7 13 11 27 37 3 45 31 5 29 21 39 33 35 19 9 43 1 15 22
16 16 26 2 32 6 4 18 12 8 36 24 16 26 2 32 6 4 18 12 8 36 24 16 –
17 17 13 37 31 21 35 43 41 7 27 45 29 33 9 15 25 11 3 5 39 19 1 17 22
18 18 2 36 4 26 8 6 16 12 32 24 18 2 36 4 26 8 6 16 12 32 24 18 –
19 19 39 5 3 11 25 15 9 33 29 45 27 7 41 43 35 21 31 37 13 17 1 19 22
20 20 32 42 12 10 16 44 6 28 8 22 26 14 4 34 36 30 2 40 18 38 24 20 –
21 21 27 15 39 37 41 33 3 17 35 45 25 19 31 7 9 5 13 43 29 11 1 21 22
22 22 24 22 24 22 24 22 24 22 24 22 24 22 24 22 24 22 24 22 24 22 24 22 –
23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 23 –
Theorem 5.15 Given a modulus m and a number a, relative prime to m, the fol-
lowing is true:
i i
i i
i i
only if or dm (a ) = φ (m ).
Even for prime moduli p and 0 < a < p, not all a are of order φ ( p ) = p −
1. Compare Table 5.7 as an example. But if or dm (a ) = φ (m ), a i (mod p) goes
through all the values 1, . . . , p − 1. Exhausting all possible values of the set is an
important cryptographic proposition (compare Theorem 5.5). This determines a
permutation π ( p − 1).
Table 5.9 demonstrates that also for composite moduli m not all a are
of maximal order φ (m ). In this example only 5, 7, 11, 15, 17, 19, and 21 are of
order 22.
The left-hand side of Theorem 5.15 holds exactly if a is a primitive root modulo
m (see Definition 5.12).
The multiplicative group Z m ∗ (see Definition 5.9) contains all values from 1 to
• φ (14) = φ (2 · 7) = 1 · 6 = 6
• φ (22) = φ (2 · 11) = 1 · 10 = 10
i i
i i
i i
i i
i i
i i
for every single component of that tuple find a primitive root modulo the
corresponding m i , the modulus of that component. In this manner we
get a tuple of primitive roots—with respect to the moduli m i —for which
by the Chinese remainder theorem there corresponds a unique number
a ∈ {1, . . . , n − 1}. This number then generates a cycle of maximal length
lcm(φ (m 1 ), φ (m 2 ), . . . , φ (m r )) as already mentioned in Theorem 5.14. The
listing 5.29 shows a SageMath example for computing such an element.
b. In some cases the maximum cycle length can be achieved for some values
of a despite no multiplicative order exists for them (then in Tables 5.10
and 5.11 under the column header or dm (a ) there is a “0” instead of a dash
like in Table 5.8).
Samples:
– In Table 5.10: lmax = φ (14) = 6 for a = 10, 12 (cell highlighted in red)
– In Table 5.11: lmax = φ (22) = 10 for a = 2, 6, 8, 18
Both cases are special cases of Theorem 5.14 because 14 and 22 are of the
form 2u with u not only odd but also prime.
SageMath Example 5.20 contains the source code to generate
Tables 5.10 and 5.11—see Section 5.17.3.
The topic of cycles and their lengths is also treated in detail in context with the
RSA plane, where the notions orbit and path is used. See Section 6.5, especially
Sections 6.5.8, 6.5.8.2, and 6.5.8.3.
Using the Euler-Fermat theorem (see Theorem 5.13) we can prove the RSA
procedure in the group Z∗n .
The RSA procedure is the most common asymmetric cryptography procedure.
Developed in 1978 by Ronald Rivest, Adi Shamir, and Leonard Adleman, it can be
used both for signatures and for encryption.
i i
i i
i i
i i
i i
i i
M = D ((n, d ), C ) = C d (mod n )
Remarks:
1. The numbers p, q, n chosen in step 1 are extremely large in practice (e.g.,
p and q have 1000 bit each, n 2000 bit length).
2. Further security aspects of the implementation and the algorithm itself are
discussed in Sections 5.11 and 5.12.
3. In Section 6.5 the RSA algorithm is more deeply reasoned from number
theory: The RSA plane is a model to illustrate the processes in this algorithm
using pictures of rectangles.
4. Compaq introduced the multiprime method with high marketing effort in
2000. n was not the product of two primes, but of three: of two big ones
and one relative small prime: n = o · p · q. With Theorem 5.10 we get:
φ (n ) = (o − 1) · ( p − 1) · (q − 1). This method did not assert itself.
One reason probably was that Compaq claimed a patent on it. Gene-
rally there is less understanding in Europe and within the open-source
community that one can claim patents on algorithms. But there is really
no understanding outside the United States, that one can get a patent for
a special case (3 instead of 2 factors) of an algorithm (RSA), although the
patent for the general case was almost expired.1
5. If the two primes p and q are equal then (m e )d ≡ m mod n is not true for
all m < n (although e · d ≡ 1 mod φ (n ) is fulfilled).
Example: If n = 52 then according to Theorem 5.11, it is φ (n ) = 5 · 4 =
20, e = 3, d = 7, e · d = 21 ≡ 1 mod φ (n ).
But it is (53 )7 ≡ 0 mod 25. Therefore, p and q must be different.
6. The BSI (German Information Security Agency) recommends to choose the
prime factors p and q almost the same, but not too close:
They recommend generating the primes independently and check that the
restriction is fulfilled (see [12]).
1. The multiprime RSA method is contained in JCT Default Perspective F Visuals as well as in the JCT
Algorithm Perspective.
i i
i i
i i
7. For reasons of security, the selected e should not be too small. Since φ (n ) =
( p − 1) · (q − 1) is even and e has to be relatively prime to φ (n ), e cannot be
2. So the smallest value for e is 3 [13, Chap. 7.2.7].
The BSI reference [12] recommends 216 + 1 ≤ 2256 − 1. The procedure
also allows us to select d freely and then calculate e. However, this has
practical disadvantages. We usually want to be able to encrypt messages
quickly, which is why we choose a public exponent e such that it has a short
bit length compared to the modulus n and as few binary ones as possible
(e.g., 216 + 1). So a fast exponentiation is possible when encrypting. The
prime numbers 3, 17, and 65537 have proved to be particularly practical for
this purpose. The most often used number is 65537 = 216 + 1, or in binary:
10 · · · 00 · · · 01 (this number is prime and therefore relatively prime to many
other numbers).
M e·d ≡ M (mod n )
We will show this in three steps using Theorem 5.12 (Fermat’s little theorem)
(according to [3, p. 131ff]).
Step 1:
In the first step we show that: M e·d ≡ M (mod p).
Since n = p · q and φ ( p · q ) = ( p − 1) · (q − 1) and since e and d are selected
in such a way that e · d ≡ 1 (mod φ (n )), there is an integer k such that: e · d =
1 + k · ( p − 1) · (q − 1).
The requirement for using the simplified Euler-Fermat (Theorem 5.12) was that M
and p are relatively prime.
i i
i i
i i
Since this is not true in general, we need to consider the case when M and p
are not relatively prime. Since p is a prime number, this implies that p is a factor of
M. But this means:
M ≡ 0 (mod p ).
M e·d ≡ 0 (mod p ).
Comment 1:
We can also condense the three steps if we use the Theorem 5.13 (Euler-Fermat),
that is, not the simplified theorem where n = p and which corresponds to Fermat’s
little theorem:
Comment 2:
When it comes to signing messages, we perform the same operations but first use
the secret key d (for signing), followed by the public key e (for validation). The RSA
procedure can also be used to create digital signatures because:
M ≡ ( M d )e (mod n ).
i i
i i
i i
Section 5.12 deals with the security of the actual algorithm. On the other hand, this
section is about practical security.
As we have presented RSA2 so far in this chapter, it is also called textbook
RSA; that is, the use of the algorithm itself. RSA is a kind of monoalphabetic sub-
stitution (see Section 2.2.1), except that the range of values does not only include
26 characters as in simple classical methods, but 2n values (n is the modulus).
In general, you can avoid the practical problems and many (simple) attacks by
always padding with additional and random data before encrypting the message
with RSA. This reduces the range of values for the message. It is recommended to
use, for example, the cryptographic padding method Optimal Asymmetric Encryp-
tion Padding (OAEP). OAEP is also defined in the standard PKCS#1 (version 2.2,
2012-10-27) and in RFC 8017. So a component of randomness is added to the deter-
ministic RSA algorithm. One of the modern characteristics of a secure encryption
system is that it is indistinguishable. There are two particular types of indistin-
guishability that are of importance: IND-CPA (indistinguishability under a chosen
plaintext attack), and IND-CCA (indistinguishability under a chosen ciphertext
attack). We will not go into the theoretical details here, but just state the results
for RSA under reasonable assumptions: Textbook RSA cannot be IND-CPA secure
(even less it is IND-CCA secure). RSA with OAEP on the other hand is CCA secure
in the random oracle model. More details can be found in [14] and Section 1.8.2.
Figure 5.2 shows a screenshot from CTO: In the GUI, a selection is made to
encrypt a text with RSA. The RSA public key comes from the file “my_rsa.pub”
and by default the called OpenSSL implementation uses OAEP for padding. The
internally used OpenSSL command (openssl pkeyutl -encrypt -pubin -inkey
my_rsa.pub -hexdump) is displayed in the console window (below the “Execute”
button).
The first part of this section follows the article “Vorzüge und Grenzen des RSA-
Verfahrens” written by F. Bourseau, D. Fox, and C. Thiel [15].
i i
i i
i i
Figure 5.2 CrypTool-Online: Encryption with OpenSSL (using padding via OAEP).
i i
i i
i i
• The adequate usage of the algorithm and key generation (here the choice of
p, q, e, d);
• The correct implementation of the algorithm.
Usage and key generation are well understood today. The actual implementation
based on long integer arithmetic is very easy.
The following two sections examine the RSA algorithm with respect to the first
two points.
5.12.1 Complexity
The security of the RSA algorithm depends—as with all public-key methods—on
the difficulty to calculate the private key (here d) from the public key (n, e).
Especially for the RSA method this means:
1. It is hard to calculate φ (n ) for big compounds n;
2. It is hard to calculate the prime factors of big compounds n (integer
factorization problem IFP).
There is no reason for the concern sometimes mentioned that there are not
enough primes: Raising the dimension of the modulus always offers enough
primes to consider. This is visualized in Section 4.14.
Successful decryption or forgery of a signature—without knowing the private
key—therefore requires calculating the eth root mod n. The private key, which is
the multiplicative inverse of e mod φ (n ), then can be easily determined if φ (n ) is
known. φ (n ) again can be calculated from the prime factors of n. Breaking of RSA
therefore cannot be more difficult than factorization of the modulus n.
The inverse proposition that the RSA algorithm can be broken only by factor-
ization of n is still not proven. Most number theorists consider the RSA problem
and the factorization problem equivalent in terms of time complexity.
The best factorization method known today is a further development of the
general number field sieve (GNFS), which was originally devised to factor only
numbers of a special form (like Fermat numbers).
More details about GNFS and its complexity can be found in Section 12.4.
The discussion there shows that the GNFS belongs to the class of problems with
subexponential time complexity (i.e., time complexity grows asymptotically
√
not as
fast as exponential functions like el or 2l , but strictly slower, like e l ).
This classification is current knowledge; it does not preclude the possibility that
the factorization problem can be solved in polynomial time (see Section 5.12.5.1
and Sections 5.10 and 6.3.1).
3. The quadratic sieve (QS) can be found in CT1, CT2, and CTO (see Msieve).
i i
i i
i i
• In 1994 a 129-digit RSA modulus (428 bits), published in 1977, was factor-
ized by a distributed implementation of the quadratic sieve algorithm (QS),
developed 1982 by Pomerance. This effort took 8 months. Please refer to
[16].
• In 1999 a 155-digit modulus (512 bits) was factorized with an implementa-
tion of the GNFS developed by Buhler, Lenstra, and Pomerance. The GNFS
is more efficient than QS if n is longer than about 116 decimal digits. This
effort took 5 months. Please refer to [17].
• Ten years later, at the end of 2009, a 232-digit modulus (768 bits) was
factorized by Kleinjung after 2 ½ years. See [18].
This clearly demonstrates that a modulus length of 768 bits no longer provides
sufficient protection against attackers.
For details about factorization progress since 1999, see Section 5.12.4.
A good website for online factorization is Dario Alpern’s Integer Factorization
Calculator; see [19].
RSA cannot only be attacked by factorization but by several—well known—
poorly chosen settings. A tool that implemented almost all these attacks (mostly in
Python, some in SageMath) is RsaCtfTool. See [20].
i i
i i
i i
Figure 5.3 Comparison between the published, real factorization records (blue) and the predicted
development (orange). [Forecast by Fox 2001; last real addition 2020 (see Table 5.12).]
i i
i i
i i
to cite original sources, but for overviews websites are often more up-to-date and
these two Wikipedia websites are frequently updated. Further websites are primere-
cords [26] (but its last edit was in 2018 and it still does not offer https) and
FactorDB by Markus Tervooren, which provides over 2 billion fully factorized
composite numbers; see [27].
The last records with factorization algorithms for composed numbers are listed
in Table 5.12: The RSA numbers in the first column are certain large semiprime
numbers (i.e., numbers with exactly two prime factors). The “C” numbers are com-
pound and special numbers: They are either a Mersenne/Cunningham number (see
Sections 4.4.2 and 4.6.3) themselves or factors of such a number.
The RSA numbers were generated and published by the company RSA Security.
In the RSA Factoring Challenge the prime factors for these numbers are sought.
RSA Labs has offered its challenges since the beginning of the 1990s. The first
challenge labeled the numbers, from RSA-100 to RSA-500, according to their num-
ber of decimal digits; the second RSA Factoring Challenge labeled the numbers
after their number of binary digits. Within the second challenge cash prizes were
offered for successful factorizations of RSA-576 to RSA-2048 (RSA-576, RSA-
640, etc. using 64-bit steps upwards. An exception to this is RSA-617, which was
created prior to the change in the numbering scheme). But the RSA challenges
ended ahead of time in 2007, when RSA Inc. retracted the prize. All unsolved
RSA challenges of RSA Labs can be found at the website of the cipher challenge
“MysteryTwister” [28].
The C numbers originate from the Cunningham project [29], which seeks to
factor Mersenne numbers. These have a very special form that makes it orders of
magnitude easier to factor them compared to RSA moduli of the same length.
Table 5.12 shows for each number its length as a binary number and as a deci-
mal number, then the length of the two last and largest prime factors: p123 means
that the number is prime and has 123 decimal places. This is the notation as also
used in the standard book [30]. How difficult it is to factorize the Mersenne num-
bers depends above all on the size of their last two (largest) factors; see also [29].
Table 5.12 The Current Factoring Records as of May 2023 (Compare with Figure 5.3)
Binary Decimal Last Prime Factorized
Digits Digits Factors On By
RSA-250 829 250 p125 p125 Feb 2020 F. Baudot et al.
RSA-240 795 240 p120 p120 Dec 2019 F. Baudot et al.
RSA-768 768 232 p116 p116 Dec 2009 T. Kleinjung et al.
RSA-200 663 200 p100 p100 May 2005 Jens Franke et al.
RSA-640 640 193 p97 p97 Nov 2005 Jens Franke et al.
RSA-576 576 174 p87 p87 Dec 2003 Jens Franke et al.
RSA-160 530 160 p80 p80 Apr 2003 Jens Franke et al.
RSA-155 512 155 p78 p78 Aug 1999 H. te Riele et al.
…
C355 in 21193 − 1 1177 355 p104 p251 Aug 2014 T. Kleinjung et al.
C320 = 21061 − 1 1061 320 p143 p177 Aug 2012 G. Childers et al.
C307 in 21039 − 1 1017 307 p80 p227 May 2007 K. Aoki et al.
C274 in 6353 − 1 911 274 p120 p155 Jan 2006 K. Aoki et al.
C176 in 11281 + 1 583 176 p87 p89 May 2005 K. Aoki et al.
C158 in 2953 − 1 523 158 p73 p86 Jan 2002 Jens Franke et al.
i i
i i
i i
The last two columns of the table show when and by whom the number was fully
factorized.
If you are looking for a challenge, you will find many incompletely factorized
Mersenne numbers in the [29] database—these have the status code “CF” such as:
• C337: 21207 − 1 = 131071 · 228479 · 48544121 · 212885833 · 7121450524 . . . 71
• C297: 21213 − 1 = 327511 · 7150798418 . . . 71 · 6022881435 . . . 11
• C284: 21229 − 1 = 36871 · 46703 · 10543179280661916121033 ·
9536289355 . . . 57 · 5339295584 . . . 87
Further tasks/challenges can be found in the “Wanted list” in [29].
The current record (as of May 2023) obtained using the GNFS method
factorized a general 250 decimal-digit integer (829 bits) into its both prime factors.
Experiments about the elapsed time of factorization with the open-source
software Pari-GP, SageMath, CrypTool 1, and CrypTool 2 can be found in [31].
Considerations by Martin Ziegler and Samuel S. Wagstaff Jr. (Cunningham
table maintainer), which (non-)sense the factoring of such large numbers make,
can be found in [32] and [33].
Some of the records listed in Table 5.12 are explained in more detail below.
RSA-155
On August 22, 1999, researchers from the Netherlands found the solution of
the RSA-155 challenge. They factorized a 155-digit number into its both 78-digit
primes (see Section 5.12.2).
This 512-bit RSA-155 meant to reach a kind of magic border.
C158
On January 18, 2002, researchers at the University of Bonn factorized a 158-digit
decimal number into its both prime factors (these are built with 73 and 86 decimal
digits) using the GNFS method.
This record got much less attention within the press than the solution of RSA-
155. The task of the researchers was not initiated by a challenge, but they wanted
to find the last prime factors of the integer 2953 − 1 (see “Wanted List” in the
Cunningham Project [29]). The six smaller prime factors, already found before
have been:
3, 1907, 425796183929,
1624700279478894385598779655842584377,
3802306738549441324432139091271828121 and
128064886830166671444802576129115872060027
The first three factors can be easily computed.4 The next three prime factors were
found by P. Zimmermann, T. Grandlund, and R. Harley during 1999 and 2000
using the elliptic curve factorization method.
4. For example, using CT1 Indiv. Procedures F RSA Cryptosystem F Factorization of a Number.
CTO’s Msieve shows errors. Alpertron’s Calculator also finds the first three factors immediately. CT1 can
factorize in a reasonable time numbers only not longer than 250 bits.
i i
i i
i i
The last remaining factor, called C158, was known to be composite by then,
but its factors were not known (the following three lines contain one number):
39505874583265144526419767800614481996020776460304936
45413937605157935562652945068360972784246821953509354
4305870490251995655335710209799226484977949442955603
The factorization of C158 resulted in the following two 73- and 86-digit prime
factors:
3388495837466721394368393204672181522
815830368604993048084925840555281177
and
1165882340667125990314837655838327081813101
2258146392600439520994131344334162924536139.
RSA-160
On January 18, 2002, researchers at the University of Bonn factorized a 160-digit
number into its both prime factors (each with 80 decimal digits) using the GNFS
method. The computations for the factorization of RSA-160 also took place at the
German Information Security Agency (BSI) in Bonn.
The 160-digit decimal number origins from the old challenge list of RSA Secu-
rity. This number was retracted after RSA-155 had been factorized successfully. The
prime factors of RSA-160 were still unknown. So this record of the team of Franke
provides the solution of the old challenge, for which no prize is awarded anymore.
The composite number called RSA-160 is (the following three lines contain one
number):
215274110271888970189601520131282542925777358884567598017049
767677813314521885913567301105977349105960249790711158521430
2079314665202840140619946994927570407753
p = 45427892858481394071686190649738831
656137145778469793250959984709250004157335359
and
q = 47388090603832016196633832303788951
973268922921040957944741354648812028493909367
The calculations took place between December 2002 and April 2003.
RSA-200
On May 9, 2005, the research group of Jens Franke at the University of Bonn
i i
i i
i i
announced that they factorized a 200-digit number into its both prime factors (each
with 100 decimal digits) using the GNFS method.
The composite number called RSA-200 is (the following three lines contain one
number):
2799783391122132787082946763872260162107044678695542853756000992932
6128400107609345671052955360856061822351910951365788637105954482006
576775098580557613579098734950144178863178946295187237869221823983
p = 35324619344027701212726049781984643686711974001976
25023649303468776121253679423200058547956528088349
and
q = 79258699544783330333470858414800596877379758573642
19960734330341455767872818152135381409304740185467
The calculations took place between December 2003 and May 2005. The
research group included Bahr, Böhm, Franke, Kleinjung, Montgomery, and te Riele.
The operating expense of the calculations was about 120,000 MIPS-years. A MIPS-
year (MY) is the quantity of operations a machine can perform in one year if the
machine constantly achieves one million integer operations per second (MIPS). For
context, an Intel Pentium processor then had about 10 MIPS.
To factorize a 2048-bit modulus it is estimated to need about 8.5 · 1040 MY.
A current processor (such as AMD Ryzen 5900) achieved around 105 MIPS at the
end of 2021.
C307/M1039
In May 2007, Franke, Kleinjung (University of Bonn), the Japanese telecommu-
nication company NTT, and Arjen Lenstra (Polytechnical University of Lausanne)
announced that they managed to factorize a 307-digit decimal number into its both
prime factors with the SNFS method (special number field sieve) within 11 months
(the two factors have 80 and 227 decimal digits).
The task of the researchers was not initiated by a challenge, but they wanted
to find the last prime factors of the Mersenne number 21039 + 1 from the “Wanted
List” of the Cunningham Project [29].
The numbers in the Cunningham table have the following notation: “(2,n)-”
means 2n − 1; “(2,n)+” means 2n + 1.
To describe the magnitude one writes “p<n>” or “c<n>”: “n” is the number of
decimal digits and “p” and “c” tell whether the number is prime or composite: So
21039 − 1 = p7 · c307 = p7 · p80 · p227.
It is explained more precisely in [34]. “2,651+” means 2651 + 1 and the size
(c209 means 209 decimal digits) of the number that was factored. Then come the
new factor(s), the discoverer, and the method used. Recently, only the multiple poly-
nomial quadratic sieve (ppmpqs), the elliptic curve method (ecm), and the number
field sieve (nfs) have been used. “hmpqs” stands for hypercube multiple polynomial
i i
i i
i i
quadratic sieve. Under “new factors,” “p90” means a 90-digit prime and “c201”
is a 201-digit composite number.
The number 21039 − 1 consists of three prime factors. The smallest one, p 7 =
5080711, was already known.5
To complete this, the second factor (codivider) “C307” had to be factorized.
Until then it was only known that the last remaining factor was composite, but it
was unknown how many prime factors it had and what were the prime factors. The
following five lines contain one number:
C 307 = 1159420574072573064369807148876894640753899791702017724986
868353538822483859966756608000609540800517947205399326123020487
440286043530286191410144093453512334712739679888502263075752809
379166028555105500425810771176177610094137970787973806187008437
777186828680889844712822002935201806074755451541370711023817
The factorization of C307 resulted in the following two 80- and 227-digit prime
factors:
p 80 = 558536666199362912607492046583159449686465270184
88637648010052346319853288374753
and
p 227 = 207581819464423827645704813703594695162939708007395209881208
387037927290903246793823431438841448348825340533447691122230
281583276965253760914101891052419938993341097116243589620659
72167481161749004803659735573409253205425523689.
So now the number 21039 − 1 is completely factorized in its three prime factors.
RSA-768
On December 12, 2009, the research group of Thorsten Kleinjung announced that
they factorized a 232-digit number into its both prime factors (both factors have 116
decimal digits). They used the GNFS method in a way where they did oversieving
on several hundred computers before starting the matrix step.
The composite number called “RSA-768” is (the following three lines contain
one number):
123018668453011775513049495838496272077285356959533479219732245215
172640050726365751874520219978646938995647494277406384592519255732
630345373154826850791702612214291346167042921431160222124047927473
7794080665351419597459856902143413
5. This one can also be found using CT1 Indiv. Procedures F RSA Cryptosystem F Factorization of
a Number with the algorithms of Brent, Williams, or Lenstra, which are good to separate relatively small
factors.
i i
i i
i i
The factorization of RSA-768 resulted in the following two prime factors (each with
384 bits):
p = 3347807169895689878604416984821269081770479498371376856891
2431388982883793878002287614711652531743087737814467999489
and
q = 3674604366679959042824463379962795263227915816434308764267
6032283815739666511279233373417143396810270092798736308917
i i
i i
i i
5.12.5.1 Bernstein’s Paper and Its Implication on the Security of the RSA Algorithm
In his paper “Circuits for Integer Factorization: A Proposal,” published November
2001, D. J. Bernstein [35] addresses the problem of factorizing large integers. As a
main result Bernstein claims that the implementation of the GNFS algorithm can be
improved to factorize integers with three times more digits—with the same effort
as before.
Here the definition of effort is a crucial point: Bernstein claims that effort is the
product of time and costs of the machine (including the memory used). The gist of
the paper lies in the fact that he can reduce a big part of factorizing to sorting. Using
Schimmler’s scheme, sorting can be optimized by massive parallel computing. At the
end of Section 3, Bernstein explains this effect: The costs of m 2 parallel computers
with a constant amount of memory is a constant time m 2 . The costs of a computer
with a single processor and memory of size m 2 is also of the order of m 2 , but with
a different constant factor. With m 2 processors in parallel, sorting of m 2 numbers
(with Schimmler’s scheme) can be achieved in time m, while a m 2 -memory computer
needs time of the order of m 2 . Decreasing memory and increasing the number of
processors, the computing time can be reduced by a factor 1/m without additional
effort in terms of total costs. In Section 5 it is said that massive parallel computing
can also increase efficiency of factorizing using Lenstra’s elliptic-curve-method (a
search algorithm has costs that increase in a quadratic square manner instead of
cubically).
All results achieved so far are asymptotic results. This means that they only
hold in the limit n to infinity. Unfortunately, there is no upper limit for the resid-
ual error (i.e., the difference between the real and the asymptotic value) for finite
n – a problem that has already been addressed by the author. As a consequence,
one cannot conclude whether the costs (in the sense of Bernstein) for factorizing
1024−2048-bit RSA moduli can be significantly reduced.
There is no doubt that Bernstein’s approach is innovative. However, the reduc-
tion of computing time under constant costs comes along with a massive use of
parallel computing—a scenario that seems not to be realistic yet. For example,
formally 1 sec computing time on one machine and 1/1,000,000 sec time paral-
lel computing time on 1,000,000 machines might have same costs. In reality, it is
much harder to realize the second situation. Although distributed computing over a
large network might help to overcome this problem, realistic costs for data transfer
have to be taken into account.
Arjen Lenstra, Adi Shamir, et al. analyzed the paper of Bernstein [36]. In sum-
mary, they expect a factorization improvement on how much longer the bit length of
the keys could be with a factor of 1.17 (instead of factor 3 as proposed by Bernstein).
The abstract of their paper “Analysis of Bernstein’s Factorization Circuit” says:
i i
i i
i i
RSA Security concludes in its analysis of the Bernstein paper [37] from April 8,
2002, also—as expected—that RSA is still not compromised.
A detailed explanation from these two authors also can be found in the RSA
Laboratories CryptoBytes [39].
The three-page article in the DuD issue of June 2003 [40] contains a good
explanation of how the attack using the GNFS works and what progress is made to
factorize numbers. With GNFS we can distinguish two general steps: The sieve step
(relation collecting) and the matrix reduction. Besides that the sieve step is highly
parallelizable, it also dominates the overall calculation burden. Shamir and Tromer
haven’t built a TWIRL device yet, but the estimated costs of 10 to 50 million Euro
(in order to factorize a 1024-bit number) is not prohibitive for secret agencies or
big criminal organizations, as the costs for a single espionage satellite is estimated,
for example, to be several billion USD. The authors therefore recommend getting
rid of sensible RSA keys with a key length below 2048 bit as soon as possible.
This fits with recommendations like the BSI’s annual technical guideline [41]
to switch to longer RSA key lengths.
i i
i i
i i
i i
i i
i i
Start_Time = time.time ()
m2=cf * 162259276829213363391578010288127
print (" Time = %f sec \n m2:" % (time.time ()-Start_Time), m2)
Start_Time = time.time ()
r=583139672825572068433667900695808357466165186436234672858047078770918 �
� 753 / \
3593875704495823757388199894268773153439
print (" Time = %f sec \n m2/cf:" % (time.time ()-Start_Time), r)
i i
i i
i i
Start_Time = time.time ()
r=factor(30230154112263974517038253016890385962549205706778094829333106 �
� 0817639)
print (" Time = %f sec \n m1 =" % (time.time ()-Start_Time), r)
SageMath Example 5.11: Printing the Execution Time on the Sage Command
Line / Factorize
sage: # Calculate gcd
sage: %
....: 3023015411226397451703825301689038596254920570677809 �
� 48293331060817639)
CPU times: user 15 µs , sys: 0 ns , total: 15 µs
Wall time: 16.2 µs
3593875704495823757388199894268773153439
sage: %
/usr/lib/python3/dist -packages/IPython/core/interactiveshell.py:2364: �
� RuntimeWarning:
the factorization returned by qsieve may be incomplete (the factors may �
� not be prime)
or even wrong; see qsieve? for details result = fn(*args , ** kwargs)
CPU times: user 1.92 ms , sys: 10 µs , total: 1.93 ms
i i
i i
i i
sage: %
CPU times: user 74 ms , sys: 28 ms , total: 102 ms
Wall time: 3min 48s
162259276829213363391578010288127 * 35938757044958237573881998942687731 �
� 53439
Then, using a remainder tree, for each i the remainder z i of the division of P by m i2
is computed:
z i ≡ P mod m i2 , z i ∈ {0, 1, . . . , m i2 − 1}
gcd (ri , m i )
This is visualized in Figure 5.4, which is taken from [46] with some minor changes.
i i
i i
i i
Figure 5.4 Efficient computation of shared primes (quasi-linear gcd finding). (From: [46].)
The paper we are referring to explains well how the algorithm works, but not
as well why. The product P of all moduli is a very big number, even compared to a
single modulus. Without the simplifications from the remainder tree you would go
the following way: Calculate gi := gcdi = gcd( P /m i , m i ) for all i. Now for every
i there are three possibilities:
• gi = gcdi = 1
• gi = gcdi is a prime number
• gi = gcdi = m i
The third case is a special case that occurs if, m 1 = p1 · q1 and p1 divides m 2 and q1
divides m 3 . This case occurred only “in a handful of instances in our dataset” ([46,
p. 5]) and was solved by computing the gcd pairwise.
In the second case, one has found a prime factor of m i . In the first case, no
information about m i can be retrieved.
Here an example with very small moduli:
m 1 = 2 · 3 = 6; m 2 = 2 · 7 = 14; P = 6 · 14 = 84
P mod m 1 = 84 mod 6 = 0; P mod m 21 = 84 mod 36 = 12
P mod m 2 = 84 mod 14 = 0; P mod m 22 = 84 mod 196 = 84
g1 = gcd1 = gcd(12/6, 6) = gcd(2, 6) = 2
g2 = gcd2 = gcd(84/14, 14) = gcd(6, 14) = 2
i i
i i
i i
Why does gcd(( P mod m i2 )/m i , m i ) deliver the same result as gcd( P /m i , m i )?
We have a closer look at why this identity Q is correct.
Let, as before, P be the product ik=1 m i and z i ≡ P mod m i2 with z i ∈
{0, 1, . . . , m i2 − 1} for i = 1, 2, . . . , k.
Then, if we again denote with ri the (integer) quotient mzii , we have
k
Y
P = ci m i2 + z i or zi = m j − ci m i2 for some integer ci
j =1
and therefore
Qk k
zi j =1 m j − ci m i2 Y
ri = = = m j − ci m i (5.1)
mi mi
j =1, j6=i
as well as: k
Y
m j = ri + ci m i (5.2)
j =1, j6=i
ti = gcd (ri , m i ) .
We also write gi = gcd mPi , m i . Clearly in (5.1) one can always factor out gi
and so gi divides ti .
Conversely, ti always divides gi : Because of ti dividing both m i and ri , it must
because of (5.2) also divide j6=i m j = mPi and therefore also gi . It follows ti = gi
Q
for all i.
The latter is only an alternative formulation of the statement we had made
before:
gcd(( P mod m i2 )/m i , m i ) = gcd( P /m i , m i ).
i i
i i
i i
example, the sender of a message could add a number to be kept secret (the key
S) to the plaintext number M and thereby obtain the ciphertext number C:
C =M+S
By reversing this operation, that is, by subtracting S, the receiver can reconstruct
the plaintext:
M =C−S
Adding S reliably obfuscates the plaintext. Nevertheless, this “encryption” is very
weak: If an eavesdropper gets her hands on just one pair of plaintext and ciphertext
numbers, she can calculate the key
S=C−M
and read all subsequent messages encrypted with S. A key reason for this is that
subtraction is as simple an operation as addition.
One-Way Functions
If we want to make it impossible to determine the key even with the knowledge of
both the plaintext and the ciphertext, we need a function that is, on the one hand,
relatively easy to calculate. On the other hand, the inverse function should exist
(otherwise information would be lost during encryption), but should be de facto
incalculable.
What are possible candidates for such a one-way function? We could take mul-
tiplication rather than addition, but even primary school children know that the
inverse function, division, is only slightly more difficult than multiplication itself.
We need to go one step higher in the hierarchy of calculation methods. It is still
relatively simple to calculate the power of a number, but the corresponding two
reverse functions—taking roots (find b in the equation a = bc when a and c are
known) and calculating logarithms (find c in the equation a = bc when a and b are
known) are so complicated that students normally do not learn them at school.
Knowing a few values of the function then for addition and multiplication,
a certain structure can still be recognized, but raising numbers to the power of
another one or calculating exponentiations doesn’t tell us much about the function
parameters. Taking the logarithm becomes even more difficult if you don’t work in
infinite sets like N or Z, but in large finite sets.
i i
i i
i i
For allocating the participants in the protocol, Bob and Alice are used, which
are the default names for the two authorized participants (see [49, p. 23]).
Alice and Bob use a one-way function to obtain a secret key S, the session
key, for subsequent correspondence; see Figure 5.5. The session key can be used,
for example, as a key in a symmetrical procedure such as AES. This session key is
only known to the two parties. How do the protocol works: Alice selects a random
number a and keeps it secret. She applies a one-way function to a to calculate the
number A = g a and sends it to Bob. He does the same, by selecting a secret random
number b, calculating B = g b and sending it to Alice. The number g is random and
can be publicly known. Alice applies the one-way function together with her secret
number a to B, while Bob does the same with his secret number b and the received
number A.
The result S is the same in each case because the one-way function is commuta-
tive: (g a )b = (g b )a . But even Bob cannot reconstruct Alice’s secret number a from
the data available to him, while Alice cannot determine Bob’s secret number b. And
an eavesdropper (Eve) who knows g and has intercepted both A and B cannot use
this knowledge to determine a, b, or S.
Procedure:
Alice and Bob want to negotiate a secret session key S via a channel that may be
intercepted.
1. They select a prime number p and a random number g and exchange this
information openly.
2. Alice now selects a, a random number less than p and keeps it secret.
Similarly, Bob selects b, a random number less than p and keeps it secret.
3. Alice now calculates A ≡ g a (mod p ).
Bob calculates B ≡ g b (mod p ).
Figure 5.5 Process of the DH key-exchange protocol (all operations modulo p).
i i
i i
i i
print ("Get the secret key of Alice (with g=11, p=347, A=49, a=240 or 67 �
� ) ---")
i i
i i
i i
print ("Get the secret key of Bob: (with g=11, p=347, B=285, b=39) ---")
B=R(285)
print (" b:", discrete_log(B,g))
#------------------------------------
# CHAP05 -- Sage -Script -SAMPLE 020: =========
# Get the secret key of Alice (with g=11, p=347, A=49, a=240 or 67) ---
# a) via 'normal ' integer numbers
# a: 67
# b) via the ring of integers (better)
# a: 67
# Get the secret key of Bob: (with g=11, p=347, B=285, b=39) ---
# b: 39
ple) satisfy the equation and can therefore be used to calculate the session key:
285240 ≡ 28567 ≡ 268 (mod 347). If Alice and Bob had selected a primitive root
modulo p as base g, then for every remainder from the set {1, 2, . . . , p − 1} there is
exactly one exponent from the set {0, 1, . . . , p − 2}.
i i
i i
i i
As an aside, there are 172 different primitive roots modulo 347, 32 of which
are prime (not necessary). Since the number 11 selected for g in the example is
not a primitive root of 347, the remainders do not take all values from the set
{1, 2, . . . , 346}. Thus, for a particular remainder there may be more than one
exponent or even no exponent at all in the set {0, 1, . . . , 345} that satisfies the
equation.
With the relevant SageMath commands you find:
is_prime(347)=True, euler_phi(347)=346, gcd(11,347)=1, and
multiplicative_order(mod(11, 347))=173.
i 11i mod 347
0 1
1 11
2 121
3 290
67 49 searched exponent
172 284
173 1 = multiplicative order of 11i mod 347
174 11
175 121
176 290
240 49 searched exponent
Further information can be found in Section 5.17.4.
Having described in Section 5.10.2 how the RSA procedure works, we will now
work through the steps using specific, but still small, numbers—and still only
textbook RSA.
5.14.1 RSA with Small Prime Numbers and with a Number as Message
Before applying the RSA procedure to a text, we will first demonstrate it directly
using a single number as message. In practice, RSA is not applied on texts, but only
on big numbers.7
7. - You can handle this, for example, using CT1 Indiv. Procedures F RSA Cryptosystem F RSA
Demonstration.
- Or in CTO: either in the plugin “RSA (step-by-step)”: https://www.cryptool.org/en/cto/rsa-step-
by-step or in the plugin “RSA visual and more”: https://www.cryptool.org/en/cto/rsa-visual in
the tabs “RSA visual” or “RSA didactic.”
- Or using CT2 Templates F Mathematics F RSA with big numbers.
i i
i i
i i
5.14.2 RSA with Slightly Larger Primes and a Text of Uppercase Letters
We have the text “ATTACK AT DAWN,” and the characters (including the blank)
are coded according to Table 5.14.8
Key generation (steps 1 to 3):
1. p = 47, q = 79 (n = 3713; φ (n ) = ( p − 1) · (q − 1) = 3588).
2. e = 37 (e must be relatively prime to 3588).
3. d = 97 ( since e · d = 1 mod φ (n ); 37 · 97 ≡ 3589 ≡ 1 (mod 3588) ).
4. Encryption:
Text: A T T A C K A T D A W N
Number: 01 20 20 01 03 11 00 01 20 00 04 01 23 14
8. - You can handle this using CT1 Indiv. Procedures F RSA Cryptosystem F RSA Demonstration. This
is also described in the tutorial/scenario in CT1’s online help [Options: specify alphabet, number system,
block length 2 and decimal representation].
- In CTO in the plugin “RSA visual and more”: https://www.cryptool.org/en/cto/rsa-visual. See
Figures 5.6 and 5.7.
i i
i i
i i
Figure 5.6 RSA in CTO: text encryption, own alphabet, decimal concatenation, block length 2; Part 1:
generate and store key.
This 28-digit number is divided into four-digit parts (because 2626 is still
smaller than n = 3713). This means that the block length is 2 (the numerical
values of two characters are combined):
i i
i i
i i
Figure 5.7 RSA in CTO: text encryption, own alphabet, decimal concatenation, block length 2; Part 2:
encryption.
Using the selected values it is easy for a cryptanalyst to derive the secret values
from the public parameters n = 3713 and e = 37 by factorizing n. However, if n
is a 2048-bit number, there is, according to present knowledge, little chance to do
a factorization. Nevertheless, this form of RSA is insecure even with large moduli
(see Section 5.11).
5.14.3 RSA with Even Larger Primes and a Text Made up of ASCII
Characters
In real life, the ASCII alphabet is used to code the individual characters of the
message as 8-bit numbers.
i i
i i
i i
The idea for this exercise9 is taken from the example in [50, p. 271].
Coded in decimal notation, the text “RSA works!” is as follows:
Text: R S A w o r k s !
Number: 82 83 65 32 119 111 114 107 115 33
We will work through the example in two variants. The steps 1 to 3 are common
for both.
Variant 1: All ASCII characters are en-/decrypted separately (no blocks are formed)
See Section 5.17.5 for the source code for RSA operations like modular exponenti-
ation or the Euler function using SageMath.
4. Encryption:
Text: R S A w o r k s !
Number: 82 83 65 32 119 111 114 107 115 33
The letters are not combined here. For secure procedures we need large numbers
that accept—as far as possible—all values up to n − 1. If the possible value set for
the numbers in the message is too small, even large prime numbers cannot make
the procedure secure. An ASCII character is represented by 8 bits. If we want larger
values we must combine several numbers. Two characters need 16 bits, whereby
the maximum value that can be represented is 65536. The modulus n must then
be greater than 216 = 65536. This is applied in variant 2. When the numbers are
combined, the leading zeros are kept in binary notation (just as if we were to write
all numbers with three digits in decimal notation above and were then to obtain the
sequence 082 083, 065 032, 119 111, 114 107, 115 033).
Each character is encrypted using: C = M 65537 (mod 256027):
9. - You can handle this exercise using CT1 Indiv. Procedures F RSA Cryptosystem F RSA
Demonstration.
- Using CT2 Templates F Mathematics F RSA with big numbers for single numbers.
- Using JCT Default Perspective F Visuals F RSA Cryptosystem you can handle this task too.
- In CTO in the plugin “RSA visual and more” both variants (with and without block formation)
and both sequences of coding (concatenation of the binary representation of the individual characters,
or their decimal representation is concatenated first and then converted to binary) can also be used:
https://www.cryptool.org/en/cto/rsa-visual. See Figures 5.8 and 5.9 for variant 2.
i i
i i
i i
Figure 5.8 RSA in CTO: text encryption, ASCII alphabet, block length 2; Part 1: b-adic encoding.
5. Decryption:
Ciphertext:
i i
i i
i i
Figure 5.9 RSA in CTO: text encryption, ASCII alphabet, block length 2; Part 2: decimal conatenation.
Text: R S A w o r k s !
Number: 82 83 65 32 119 111 114 107 115 33
10. Also solvable with CTO in the plugin “RSA visual and more”: https://www.cryptool.org/en/cto/rsa-
visual. The adequate settings alphabet (ASCII or self-defined), b-adic or concatenation, and block length
are set in Figures 5.8 and 5.9.
i i
i i
i i
4. Encryption:
Blocks are formed by encoding each ASCII character into an 8-digit binary number
and joining two binary numbers are:
Forming a block:
single character binary representation decimal representation
01010010, 82 01010010 01010011 = 21075
01010011, 83
01000001, 65 01000001 00100000 = 16672
00100000, 32
01110111, 119 01110111 01101111 = 30575
01101111, 111
01110010, 114 01110010 01101011 = 29291
01101011, 107
01110011, 115 01110011 00100001 = 29473
00100001, 33
Altogether:11
5. Decryption:
Ciphertext:
4’. Encryption:
Blocks are formed (each block contains two ASCII characters, and the ASCII
characters are written as two 3-digit decimal numbers one after the other):
RSA encryption works correctly with the modulus n = 256027 because each ASCII
block of two characters will be encoded into a number that is smaller or equal to
the number 255,255.
11. You can solve this using CT1 Indiv. Procedures F RSA Cryptosystem F RSA Demonstration with the
following options: all 256 ASCII characters, b-adic, block length 2, and decimal representation.
i i
i i
i i
5’. Decryption:
Ciphertext:
You will have to invert this process as the final step in your program.
The first plaintext was taken from The Diary of Samuel Marchbanks by Robert-
son Davies, 1947, and the second was taken from Lake Wobegon Days by Garrison
Keillor, 1985.
i i
i i
i i
i i
i i
i i
a. Known-plaintext attack: find the secret key d using the additionally known
original message.
b. Ciphertext-only attack: find d and the plaintext.
c. Calculate the RSA modulus; in other words, factorization (with no knowl-
edge of the message).
n = 63978486879527143858831415041, e = 17579
Message:
1401202118011200,
1421130205181900,
0118050013010405,
0002250007150400
Cipher:
45411667895024938209259253423,
16597091621432020076311552201,
46468979279750354732637631044,
32870167545903741339819671379
Comment:
The original message consisted of a sentence containing 31 characters (coded with
the capital letters’ alphabet from Section 5.14.2). Each group of 16 decimal numbers
is then combined to form one number (the last number is filled with zeros). These
numbers are raised to the power of e.
When you decrypt the message you must fill the calculated numbers with lead-
ing zeros in order to obtain plaintext. This needs to be stressed because the type
of padding is extremely important during implementation and standardization for
interoperable algorithms.
i i
i i
i i
From time to time, some students ask how to deal with negative results (e.g.,
−1). For example, for affine ciphers with 26 characters, you calculate modulo 26.
In Z26 = {0, 1, 2, · · · , 25} it is 0 − 1 = −1 = 25 (mod 26).
The modulo calculation and which numbers belong to the same residue class
are illustrated in Table 5.17. You can see that numbers in the same column belong to
the same residue class. Such didactic representations help certain types of learners
more than formulas.
So here you can see that the following numbers are congruent: 51 ≡ 25 ≡
−1 (mod 26). Being congruent means belonging to the same residue class. Two
numbers are congruent if their difference can be divided by the modulus. So, (25 −
(−1)) = (51 − 25) = 26 are all divisible by 26.
For a given number z one may ask how to represent√ such a number. In general
we use representations like z = 2374 or z = 2. The second number consists of
an infinite number of digits and therefore it can never be described precisely by
the first representation. You can get around this problem by writing the number
symbolically. But if you have to write it in digits, the number must be rounded.
We represent numbers usually in the decimal system (base 10). Computers are
working with the binary representation of numbers—only for the display numbers
are represented in decimal or sometimes hexadecimal (base 16) form.
This section describes how to generate arbitrary base representations of any
positive integer and how to determine the number of required digits via the
logarithm function.
z = an bn + an−1 bn−1 + · · · + a1 b + a0 ,
i i
i i
i i
5.16 Base Representation and Base Transformation of Numbers and Estimation of Length 269
(Using these inequalities it can be shown that each positive integer can be repre-
sented by a b-adic sum).
By writing the digits an an−1 · · · a1 a0 in a row directly after each other (without
the bi ) the usual writing for numbers becomes available.
Example:
base b = 10: 10278 = 1 · 104 + 0 · 103 + 2 · 102 + 7 · 101 + 8.
base b = 16: FE70A = 15 · 164 + 14 · 163 + 7 · 162 + 0 · 161 + 10.
lb (z ) := blogb zc + 1
Applying the logarithm formula on base b and b0 we have logb z = logb0 z / logb0 b.
It is therefore easy using, for example, logarithm tables for the base b0 = 10 to com-
pute the logarithm of base b = 2. With SageMath it is even easier: The command
log(n,b) returns the logarithm ob n to the base b, usually in an algebraic form:
log(101,10) returns log(101)/log(10) where log(n) is the natural logarithm
with base e. For numerical values use log(101,10).n(), then you get 2.0043...
and for rounding down use floor(log(101,10)) then you get 2.
Example 1 (decimal→hex)
We compute for the decimal number z = 234 (EA in hex) the hexadecimal
representation (number base b = 16)
Example 2 (decimal→binary)
We compute for the decimal number z = 234 (11101010 in binary) the binary
representation (number base b = 2)
i i
i i
i i
Example 3 (binary→decimal)
We compute for the binary number z = 11101010 (234 decimal) the decimal
representation (number base b = 10)
input: z, b
n := 0, z 0 := z
while z 0 > 0 do
an := z 0 (mod b)
z 0 := bz 0 /bc
n := n + 1
end do
output: an an−1 · · · a1 a0 in base b representation.
Example 4 (decimal→hex)
The integer z = 234 on the number base 10 will be transformed into the hex rep-
resentation via a0 = 234 (mod 16) = 10 = A; 234/16 = 14 = E, a1 = 14
(mod 16) = E, and therefore we have E A.
Example 5 (binary→decimal):
The binary number z = 1000100101110101 is transformed into the decimal repre-
sentation via the following steps:
SageMath Example 5.13 contains code for the examples about digit length and
converting the representation between different bases. Sage integers can be read
as a decimal, octal, hexadecimal, or binary number: Integer() or ZZ() interpret
strings that begin with “0o” as octal numbers, strings that begin with “0x” as
hexadecimal numbers, and strings that begin with “0b” as binary numbers. We can
omit Integer() and ZZ() when entering a number on the Sage command line, as
the interpretation as a Sage integer is the default.
i i
i i
i i
5.16 Base Representation and Base Transformation of Numbers and Estimation of Length 271
i i
i i
i i
Below you can find SageMath source code related to contents of this Chapter 5.
We also recommend the short article by Nguyen, which is didactically very clear
and treats basic number theory and SageMath usage [52].
m = 5; R=Zmod(m)
T = R.multiplication_table(names='digits '); print(T)
# print( latex(T) ) # get the code for LaTeX to print the according table
m = 5; R=Zmod(m); elem = [str(i) for i in range(1,m)] #; print (" elem: ", elem)
T = R.multiplication_table(names='elements ', elements=elem); print(T) # =elem instead of �
� elements =('1 ','2 ','3 ','4 ')
# print(T.column_keys (), "\n") # (1, 2, 3, 4)
m = 6; R=Zmod(m) # m = 15
T = R.multiplication_table(names='digits '); print(T)
m = 17; a = 5
print( [mod(a * i, m) for i in range(m)] )
a = 6
print( [mod(a * i, m) for i in range(m)] )
i i
i i
i i
#------------------------------------
# CHAP05 -- Sage -Script -SAMPLE 030: =========
# [0, 5, 10, 15, 3, 8, 13, 1, 6, 11, 16, 4, 9, 14, 2, 7, 12]
# [0, 6, 12, 1, 7, 13, 2, 8, 14, 3, 9, 15, 4, 10, 16, 5, 11]
The function mod() returns an object that represents integers modulo m (in our
case m = 17).
The other multiplication table examples modulo 13 (Table 5.5) and modulo 12
(Table 5.6) can be computed similarly by replacing m = 17 with m = 13 and m =
12, respectively.
a = 87; m = 103
exp = [2, 4, 8, 16, 32, 43]
z = [power_mod(a, e, m) for e in exp]
print( type(z), "\n", z )
#------------------------------------
# CHAP05 -- Sage -Script -SAMPLE 040: =========
# <class 'list '>
# [50, 28, 63, 55, 38, 85]
SageMath Example 5.17: Table with All Powers a i (mod m ) for m = 11,
a, i = 1, ..., 10
print ("\n# CHAP05 -- Sage -Script -SAMPLE 050: =========")
m = 11
for a in range(1, m):
print( [power_mod(a, i, m) for i in range(1, m)] )
# E: adding a last column with the order of each 'a' mod (11)
# D: die letzte Spalte um die Ordnung des jeweiligen 'a' mod (11) ergänzen
print () # add an empty line between the two tables
i i
i i
i i
Table 5.8 gives examples for ord45 (a ) and the Euler number φ (45). SageMath
Example 5.18 constructs a table similar to Table 5.8. In addition, this sample uses
the method table in order to print the layout of the table.
SageMath Example 5.18: Table with All Powers a i (mod 45) for a, i =
1, . . . , 12 Plus the Order of a
print ("\n# CHAP05 -- Sage -Script -SAMPLE 060: =========")
tbl = []
m = 45
noCols=m; noRows=m # so whole table isprinted
noCols=13; noRows=13 # so smaller , more clear table isprinted
Programming hint: In the code example 5.18, we put the calculation of the mul-
tiplicative order within a try-except block. So you can catch any exceptions or
errors raised by the function multiplicative_order(). If an exception or error is
raised in the try block, then we know that ordm (a ) does not exist for that particu-
lar value of a. Hence in the except block we append the string "No mult. order"
to the row represented by the object lst.
Table 5.9 displays exponentiation a i (mod 46) as well as the order ord46 (a ).
SageMath Example 5.19 creates such a table.
SageMath Example 5.19: Table with All Powers a i (mod 46) for a, i =
1, . . . , 23 Plus the Order of a
print ("\n# CHAP05 -- Sage -Script -SAMPLE 070: =========")
m = 46
print( euler_phi(m) ); print ()
i i
i i
i i
SageMath Example 5.20 generates Tables 5.10 and 5.11. It also delivers the
result in a way that can be easily processed in LaTeX. The prerequisite is that all
content is assigned to one SageMath object (here the matrix r ).
A note about SageMath Example 5.20, especially about the SageMath
indices:
• for x in range(2, 5) delivers 2,3,4.
• m = matrix(ZZ, 2, 5) has 2 rows and 5 columns. The cells are named
m(0,0) to m(1,4).
• All elements of the matrix have to be numerical, so “0” is used instead of
None as in the tables before.
• The output of matrices can be controlled in SageMath with:
sage: from sage.matrix.matrix import set_max_cols, set_max_rows
sage: set_max_cols(100)
sage: set_max_rows(100)
• The length of the cycle in the last column of the Tables 5.10 and 5.11 was
added manually.
SageMath Example 5.20: Code for Tables with All Powers a i (mod m ) for
Variables a and i Plus Order of a and Eulerphi of m
print ("\n# CHAP05 -- Sage -Script -SAMPLE 080: =========")
i i
i i
i i
i i
i i
i i
...
i i
i i
i i
Chapter 9), here Python is used to import just this function from another Sage
script.
To do so, the importing script uses the function my_import which gets as
argument the function name to be imported. my_import then uses Python
mechanisms to load and execute the function from the argument from
another Sage script. Note that the function is loaded from the Python ver-
sion of the Sage script. This works because SageMath always transforms
the Sage script into a Python script, which then is performed (sample:
When calling $sage myfile.sage a Python file myfile.sage.py is created
from myfile.sage). Currently, this my_import function is written in such
a way that it requires a typical Unix shell (e.g., Bash), which is available
by default on Linux and macOS. However, this also works on Windows,
where SageMath for Windows is delivered together with the Bash shell (see
https://wiki.sagemath.org/SageWindows).
The call within the own Sage script looks like this:
my_import("chap05_sample100", "enum_PrimitiveRoots_of_an_Integer").
i i
i i
i i
if bPrimesOnly:
print (" Found all %s" % nPrimitiveRoots + \
" primitive roots of %s prime(s)." % nCheckedNumb)
else:
if nCheckedNumb_WithoutPrimitivRoots == 0:
print (" Found all %s " % nPrimitiveRoots + \
"primitive roots of %s number(s)." % nCheckedNumb)
else:
print (" Found all %s " % nPrimitiveRoots + \
"primitive roots of %s number(s)." % \
(nCheckedNumb - nCheckedNumb_WithoutPrimitivRoots ))
print ("( Total of numbers checked: %s " % nCheckedNumb + \
"Amount of numbers without primitive roots: %s)" % \
nCheckedNumb_WithoutPrimitivRoots )
import time # in sage scripts: measure time like in Python and calculate execution time
i i
i i
i i
import time
my_import (" chap05 _sample100", " enum_PrimitiveRoots_of_an_Integer ")
i i
i i
i i
import time
StartTime = time.time ()
start = 1 # normal value: 1 // test value: 10^5+3
end = start+200 # normal value: 10^6 // start+200 test value
fileName = "./ primroot -smallest_up -to -one -million.dat"
print ("... Creating file %s with start =%d, end=%d" % (fileName , start , end))
file = open(fileName , "w")
file.write (" Used parameters: start = " + str(start) + ", end = " + str(end) + "\n")
file.write("---- StartTime: " + str(StartTime) + " sec ----\n")
file.flush ()
for p in primes(start , end+1):
L = enum_PrimitiveRoots_of_an_Integer (p)
# - To commandline , output only p and number of prim roots of Z_p
# print(p, len(L)) # just temporarily active to see where you are while testing
# - To file , output much more in the following format:
# (1) the prime number p
# (2) the number of primitive roots of Z_p
# (3) the smallest primitive root of Z_p
# (4) the largest primitive root of Z_p
LL = sorted(L) # sort necessary as the smallest primroot is
# not always found first (see L of p=43)
file.write(str(p) + " " + str(len(L)) + " " + str(LL[0]) + " " + str(LL[-1]) + "\n �
� ")
file.flush ()
i i
i i
i i
If you are looking only for the smallest primitive root, then this script could
be accelerated dramatically by applying mathematical theory and searching
more directly for possible candidates (instead of first generating all primitive
roots with enum_PrimitiveRoots_of_an_Integer).
g. SageMath Example 5.27
The database file primroots_1-100000.dat from the SageMath Example
5.27 then was used as input to create three graphics using the example 5.27).
For a change, here the Sage code is from the CLI instead of from a Sage script.
i i
i i
i i
Figure 5.11 graphs the number of primitive roots for each prime between 1
and 100,000. The x-axis represents primes between 1 and 100,000, while the
y-axis counts the number of primitive roots for each prime.
Figure 5.12 graphs the smallest primitive roots of all primes between 1 and
100,000. The x-axis again represents primes between 1 and 100,000. The
y-axis represents the smallest primitive root of each prime.
Figure 5.13 shows a corresponding graph for the largest primitive root of
each prime within the same interval between 1 and 100,000.
i i
i i
i i
Figure 5.11 The number of primitive roots of all primes between 1 and 100,000.
Figure 5.12 The smallest primitive roots of all primes between 1 and 100,000.
i i
i i
i i
Figure 5.13 The largest primitive roots of all primes between 1 and 100,000.
Figure 5.14 Number and smallest and biggest primitive root for all primes up to 100.
i i
i i
i i
def Display(F,fname):
...
# Generate 3 graphics:
# 1) Plot of number of primitive roots modulo p
# a) Either plot with the 2D plotting class "point2d()" built in sage
# Remark 1: If you have a smaller primes range , use bigger
# pointsize values or get rid of this parameter
# For huge sets , "pointsize=1" is fine.
# Remark 2: point2d() has no option "plotjoined=True"
# nplot = point2d(zip(plist , nlist))
# nplot = point2d(zip(plist , nlist), pointsize=1)
# b) or plot with "list_plot ()"
# Remark 3: "list_plot(list(zip(plist , nlist))" needs cast with list ()
# and has same result as "point2d(zip(plist , nlist))"
# Remark 4: list_plot () has option "plotjoined=True" to connect the
# points. This gives a better impression for smaller sets.
nplot = list_plot(list(zip(plist , nlist)), plotjoined=True)
nplot.axes_labels (["p", "number of primitive roots "])
Display(nplot , "Plot_number -of -all -primitive -roots ")
i i
i i
i i
Figure 5.14 contains three graphs. The x-axis always represents the primes
between 1 and 100. In the top-left graph the y values are the number of
primitive roots for each prime. In the graph in the top-right, the y value
represents the smallest primitive root for the corresponding prime number.
In the bottom graph, the y value represents the biggest primitive root for the
corresponding prime number.
Compared to SageMath Example 5.27, here list_plot() is used which
offers the option plotjoined. This option connects the single points with
lines, which only makes sense for small sets of points.
i. SageMath Example 5.29
i i
i i
i i
5.17.6 How Many Private RSA Keys d Exist within a Given Modulo Range?
The RSA encryption procedure was described in Section 5.10.2. Steps 1 to 3
constitute key generation, steps 4 and 5 are the encryption:
1. Select two distinct random prime numbers p and q and calculate n = p · q.
The value n is called the RSA modulus.
2. Select an arbitrary e ∈ {2, · · · , n − 1} such that:
e is relatively prime to φ (n ) = ( p − 1) · (q − 1).
We can then throw away p and q.
3. Select d ∈ {1, · · · , n − 1} with e · d ≡ 1 (mod φ (n )).
That is, d is the multiplicative inverse of e modulo φ (n ). We can then throw
away φ (n ).
→ (n, e) is the public key P.
→ (n, d ) is the private key S (only d must be kept secret).
i i
i i
i i
i i
i i
i i
SageMath Example 5.35: How Many Private RSA Keys d Are There If You
Know a Range for the Public Key n?
print ("\n# CHAP05 -- Sage -Script -SAMPLE 160: =========")
print (" Number of private keys d for moduli in given range: %s (# comb =%s), " % (s, comb))
# Just for comparison: How many primes are in the given moduli range [a,b+1]?
if Verbose:
s = 0
primeslist =[]
for p in prime_range(a, b+1):
if Verbose >=2:
primeslist.append(p)
s = s + 1
if Verbose >=2:
print (" a=%s, " % a + "b=%s, " % b + "\n primeslist =%s" % primeslist)
print (" Number of primes in given range: %s" % s)
import time
print ("\n-----------Testcase: Moduli range = (100, 107, True)[this range has 3 primes ]")
StartTime = time.time ()
count_Number_of_RSA_Keys (100, 107, True)
print (" Time = %f sec" % (time.time ()-StartTime))
...
As there are so many private keys (n, d ) within a bigger range of values for
n, even brute-force factoring would be more efficient than brute-force trying all
possible private keys.
i i
i i
i i
algorithm (function) onto themselves are called fixed points. In cryptography the
corresponding messages are called unconcealed messages.
Generally speaking, fixed points are undesirable and there should be only very
few compared to the overall range of possible messages. The more fixed points an
encryption algorithm contains, the easier it is to break it. To deal with this and
with rainbow attacks, in practice random padding like in OAEP is added (instead
of using textbook RSA).
With the RSA procedure, n = pq is the product of two different prime numbers,
and there exists e where gcd (e, ( p − 1)(q − 1)) = 1. The encryption is then c = m e
mod n. A fixed point in the RSA procedure is a message m, where: m = m e mod n.
The result of the encryption is the given message.
When the size of n is sufficiently big, the probability of the occurrence of fixed
points in RSA is very small, as illustrated in Figure 5.16. Experimentally, we found
on average not more than 40 fixed points for a single given RSA parameter set.
Students often presume the occurrence of fixed points is high, because they
encounter a relatively large number of fixed point examples when experimenting
with small prime numbers, as m = 0, 1, n − 1 are always fixed points with RSA.
In practice, where large prime numbers are chosen, fixed points have no signif-
icance for the security of RSA. Therefore, here we refer more to the mathematical
questions.
x n = 1 and x k 6= 1 (k = 1, 2, 3, ..., n − 1)
i i
i i
i i
p−1
numerator), α must be a multiple of δ .
p−1
α=k· for some k ∈ Z
δ
For k = 1, . . . , δ we get δ different possible values for α. For larger k write k =
r · δ + k 0 with k 0 < δ, then we have
p−1 p−1 0 p−1 0 p−1 0 p−1
g α = g k·
0
δ = g (r ·δ+k )· δ = gr ·( p−1)+k · δ = (gr ) p−1 · g k · δ = gk · δ
Proof
Given m e = m mod n. According to the Chinese remainder theorem (CRT), the
following statements are equivalent:
We consider m e−1 = 1 mod p and search all (e − 1)th roots of unity in Z∗p .
We know that Z∗p for a prime p is cyclic. ⇒ A generator g exists which
produces Z∗p : Z∗p =< g >.
Theorem 5.16 delivers the remaining part.
The number of combinations of the (e − 1)th root of unity in Z∗p and Zq∗ gives
the total quantity of RSA fixed points: m e = m mod n with m ∈ {1, ..., n − 1}:
gcd( p − 1, e − 1) · gcd(q − 1, e − 1)
(gcd ( p − 1, e − 1) + 1) · (gcd (q − 1, e − 1) + 1)
i i
i i
i i
Proof
Each value ( p − 1) and (q − 1) is even for primes p, q > 2.
The RSA algorithm requires choosing e so that 1 < e < φ (n ) = ( p − 1)(q − 1) and
gcd (e, ( p − 1)(q − 1)) = 1.
Since ( p − 1) and (q − 1) are even, e is odd ⇒ e − 1 is even.
Since ( p − 1) and (e − 1) are even, then: gcd ( p − 1, e − 1) ≥ 2.
⇒ (gcd ( p − 1, e − 1) + 1) ≥ 3 and (gcd (q − 1, e − 1) + 1) ≥ 3.
⇒ (gcd ( p − 1, e − 1) + 1) · (gcd (q − 1, e − 1) + 1) ≥ 9.
Samples with m ∈ {0, ..., n − 1}:
Figure 5.15 was taken from “RSA Visual and More,” https://www.cryptool
.org/en/cto/rsa-visual. In this plugin you can either see with graphics how
RSA assigns its input values when encrypting, or you can test textbook RSA with
big numbers (and subject keys in a key store to simulate certificate exchange in
a pupils’ lab), or use RSA with OAEP, padding, and certificates as it is used in
practice.
i i
i i
i i
Figure 5.15 CTO: Nine fixed points (in red) with RSA using (e, n ) = (7, 55) with m ∈ {0, . . . , 54}.
Proof Given:
– e · d = 1 mod φ (n ) or e · d = 1 mod lcm ( p − 1, q − 1)
– m x mod n = m x mod φ (n ) mod n
Encryption of messages:
c = m e mod n, where c is the ciphertext and m is the plaintext.
Decryption of messages:
m 0 = cd mod n, where d is the multiplicative inverse of e.
We will show: c = m mod n for the chosen e.
c = m e mod n
c = m 1+lcm ( p−1,q−1) mod n
c = m 1 · m k·( p−1)·(q−1) mod n
c = m 1 · m [k·φ (n )] mod φ (n ) mod n
c = m 1 · m 0 = m mod n
i i
i i
i i
is different to the weak keys k in DES, where every message m relates to itself if
the encryption is done twice. To my knowledge, for larger n the RSA procedure
does not have weaknesses in this meaning: (m e )e = m. A double operation with the
public key also makes no sense with asymmetric procedures.
With JCT Default Perspective F Visuals F Inner States of the Data
Encryption Standard (DES) you can find weak DES keys.
Theorem 5.22 The complete fixed point property of all m is valid for every e =
j · lcm ( p − 1, q − 1) + 1, where j = 0, 1, 2, 3, 4, ... to e ≤ φ (n ).
Starting with j = 12, it holds: e = 12 · lcm (12, 36) + 1 = 432 + 1 = 433 > 432 =
φ (n ).
Checking the same four values for m as in the example 1 above, but now with
e = 217, the results are:
4217 mod 481 = 4
6217 mod 481 = 6
7217 mod 481 = 7
480217 mod 481 = 480
Theorem 5.23 The number of possible values for e with m e = m mod n can be
computed by:
φ (n ) φ (n )
[Quantity e] = +1=
lcm ( p − 1, q − 1) + 1 lcm ( p − 1, q − 1)
5.17.7.4 An Empirical Estimate of the Quantity of Fixed Points for Growing Moduli
In this section, we make an empirical estimate of the quantity of fixed points for
growing moduli (here we did not use weak e as in Section 5.17.7.3).
For this, we randomly choose p and q from the six following ranges each char-
acterized by its lower and upper bound: (22 , 210 ), (210 , 220 ), (220 , 240 ), (240 , 280 ),
(280 , 2160 ), (2160 , 2320 ).
For each range, 10 attempts were made. For the exponent e, the standard value
e = 216 + 1 was always chosen. The quantity of fixed points for all 60 attempts
was computed with SageMath Example 5.36.
Figure 5.16 shows that the average number of fixed points was not greater than
40 in any of the six size ranges.
i i
i i
i i
Figure 5.16 An empirical estimate of the quantity of fixed points for growing moduli.
5.17.7.5 Example: Determine All Fixed Points for a Specific Public RSA Key
The exercise is to determine all fixed points for (n, e) = (866959, 17).
Solution:
We start by factoring n: 866959 = 811 · 1069.
The quantity of RSA fixed points results from Theorem 5.18:
(gcd ( p − 1, e − 1) + 1) · (gcd (q − 1, e − 1) + 1) = (gcd (811 − 1, 17 − 1) + 1) ·
(gcd (1069 − 1, 17 − 1) + 1) = (2 + 1) · (4 + 1) = 15
SageMath Example 5.36 generates the 15 fixed points for (n, e) = (866959, 17)
shown in Table 5.18.
Sample validating the fixed point property for m = 843441: 84344117
mod 866959 = 843441.
So m = 843441 is actually a fixed point for the given public key (n, e).
SageMath Example 5.36: Determine All Fixed Points for a Specific Public
RSA Key
print ("\n# CHAP05 -- Sage -Script -SAMPLE 170: =========")
print("--- Search for fixpoints in textbook RSA given p, q, e ---")
import numpy
i i
i i
i i
fp=numpy.array ([0])
fq=numpy.array ([0])
n=p*q
print (" Prime p:", p)
print (" Prime q:", q)
print (" Modul n:", n)
print (" Public exponent e:", e)
r=Integers(p)
gen_f_p = r. multiplicative_generator (); print ("\ nGenerator of f_p:", gen_f_p)
s=Integers(q)
gen_f_q = s. multiplicative_generator (); print (" Generator of f_q:", gen_f_q)
gcd_p = gcd(e-1,p-1)
gcd_q = gcd(e-1,q-1)
print ("\ ngcd(e-1,p-1):", gcd_p)
print ("gcd(e-1,q-1):", gcd_q)
print (" Number of fixpoints :", (gcd_p+1)*( gcd_q+1))
print ("\ nFixpoints for the public RSA key (n,e) = (%d, %d):" % (n, e) )
for r in fp:
for s in fq:
print(crt(Integer(r),Integer(s),Integer(p),Integer(q)))
print ("\ nRemark: You can verify each fixpoint with power_mod(m,e,n).")
• gen_f_p = r.multiplicative_generator()
r is a residue class ring modulo p, and multiplicative_generator()
returns a generator element that was created by the ring modulo p.
• power_mod(gen_f_p,Integer(i*(p-1)/gcd_p),p)
The power_mod function raises a number m to the power of e, and returns
the results modulo n.
Sample: power_mod(m,e,n) := m^e modulo n
• numpy.append(fp,power_mod(gen_f_p,Integer(i*(p-1)/gcd_p),p))
Die append function extends an array f p by an additional element.
• crt(Integer(r),Integer(s),Integer(p),Integer(q))
CRT is the acronym for the Chinese remainder theorem. crt(r,s,p,q)
solves the congruences x ≡ r mod p and x ≡ s mod q with the help of
the CRT.
i i
i i
i i
References
i i
i i
i i
i i
i i
i i
i i
i i
i i
CHAPTER 6
CHAPTER 6
The Mathematical Ideas Behind
Modern Asymmetric Cryptography
301
i i
i i
i i
Each subscriber T to the system is assigned a key pair: a private key dT and a
public key eT . These keys must have the following property (public-key property):
• The class P: This class contains those problems that can be solved in a
polynomial amount of time.
• The class NP: The definition of this class doesn’t look at the time required
to solve a problem, but rather at the time required to verify a given solu-
tion. The class NP consists of those problems for which a given solution
can be verified in a polynomial amount of time. Hereby, the term NP “non-
deterministic” means polynomial and is based on a calculation model (i.e.,
on a computer that only exists in theory and can guess correct solutions
nondeterministically then verify them in polynomial time).
i i
i i
i i
property of the class NP is that it also contains what are known as NP-complete
problems. These are problems that represent the class NP as follows: If a “good”
algorithm for such a problem exists, then “good” algorithms exist for all prob-
lems from NP. In particular, if P only contained one complete problem (i.e., if a
polynomial solution algorithm existed for this problem), then P would be equal
to NP. In this sense, the NP-complete problems are the most difficult problems
in NP.
Many cryptographic protocols are formed in such a way that the “good” sub-
scribers only have to solve problems from P, whereas a perpetrator is faced with
problems from NP.
Unfortunately, we do not yet know whether one-way functions actually exist.
However, we can prove that one-way functions exist if and only if P 6= NP [1,
p. 63].
Some mathematicians have again and again claimed to have proven this
equivalence, but so far the claims have always turned out to be false [2].
A number of algorithms have been suggested for public-key procedures. In
many cases—although they at first appeared promising—it was discovered that
they could be solved in polynomial time. The most famous failed applicant is the
knapsack with trapdoor suggested by Ralph Merkle [3]. Also see Section 11.8.1.
(2) g ≡ wg 0 mod m ;
(3) ai ≡ wai0 mod m for all i = 1, . . . , n.
i i
i i
i i
Comment:
Congruent 0-1 knapsack problems have the same solutions. No quick algorithm is
known for clarifying whether two 0-1 knapsack problems are congruent.
i i
i i
i i
6.3 Decomposition into Prime Factors as a Basis for Public-Key Procedures 305
n
( j)
X
( j)
g := xi bπ (i )
i =1
and sends g ( j ) , ( j = 1, 2, . . . ).
The owner of the key calculates
( j) ( j)
and obtains the xµ(i ) ∈ {0, 1} (and thus also the xi ) from
n n
( j) ( j)
X X
G( j) ≡ w̄g ( j ) = xi bπ (i ) w̄ ≡ xi aπ (i ) mod m
i =1 i =1
n n
( j) ( j)
X X
= xµ(i ) aπ (µ(i )) = xµ(i ) ai mod m
i =1 i =1
In 1982, Shamir [5] specified an algorithm for breaking the system in polyno-
mial time without solving the general knapsack problem. Len Adleman [6] and
Jeff Lagarias [7] specified an algorithm for breaking the twice iterated Merkle-
Hellman knapsack encryption procedure in polynomial time. Ernst Brickell [8] then
specified an algorithm for breaking multiply iterated Merkle-Hellman knapsack
encryption procedures in polynomial time. This made this procedure unsuitable as
an encryption procedure. It therefore delivers a one-way function whose trapdoor
information (defamiliarization of the 0-1 knapsack problem) could be discovered
by an eavesdropper.
Primes form the basis for numerous algorithms for public-key procedures.
i i
i i
i i
You can gain practical experience with the RSA procedure in CT under:
• CTO has two broad plugins for RSA:
◦ Via “RSA (Step-by-step)” https://www.cryptool.org/en/cto/rsa-
step-by-step.
◦ Via “RSA visual and more” kb=https://www.cryptool.org/en/cto/
rsa-visual you can see with graphics how RSA assigns its input values
when encrypting, you can test textbook RSA with big numbers, and also
use RSA with OAEP, padding, and certificates as it is used in practice.
• Using CT1 Indiv. Procedures F RSA Cryptosystem F RSA Demonstra-
tion.
• Using CT2 Templates F Mathematics F RSA with big numbers and fur-
ther RSA templates in CT2.
• Using JCT Default Perspective F Visuals and JCT Algorithm Per-
spective.
ed ≡ 1 mod φ ( N )
Public key: N, e
Private key: N, d
i i
i i
i i
6.3 Decomposition into Prime Factors as a Basis for Public-Key Procedures 307
|{x < 24 : gcd(x, 24) = 1}| = |{1, 5, 7, 11, 13, 17, 19, 23}|.
SageMath Example 6.1 shows how to get these values via SageMath and how to
create the graphics for the Euler phi function (Figure 6.1).
SageMath Example 6.1: Phi and the List of Coprime Numbers via SageMath
sage: n=24; philist =[i for i in range(n) if gcd(n,i) == 1];
print('n =', n, '; Len =', euler_phi(n), '; List =', philist)
n = 24 ; Len = 8 ; List = [1, 5, 7, 11, 13, 17, 19, 23]
i i
i i
i i
Further formulas for the Euler phi function are in Section 5.8.2.
The function enc is a one-way function whose trapdoor information is the
decomposition of N into primes.
At the moment, no algorithm is known that can factorize two prime numbers
sufficiently quickly for extremely large values (e.g., for several hundred decimal
places). The quickest algorithms known todayp [10] factorize a compound integer
N in a time period proportional to L ( N ) = e ln( N ) ln(ln( N )) . Some example values
can be found in Table 6.2.
To this date, it has not been proved that the problem of breaking RSA is equiv-
alent to the factorization problem. Nevertheless, it is clear that the RSA procedure
will no longer be safe if the factorization problem is solved.
i i
i i
i i
Private key: ( p, q )
Decryption:
q
dec( y ) = y + B 2 /4 − B /2 mod n
Note that the encryption function is not injective: If doing the decryption, for
each ciphertext value you get exactly four different plaintext values that have eT (x )
as inverse image: x, −x − B, ω(x + B /2) − B /2, −ω(x + B /2) − B /2 where ω is
one of the four roots of unity.
Backdoor information is the decomposition into prime numbers of n = pq.
eg : k −→ y := g k mod p, 1 ≤ k ≤ p − 1.
The inverse function is called a discrete logarithm function logg ; the following
holds:
logg (g k ) = k.
It is much more difficult to calculate the discrete logarithm than to evaluate the
discrete exponential function (see Section 5.9). Table 6.3 lists several procedures
for calculating the discrete logarithm and their complexity [10].
From the CrypTool Variants, you can try CT2 Templates F Mathematics F
Discrete Logarithm or JCT Default Perspective F Visuals F Shanks
Babystep-Giantstep. The baby-step giant-step algorithm computes the discrete
logarithm or order of an element in a finite abelian group. The algorithm is based
on a space-time trade-off. Although the algorithm is superior to nonely trying out all
possibilities concerning the runtime, it is still not practicable for very large groups.
i i
i i
i i
In February 2007, the group Kleinjung, Franke, and Bahr at the University
of Bonn set the then-record for calculating discrete logarithms. They calculated the
discrete logarithm modulo a 160-digit (530-bit) prime number p and a generator g:
p = b10159 π c + 119849
= 314159265358979323846264338327950288419716939937510582097494
459230781640628620899862803482534211706798214808651328230664
7093844609550582231725359408128481237299
g=2
More precisely, the discrete logarithm k of the following integer y—the first
159 digits of the Euler number e—was determined:
y = b10159 ec
= 271828182845904523536028747135266249775724709369995957496696
762772407663035354759457138217852516642742746639193200305992
1817413596629043572900334295260595630738
k = logg ( y ) mod p
= 829897164650348970518646802640757844024961469323126472198531
845186895984026448342666252850466126881437617381653942624307
537679319636711561053526082423513665596
The search was performed with GNFS method (index-calculus) and took about 17
CPU years on 3.2 GHz Xeon machines.
The current record (as state of November 2021) considering integers modulo p
as the finite cyclic group G was on December 2, 2019 by Fabrice Boudot, Pierrick
Gaudry, Aurore Guillevic, Nadia Heninger, Emmanuel Thomé, and Paul Zimmer-
mann [12]. They computed the discrete logarithm modulo the 240-digit (795-bit)
prime RSA-240 + 49204 (the first safe prime above RSA-240), using the number
field sieve algorithm and the open-source software CADO-NFS.
i i
i i
i i
you cannot avoid exchanging secrets without encrypting them. Transmission safety
here must be achieved using noncryptographic methods. We say that we need a
secret channel for exchanging secrets. This channel can be realized either physically
or organizationally.
What is revolutionary about modern cryptography is, among other things, that
you no longer need secret channels: You can agree on secret keys using nonsecret
(i.e., public) channels.
One protocol that solves this problem is that of Diffie and Hellman (Crypto
Procedure 6.5).
This exchange protocol has been visualized, and you can execute the single
steps with specific numbers in:
• CT1 Indiv. Procedures F Protocols F Diffie-Hellman Demonstration
• JCT Default Perspective F Visuals F Diffie-Hellman Key Exchange (EC)
Public key: p, α, β
Private key: a
i i
i i
i i
Encryption: enc(x, k ) = ( y1 , y2 )
where y1 = α k mod p
and y2 = xβ k mod p
with
g k := g ◦ . . . ◦ g .
| {z }
k times
Lemma
The power g k can be calculated in at most 2 log2 k group operations.
Proof
Let k = 2n + kn−1 2n−1 + · · · + k1 2 + k0 be the binary representation of k. Then
n ≤ log2 (k ), because 2n ≤ k < 2n +1 . k can be written in the form k = 2k 0 + k0 with
k 0 = 2n−1 + kn−1 2n−2 + · · · + k1 . Thus,
0 0
g k = g 2k +k0 = (g k )2 g k0 .
0
We therefore obtain g k from g k by squaring and then multiplying by g. The claim
is thus proved by induction to n.
i i
i i
i i
Proof
If g jn = hg −i , that is h = g i + jn , then the problem is solved. If the lists are disjoint,
then h cannot be represented as g i + jn , i, j ≤ n. As all powers of g are thus recorded,
the logarithm problem does not have a solution.
If |G| contains a dominant prime factor p, then the complexity of the logarithm
problem is approximately
√
O ( p ).
i i
i i
i i
Public key: α, β
Private key: a
Encryption: enc(x, k ) = ( y1 , y2 )
where y1 = α k
and y2 = x ◦ β k
Earlier in Sections 5.10 to 5.12 and also in Section 6.3.1 the RSA algorithm was
discussed. We will now introduce the RSA plane.
The RSA plane is a model for illustrating the math behind the RSA algorithm
by geometrical means: If the RSA modulus equals n = pq we use rectangles with
sides p and q, and inside these rectangles we obtain a two-dimensional arrangement
of the integers from 0 to n − 1, the numbers becoming points or little squares as in
the figures on the following pages.
Although RSA has been known for a long time and the mathematical context
on which RSA is based on is not very sophisticated, there is no description of RSA
in our two-dimensional model in the literature, at least as far as we know.
You don’t have to know what a ring is; it suffices to know that computing “modulo
n” takes place in such a ring, usually denoted by Zn .
i i
i i
i i
This then corresponds to a set of points of the plane enclosed by a rectangle, which
results in a two-dimensional arrangement of the elements. This is why we use the
terms “RSA-2D” and “RSA plane.” We mention that the RSA plane is not a plane
in a strict mathematical sense. More on that in Section 6.5.2.
The isomorphism π from Z n to Z p × Z q (with p 6= q as before) is defined by:
( )
Zn → Z p × Zq
π:
z 7 → (x, y ) := (z mod p, z mod q )
For p = 11 and q = 7 the image of; for example, 23 is π (23) = (1, 2), because when
dividing 23 by 11 it has remainder 1 and when dividing 23 by 7 it has remainder 2.
Figure 6.3 shows this example for p = 11 and q = 7: Following the blue line
that starts at the point (0, 0) and then first goes to the top right, it’s easy to see how
π maps the numbers from 0 to n − 1 (in our case n − 1 = 76) step by step onto the
points (x, y ) of the rectangle.
i i
i i
i i
We define the finite plane as the set of all points (x, y ) whose coordinates are
elements of a finite field K . As usual, we associate a two-dimensional vector space
with this plane. That means that we use vectors for describing, for example,the
way from the origin (0, 0) to the point (2, 3). In vector notation this would be 2
3
using a column style, whereas points are written in row style. In geometry, points
and vectors are not the same objects, which is why we use the term associated.
Vectors are used because one cannot do computations with points; for example, it
isn’t possible to add them (that’s actually not always true: It is indeed possible to
define an addition on points of an elliptic curve, see Section 8.5).
Vectors, on the contrary, can be added in the way it is known from school
mathematics. The main difference of addition in finite vector spaces, compared
with infinite ones, is that when adding the same vector repeatedly one has to end
up with the zero vector at some point because of the finite field from which the
coordinates of the vector are taken from. It is known from algebra that finite fields
are either equal to Z p for a prime p or that they contain Z p as a subset.
Remark: To be exact, instead of using the term “equal” to Z p we should use the
term “isomorphic” because the elements of a finite field are not always denoted by
the “symbols” {0, 1, 2, . . . }. Sometimes variables are used; for example, e instead
of 1 or for a multiplicative generator. The same is true for the subset: To be more
exact, we should say: They contain a subset that is isomorphic to Z p .
i i
i i
i i
The number of elements in such a field is then always equal to a prime power
p N for some N ∈ N. The prime p controls the behavior of the addition: For an
arbitrary element x from such a field the sum |x + x +
{z· · · + x} must be equal to 0.
p−times
This is a property of all finite fields with p N elements. The number p is called the
characteristic. For more about the characteristic, see Section 8.3.2.
For comparing finite planes with RSA planes restricting N to N = 1 is sufficient.
In this case we can think of the finite plane as a square, similar to the RSA plane.
The difference is that the model for the RSA plane is a rectangle but not a square
with two sides of equal length. The two-dimensional vector space that corresponds
to a finite plane is written as Z2p or Z p ×Z p , the same way as R2 = R×R. Remember
that the notation: Z2p is the two-dimensional vector space over the field Z p (with p
elements), whereas Z p2 is the field with p 2 elements. Unfortunately, the notations
used in mathematics in this context are somewhat inconsistent. For instance, Z N is
usually used for the additive group of integers modulo N but also for the ring if not
only addition but also multiplication is under consideration. In the special case of
N = p for a prime p this ring is also a field and then one uses F p or GF( p ) rather
than Z p . Finite fields are also called Galois fields, hence GF. The notion Z p is also
used for the p-adic numbers, which contain the integers Z as a subset and don’t
form a finite set. The p-adic numbers are not of interest in this book.
We are using Z p and not F p for the fields with p elements.
i i
i i
i i
Figure 6.4 The line y = x in the plane over the field Z 11 with p = q = 11.
i i
i i
i i
Figure 6.5 The line y = 6x + 2 in the finite plane over the field Z11 .
Since we are in Z p and p is prime, the k−fold multiple of every nonzero vector
for k < p is different from the zero vector. Therefore, we can conclude that every
line of a finite plane has exactly p points.
{(x, y ) ∈ Z p × Zq : y = x, x ∈ Z p }
is a subset of the RSA plane with p elements; see Figure 6.6. We call the structure
that is formed by this set an RSA line or just line. Formally we should write the
RSA line more precisely like this:
{(x, y ) ∈ Z p × Zq : y ≡ x (mod q ), x ∈ Z p }
i i
i i
i i
Our first interesting observation is that the linear equation y = x has two
different solutions in the (11, 7)-plane for some of the possible y values, which is
not possible in a finite plane over a field. When choosing examples with p > q and
in the case p = 11 and q = 7 additionally p < 2q, then the equation y = x has
two solutions for p − q = 4 of the possible 7 y−values. In the case of p > 2q there
would be several solutions for every y, so just think of the pattern in Figure 6.6
extended to the right.
The vertical lines are a special case: They have exactly q points whereas all
oblique lines consist of p points.
In Figure 6.7 one can see the analogon to Figure 6.5, the RSA line y = 6x + 2.
This line has slope −1 since the number 6 is congruent to −1 modulo 7, resulting
in the pattern “one to the right and one down.”
There’s another interesting difference between the situation in Z p × Z p (finite
plane) and the situation in Z p × Zq (RSA plane; as before p 6= q) that we want
to look at: The length of the series of points that we pass through if we repeatedly
move one to the right and one up. In the case of the square one comes back to the
starting point after p steps like in Figure 6.6. In the case of the rectangle one passes
all n = p · q points before getting back to the starting point. Figure 6.3 shows
this behavior, beginning in (0, 0), then passing through all points until arriving at
number 76 or (10, 6). Compared to the finite plane, in the RSA plane case one
passes n = p · q points and not only p before closing the loop.
i i
i i
i i
Figure 6.7 The RSA line y = 6x + 2 in the RSA plane with p = 11 and q = 7.
sentatives in blue brackets and the alternative representatives in black brackets, the
latter being positioned symmetrically to the left and right of 0.
Choosing
n the representatives
o n of Z p and Zq in othis alternative way, one has the
( p−1) p−1 (q−1) q−1
two sets − 2 ,..., 2 and − 2 ,..., 2 .
In the two-dimensional version this gives us Figure 6.9. Here all the points are
symmetrical to the p- and q-axis. In addition to that the last point when following
the line starting in the origin and moving in the direction to the upper left is not the
point (10, 6), respectively, 76 like in Figure 6.3, but (−1, −1) resp. −1.
i i
i i
i i
Figure 6.9 Rectangular two-dimensional pattern of the numbers from −38 to 38 for p = 11, q = 7, n = 77
with the origin in the center instead of in the bottom left corner.
Definition: We use the term pq-plane or RSA plane for both rectangular repre-
sentations of Z p × Zq regardless of whether the origin is in the center or bottom
left. When using specific numbers instead of the variables p and q we also write
( p, q )-plane; for example, the (11, 7)-plane for Figure 6.6.
axis elements. There are exactly p + q − 1 of them. The points not contained in the
axes are called inner points or inner elements. Figure 6.10 shows the inner points
(orange) and the axis points (violet), again for the case p = 11 and q = 7.
i i
i i
i i
Figure 6.10 Axis points and inner points of the (11, 7)-plane; the upper picture has the origin in the middle
while the lower picture has the origin in the lower left corner.
i i
i i
i i
The map f k is not 1 : 1 (or bijective) in general. The (11, 7)-plane of Figure 6.11,
for example, shows the image of f 2 consisting of all squares in Z77 . One sees that
only 24 of 77 elements of Z77 are squares, and only 15 of the 60 inner points are
squares.
Next, one observes that axis elements cannot be moved away from the axis by
f k and inner elements remain inner elements. Take for instance a point (0, y ) on the
q-axis, then the corresponding axis element in Zn is of the form pr for some r ∈ Z.
It follows that ( pr )k = p k r k ≡ 0 (mod p ) is also an axis element.
If we choose a k that is relatively prime to φ (n ), in our example (e.g., 7), then
f k is a 1 : 1 map. In this case f k is not only a map from one set to another, but
i i
i i
i i
6.5.8 Orbits
We define the notion of an orbit or a path in such a way that it intuitively fits the
geometric context. The usual group theoretic definition of an orbit would require
the introduction of the operation of a group on a set. That would lead too far here.
For a z ∈ Zn or z ∈ Z p × Zq the set hzi := {z k : k ∈ Z} is called the orbit
of z or the path of z or also the (multiplicatively) generated set, z being called the
generator. This path is finite and the number of its elements is called the length of
the orbit of z. Later we also call hzi the full orbit of z, because then we will look at
proper subsets of hzi, the so called RSA orbits (see Section 6.5.8.3).
The orbits of different z ∈ Zn are not necessarily disjoint, as can be seen in
Figure 6.12.
Remark: In group theory, orbits are defined somewhat different from our definition
here. Then they would have to be disjoint. That means their intersection would have
to be empty.
The orbits of two points are disjoint if one point is an axis point and the other
one is an inner point. The orbits of two inner points can never be disjoint since they
always contain the point (1, 1).
Figure 6.12 Orbit of 2 (top left), 3 (top right), and 17 (bottom) in the (11, 7)-plane.
i i
i i
i i
Figure 6.13 Orbits of multiples of 5 in the (7, 5)-plane: (a) Orbit of 5, (b) Orbit of 10, (c) Orbit of 15, and
(d) Orbit of 20 or 20 − 35 = −15.
have z = 5, in the second 10, in the third 15, and so forth, and in the fourth z = 20.
The next darker field then is z 2 and so on, the darkest one is the last z k that is not
yet equal to z. This must be the square with p-coordinate = 1. In Section 6.5.9 we
discuss why this is the case.
Let’s have a closer look at Figure 6.13: The length of the path shown in
Figure 6.13(a) and 6.13(b) is 6. The orbit on the top left has the generator 5 ∈ Z35
or as 2D version (−2, 0) because of −2 ≡ 5 mod 7 and 0 ≡ 5 mod 5. On the top
right the number of points in the orbit is also 6, but this time they are followed
in a different order because the generator is 10, corresponding to the point (3, 0)
because of 10 ≡ 3 mod 7 and 10 ≡ 0 mod 5.
The lower two paths shown in Figure 6.13(c) and 6.13(d) have length 1 and 2.
Of course there is exactly one path of length 3 on the p-axis since 3 divides
6 = 7 − 1 = p − 1 (see Figure 6.14). The order in which the points on the path are
run through depends on the generator.
i i
i i
i i
Figure 6.14 Orbit of 25 in the (7, 5)-plane; (a) orbit of 25, and (b) orbit of 30.
Since the order of any subgroup of a given group always divides the group
order, we have:
The length of the orbits of inner elements are divisors of φ (n ). The length of
orbits of axis elements divides p − 1 or q − 1, depending on the element being on
the p- or on the q-axis: Because the axes do not contain the element 1 or the point
(1, 1), respectively, they cannot have a path that forms a subgroup of Z∗n . But when
thinking in projections—we will investigate projections in Section 6.5.9—one can
identify the point (x, 0) with x ∈ Z∗p and (0, y ) with y ∈ Zq∗ ((x, y ) 6= (0, 0)). By
doing this, one maps 1 : 1 into a group, which implicates that the conditions on the
divisors for subgroups are also satisfied by axis elements.
From theorems about the structure of groups [13, p. 42] it is further known
that for any of the two axes there exist generators z x or z y for the two axes with
maximal length p − 1 or q − 1, respectively. Among the inner points there exists an
orbit of maximal length lcm( p − 1, q − 1). Every orbit of an inner point corresponds
i i
i i
i i
to a cyclic subgroup of Z∗n . But Z∗n itself is not cyclic. For if we assume it was cyclic,
then there would exist an element of order φ (n ) and there would also exist only one
element of order 2, and that would be x φ(n)/2 . The component Z∗p has an element
of order 2 and the component Zq∗ also has an element of order 2 because q − 1 as
well as p − 1 are even numbers. The (multiplicative) group Z∗n for n = pq always
has exactly three elements of order 2, and they are {(−1, 1), (1, −1), (−1, −1)}.
Together with (1, 1) they form a subgroup of Z p × Zq known as the Klein four
group.
We want to illustrate the connection between the divisors of φ (n ) and the
lengths of possible orbits by looking at two examples: First, the case of only a
few divisors, but also including large primes, and second, the case of many small
prime divisors, but no large ones:
In the first case all possible orbits have the following lengths:
{1, 2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 32, 36, 48, 72, 96, 144, 288}
The divisors
27 = 33 , 216 = 23 · 33 , 864 = 25 · 33 ,
54 = 2 · 33 , 256 = 28 , 1152 = 27 · 32 ,
64 = 26 , 384 = 27 · 3, 1728 = 26 · 33 ,
108 = 2 2 · 33 , 432 = 24 · 33 , 2304 = 28 · 32 ,
128 = 27 , 576 = 26 · 32 , 3456 = 27 · 33 ,
192 = 2 6 · 3, 768 = 28 · 3, 6912 = 28 · 33
do not occur as orbit lengths. These are exactly those divisors of ( p − 1)(q − 1)
with a prime power divisor of the form 2i with i ≥ 6 or 3 j with j ≥ 3. Those divide
( p − 1)(q − 1) but neither p − 1 nor q − 1. Figure 6.16 shows the orbits of 2, 5,
and 811 with length 144, 288, and 3, respectively.
i i
i i
i i
Figure 6.15 Orbits in the (83, 59)-plane: (a) Orbit of 2, (b) orbit of 60, (c) orbit of 60 multicolor, and
(d) orbit of 117.
Finally, we summarize: The orbits of the second case where there are only small
prime divisors of φ (n ) cannot be as long as in the first case where there are large
prime divisors of φ (n ).
This fact is, for example, used in the Pollard p − 1 algorithm for factoring large
numbers with only small prime divisors. We’ll come back to this in Section 6.5.11.
i i
i i
i i
Figure 6.16 Orbit of 2 (upper left), 5 (upper right), and 811 (lower) in the (97, 73)-plane.
i i
i i
i i
(∗) (∗)
( fl ◦ f k )(z ) = fl ( f k (z )) = (z k )l = z k·l = z k·l mod φ (n ) = f k·l mod φ (n ) (z )
In the case of k and l not having common divisors with φ (n ) the product kl also is
relatively prime to φ (n ). If kl is larger than φ (n ), the remainder r := kl mod φ (n )
with 0 < r < φ (n ) is also relatively prime to φ (n ). Therefore, the composition
fl ◦ f k is also a one-to-one map on the inner points.
We mention that the equalities marked with (∗) in the computation above hold
only in the finite group Z∗n . Because if z k or z k·l would be natural numbers larger
than n we would have to write · · · ≡ . . . mod n instead.
For the inverse of f k , the deciphering map, one uses the extended Euclidean
algorithm: For every k ∈ {1, . . . , φ (n )} there can be found a unique k inv ∈
{1, . . . , φ (n )} such that k · k inv ≡ 1 mod φ (n ). Then f k inv ◦ f k is the identity map
and ( f k )−1 = f k inv is the inverse map of f k .
The set of all automorphisms of Z∗n is usually denoted with Aut(Z∗n ). Note that
not every automorphism of Aut(Z∗n ) is of the form z 7→ z k .
The Chinese remainder theorem gives us
∼ Aut(Z∗ × Z∗ ),
Aut(Z∗n ) = p q
6∼ Aut(Z∗p ) × Aut(Zq∗ )
Aut(Z∗p × Zq∗ ) =
The structure of the full automorphism group of finite abelian groups is described
in the literature in, for example, https://arxiv.org/pdf/math/0605185.pdf.
For RSA we only need automorphisms that are power maps. Those form a sub-
group of Aut(Z∗n ) that will be written as A or sometimes, to avoid confusion, as An
or also AutRSA (Z∗n ). The corresponding automorphisms we call power automor-
phisms or RSA automorphisms. How many and which prime factors the number
φ (n ) has and also with which exponents they occur in p − 1 and q − 1 deter-
mines the number of possible power automorphisms of Z∗n . The following holds:
|A| = φ (lcm( p − 1, q − 1))
Now finally let’s define the notion of an RSA orbit.
i i
i i
i i
2, 4, 8, 16, 32, 64, 51, 25, 50, 23, 46, 15, 30, 60, 43, 9, 18, 36, 72, 67,
57, 37, 74, 71, 65, 53, 29, 58, 39, 1
The exponents that are relatively prime to 30 are 1, 7, 11, 13, 17, 19, 23, and 29, the
corresponding RSA orbit then contains the following φ (30) = 8 elements:
2,
51 ≡ 27 mod 77 = 128 mod 77,
46 ≡ 211 mod 77 = 2048 mod 77,
30 ≡ 213 mod 77 = 8192 mod 77,
(∗)
18 ≡ 217 mod 77 = 131072 mod 77,
72 ≡ 219 mod 77 = 524288 mod 77,
74 ≡ 223 mod 77 = 8388608 mod 77,
39 ≡ 229 mod 77 = 536870912 mod 77
with two cyclic groups of order 10 and 6. We use the standard notation C N for a
cyclic group of order N , this group being multiplicative if not told otherwise. Of
course, we have an isomorphism between (C N , ·) and (Z N , +).
∼ C2 × C5 and C6 =
Since C10 = ∼ C2 × C3 with cyclic groups of order 2, 3, and 5
we also have:
∼ AutRSA (C2 × C2 × C3 × C5 )
AutRSA (C10 × C6 ) =
The Klein four group C2 × C2 does not allow power automorphisms because auto-
mophisms map generators of cyclic subgroups to generators again. However, each
i i
i i
i i
Figure 6.17 Full orbit of 2 (upper) and RSA orbit of 2 (lower), both in the (11, 7)-plane.
C2 -component has only a single generator and therefore does not allow a mapping
to another generator of the same cyclic subgroup. This leaves:
∼ AutRSA (C2 × C2 × C3 × C5 ) =
A77 = ∼ AutRSA (C3 ) × AutRSA (C5 ).
The groups C3 and C5 have prime order, so there are no nontrivial (trivial subgroups
of any group G are always the subgroup consisting of the unit element alone and
i i
i i
i i
σ σ σ σ
2 −→ 27 −→ 249 = 219 −→ 219·7 = 213 −→ 213·7 = 2
ρ ρ ρ ρ
2 −→ 217 −→ 2289 = 219 −→ 219·17 = 223 −→ 213·17 = 2
The last of the maps in the previous list (∗) we call λ := f 29 . The map λ then is the
multiplicative inverse 2−1 = 229 of the element 2 in Z77 . From this it follows that
λ2 = f 1 = id.
We showed that {σ, σ 2 = ρ 2 , σ 3 , τ, ρ, ρ 3 , λ, id} form exactly the power
automorphism group Aut R S A (Z∗77 ), which is isomorphic to the additive group
Z2 × Z4 .
This means the enciphering of the “plaintext” 2 via RSA with the modulus 77
can only be done in seven possible ways.
Second example: n = 3097, p = 163, q = 19, p − 1 = 162 = 2 · 34 , q − 1 = 18 =
2 · 32 , φ (n ) = 2916 = 22 · 36 , lcm(162, 18) = 162.
The elements of Z3097 can have a path of the following length:
i i
i i
i i
This second example 2 was chosen similar to the preceding one (example 1) where
also φ (n ) does have only small prime divisors, here 2 and 3. We investigate the RSA
automorphism group A3097 by decomposing like in the previous example:
So for n = 3097 = 163 · 19 an RSA path has maximal length 54 and therefore every
plaintext m ∈ Zn cannot have more than 54 ciphertexts.
In Figure 6.18 we show as an example all paths of length 9 and in Figure 6.19
the corresponding RSA paths of the generating elements of those paths. The cor-
responding Table 6.4 consists of one cyclic group per row, denoted by ca , . . . cl .
The elements z i are taken from the set of representatives {0, 1, . . . , 3096} with the
generator z in the third column. For the pictures we chose the alternative set of
representatives from −(n − 1)/2 to (n − 1)/2, see Section 6.5.5. SageMath Example
6.2 produces the LaTeX code for Table 6.4.
i i
i i
i i
Figure 6.18 Paths of length 9 in the (163, 19)-plane: orbits of (a) 1996, (b) 327, (c) 2322, (d) 1600, (e) 593,
(f) 574, (g) 2911, (h) 384, (i) 1505, (j) 2987, (k) 2648, and (l) 1926.
i i
i i
i i
i i
i i
i i
# define function that returns the LaTeX source code for all the non - �
� header -rows of the table
def rows ():
orbs=parti(oi ,n)
s=''
col0=[r'$c_a$ ',r'$c_b$ ',r'$c_c$ ',r'$c_d$ ',r'$c_e$ ',r'$c_f$ ', r'$c_g$ �
� ',r'$c_h$ ',r'$c_i$ ',r'$c_j$ ',r'$c_k$ ',r'$c_l$ ']
i i
i i
i i
for i in range(len(orbs)):
zeile=LatexExpr(col0[i])+' & '+''.join(str(orbs[i][j])+' & ' for j �
� in range(oi -1))+str(orbs[i][oi -1])+LatexExpr(r'\\')+'\n '
s=s+zeile
return(s)
# define string containing LaTeX source code for defining the structure �
� and layout of the table
head=LatexExpr(r'\ begin{tabular }{@{} r')+f'*{oi}'+ LatexExpr(r'{>{$}r<{$ �
� }} @{}}\ toprule ')+'\n'
# define string containing LaTeX source code for the header line of the �
� table
row0=LatexExpr(r'&z^9&\bm{z}&\bm{z^2}&z^3&\bm{z^4}&\bm{z^5}&z^6&\bm{z^7 �
� }&\bm{z^8 }\\\ midrule ')+'\n'
# concatenate all strings for LaTeX table and append LaTeX code for �
� ending the table
table=head+row0+rows ()+LatexExpr(r'\ bottomrule ')+'\n'+ LatexExpr(r'\end{ �
� tabular }')
# ------ main: write string >>table << to file 'orbits -order9.txt ' �
� ------
filename = 'orbits -order ' + str(int(oi)) + '.txt '
with open(filename , 'w') as file:
try:
file.write(table)
print (" File '" + filename + "' created .")
except:
print (" File '" + filename + "' could not be opened .")
# after the "with" block is done , the file is guaranteed to be closed.
i i
i i
i i
If we strip away those three elements from such a cyclic group of order 9, the
remaining set of elements forms an RSA orbit consisting of all the generators of
this group of order 9.
This is illustrated in Figure 6.19. The upper part shows the union of all paths of
length 9, and the lower part shows the four subgroups of order 3 (in the upper image
(a) in black), these are exactly eight elements if the 1 (in the bottom figure (b) in
black) is excluded. Points in the upper figure with the same color—not black—form
exactly one RSA orbit of length 6.
6.5.9 Projections
Just as in the real plane {(x, y ) : x, y ∈ R}, one can also investigate projections
onto the axes in finite planes. From the point of view of linear algebra, a two-
dimensional vector space—a plane—is mapped onto a one-dimensional subspace
with a line through the origin, so this map is a linear map of rank 1. The image
of this map is the line that is projected onto, and the kernel of the map is identical
with the line through the origin that is parallel to the direction of the projection,
which must not be orthogonal to the image.
If the reader is not familiar with the terms subspace, rank, or kernel, please
consult any introduction to linear algebra, such as [14].
Because in our model only orthogonal projections are considered, we use the
short term projection instead of orthogonal projection.
The RSA plane is not a vector space in two dimensions; we already discussed
this in Section 6.5.2. As a mapping of sets the projection map can be well-defined
on the RSA plane.
The maps πx : (x, y ) 7→ (x, 0) and π y : (x, y ) 7→ (0, y ) map points onto
their shadows on the horizontal and vertical axes, so these are the two orthogonal
projections that everyone knows from elementary geometry.
Following an inner point while stepping through its path, the shadows also
follow those steps and move with the path. Vice versa, it is possible to reconstruct
from the combined paths of the horizontal and vertical shadows the path of the
point having those shadows.
We illustrate this with the example p = 19, q = 7, n = 133, z = 12.
First we show the path of 12 in Figure 6.20.
Figure 6.21 also shows the paths of the shadows.
For the path of 12 in the (19, 7)-plane, the length of the path of this inner point
is for both axes equal to the length of the projected path. But this doesn’t have to be
i i
i i
i i
i i
i i
i i
i i
i i
i i
this way; see the example of the path of 2 in Figure 6.22. It consists of 18 elements
and the path projected onto the vertical axis has only three elements.
The projection of the path of an inner point onto one of the axes not only is a
subset of the axis in question, but it inherits a part of the algebraic structure being
projected.
The algebraic structure of any path is that of a multiplicative cyclic group with
an order dividing the least common multiple of p − 1 and q − 1.
Formally, a projected path is not a multiplicative group because it does not
contain the neutral element (1, 1). But if one thinks either of just stripping away
the one coordinate which equals 0, or of replacing the 0 with 1, the image of the
projection map is identical or isomorphic to a subgroup of Z∗p or Zq∗ . Then πx or
π y are inducing a map from Z p × Zq onto Z p or Zq , respectively. For the sake of
simplicity we denote this induced map also by πx and π y .
If one composes the map π defined in Section 6.5.1 with πx or π y one then gets
Z p or Zq as image of Zn . In mathematics, such relationships are often described by
commutative diagrams like in Figure 6.23.
Before moving to the next chapter, we want to point out that there is an inter-
esting special case of RSA orbits: the fixed points. These are RSA orbits of length
1. In Section 5.17.7 one finds some information about fixed points.
Sometimes it is convenient not to look at projections onto the axes but onto the
horizontal/vertical lines through (0, 1)/(1, 0), because then we have a well-defined
group homomorphism with (1, 1) on both lines.
The definition of a homomorphism is given in Section 10.1, the chapter about
the origin of the term “homomorphic.” An isomorphism or automorphism are
special cases of homomorphisms.
In the 2D model you can think of Zq∗ as all inner points (1, y ); that is, the
vertical line without the axis point (1, 0). The second projection then has all inner
points (x, 1) as image; that is, the horizontal line without the axis point (0, 1). We
then call those two lines—without their axis point—punched lines (see Figure 6.24).
The orbit of an element of one of those lines is necessarily contained in the
corresponding line. This can be seen in a picture from before; see Figure 6.15(b)
and 6.15(c). These pictures show the path of 60 in the (83, 59)-plane. The number
60 is congruent to 1 modulo 59, so it has coordinates (60, 1).
6.5.10 Reflections
If one chooses the representation with the origin in the center, one can consider
reflections and rotations of 180◦ as one knows them from elementary geometry. The
reflections about an axis—at the horizontal as well as at the vertical axis—and their
successive execution (i.e., the point reflection or 180◦ rotation) form a group that
is isomorphic to the Klein four group. Also, the multiplicative group Z∗n contains
a subgroup isomorphic to the Klein four group, which we already addressed in
Section 6.5.8.2. Despite the isomorphism, these groups are of course fundamentally
different in our context: The reflections permute the elements of Z p × Zq , but are
not themselves elements of the RSA plane.
In mathematics, these reflections are special cases of involutions (i.e., mappings
which, executed twice in succession, yield the identity). In geometry, an involution
i i
i i
i i
i i
i i
i i
Figure 6.24 Z∗11 and Z∗7 as punched lines through (1, 1) in the (11, 7)-plane.
is usually additionally required to respect the geometric structure; that is, to map
straight lines back to straight lines and not to take a point out of a straight line and
replace it by one not on the line. If one did not specify this condition, in principle
every permutation on the given n points or numbers with order 2 would be an
i i
i i
i i
• ρ: Rotation of 180◦ σ ◦ τ = τ ◦ σ = ρ
• κ: For the sake of simplicity, we sometimes use the letter κ for any involution
from the set K ∗ := {σ, τ, ρ}. When we speak of a reflection κ about an axis,
either σ or τ is meant.
Although the question of whether there are other involutions operating on the
RSA plane apart from σ, τ , and ρ is not uninteresting, we will not pursue it here.
It should be noted that the three reflections are not automorphisms of Z∗n :
The neutral element of the multiplication, in the two-dimensional setting the point
(1, 1), leaves its place under each of the three mappings σ, τ , and ρ, which can-
not be the case for an automorphism. However, they are bijective and preserve the
partition of Zn into interior points and axis points; moreover, the origin is a fixed
point. A fixed point is called an invariant.
As with all geometric mappings, one asks about the invariants. One distin-
guishes:
i i
i i
i i
1. Single points, which remain invariant under κ, called fixed points; for
example, the origin is fixed under κ.
2. Sets with several points, which remain fixed pointwise; that is, larger sets of
fixed points. The axes of reflections are such sets.
3. Sets with several points, which remain fixed setwise, but not necessarily
pointwise; any straight line perpendicular to the axis of a reflection κ forms
such a set. Another classical example of larger sets that are fixed setwise is
the circle line {z = ei x : x ∈ R} of the complex number plane C, when the
inversion z 7→ z −1 is considered as an involution on C∗ .
4. Invariants that are not point sets but can be derived from geometric objects
that are point sets, for example, area or orientation: For triangles, for exam-
ple, there are two possible orientations, clockwise or counterclockwise; it is
reversed by reflections, but is invariant under rotations by 180◦ . In two
dimensions, the orientation can be defined with the help of the sign of the
determinant by choosing one triangle vertex as origin and writing the vec-
tors leading from this vertex to each of the other two vertices into a 2 × 2
matrix.
However, we do not consider such derived invariants here, mainly
because the RSA plane is not a plane in the strict mathematical sense (see
6.5.2) and therefore one has neither metrics nor the apparatus of linear
algebra at hand and would therefore first have to examine how one could
transfer the usual concepts such as determinant, surface content, angles,
lengths, and so forth to the RSA plane at all.
We will now classify RSA planes whether they have orbits and/or RSA orbits
that are invariant under one of these reflections. We will in Section 6.5.10.1 first
classify the full orbits and then in Section 6.5.10.2 the RSA orbits.
Inner Points
We assume the orbit of an inner point h(x, y )i is symmetric. Then it contains the
image of the point (1, 1). Depending on the existing involution, this image is equal
to the point (−1, 1), (−1, −1) or (1, −1), as can be seen in Figure 6.25.
If one of the points (−1, 1), (−1, −1) or (1, −1) lies on the path h(x, y )i, then
hxi ⊆ Z p or hyi ⊆ Zq or both must contain the element −1. Both −1 in the first
component (i.e., taken as an element of the multiplicative group Z∗p ) and −1 in the
second component (i.e., taken as an element of the multiplicative group Zq∗ ), have
order 2 as the only element in this respective group.
i i
i i
i i
Figure 6.25 Possible images of the point (1, 1) under the involutions σ , τ , or ρ.
Next, realize that a symmetric orbit can only contain exactly one of the points
{(−1, 1), (−1, −1), (1, −1)}, because orbits are cyclic subgroups of Z∗p × Zq∗ and
these can have at most one element of order two.
Let us first consider the first component x of any orbit h(x, y )i. It generates a
cyclic subgroup of Z p whose order o(x ) is a divisor of p − 1. If o(x ) is odd, the −1
is not in the path of x. Then none of the points (−1, 1) and (−1, −1) are contained
in the orbit h(x, y )i and thus for odd o(x ) the reflections σ and ρ are already ruled
out. Of course, the same reasoning applies to the second component y or o( y ).
Since o((x, y )) = lcm(o(x ), o( y )), an orbit of odd length can have neither axis nor
point symmetry.
Theorem 6.3 A necessary condition for the symmetry of an orbit is that the order
of the element which generates it is even.
We now decompose the numbers p − 1 and q − 1 into an even and an odd part:
p − 1 = 2a · c and q − 1 = 2b · d,
where a and b are positive integers and c and d are odd. Since p and q are odd,
p − 1 and q − 1 are even and therefore a and b positive.
Moreover, let u be a generating element of Z∗p and v a generating element of Zq∗ .
Thus, for the pair (x, y ) there are exponents r and s (these exponents are unique if
one requires that they are divisors of p − 1 or q − 1 respectively) such that:
x = ur , r p−1
y=v , s
s q −1
p−1 2a · c
o( x ) = = := 2α · γ , γ odd, α ≥ 0
r r
i i
i i
i i
q −1 2b · d
o( y ) = = := 2β · δ, δ odd, β ≥ 0
s s
o((x, y )) = lcm(o(x ), o( y )) = lcm(2α γ , 2β δ )
(x, y ) = (u r , v s )
This element is different from (1, 1) and is of order 2 in Z∗p × Zq∗ . The same power
applied to the individual components also yields an element of order 2, but in Z∗p
and Zq∗ , respectively: Z∗p or Zq∗ :
m−1 ·tγ 0 δ 0
0 2m−1 ·γ
= xδ
m−1 ·w
x2 = x2
m−1 ·tγ 0 δ 0
0 2m−1 ·δ
= yγ
m−1 ·w
y2 = y2
Since o(x ) and δ 0 are coprime, x and x δ have the same order in Z∗p . If (x δ )2 ·γ
0 0 m−1
was already equal to 1, the element x δ and hence x would have an order equal to
0
i i
i i
i i
in ρ (h(x, y )i), then (x, y )k 6= (−1, −1) · (x, y )l for all l ∈ Z. However, since an orbit
is a group and equations are uniquely solvable in groups, there exists some l ∈ Z
that solves the equation (x, y )k = (−1, −1) · (x, y )l . Thus, we have shown:
Theorem 6.4 Let n ∈ N be a product of different odd primes p and q and let (x, y )
be a point of the RSA plane associated with an element z ∈ Z∗n via the Chinese
remainder theorem. Further, let 2a and 2b be the respective maximal powers of two
occurring as divisors of p − 1 and q − 1, respectively; that is, p − 1 = 2a · c and
q − 1 = 2b · d with c and d odd. Then the following is true:
Let us briefly consider the example of the (11, 7)-plane, which we took up
before. Because of 11 − 1 = 10 = 2 · 5 and 7 − 1 = 6 = 2 · 3, α from point 3
of Theorem 6.4 can only be equal to 1. Then for point-symmetric orbits there are
exactly the following combinations of possible element orders of the components x
or y:
o( x ) o( y ) o((x, y ))
2 2 2
2 6 6
10 2 10
10 6 30 = lcm(10, 6)
Figure 6.26 shows the corresponding picture for the element of order 30, namely
the 17.
The 17 corresponds to the point (6, 3) = (−5, 3) in the (11, 7)-plane. The order
of 6 in Z11 is in fact 10 and the order of 3 in Z7 is 6:
i i
i i
i i
9 : 2 1 : 3
10 : 1 2 : 2
3 : 6
sage: for i in range(7):
4 : 4
....: print(i,":",3^i%
5 : 5
....:
6 : 1
0 : 1
For (−1, 3), which corresponds to element 10 in Z77 , Figure 6.27 shows on
the top the associated path of length 6. The point (−5, −1), which corresponds
to element 6 in Z77 , has a path of length 10, as can be seen in Figure 6.27 on the
bottom. The point (−1, −1) has the trivial, always existing path of length 2, which
consists of (−1, −1) and (1, 1) (not shown in the figure, because it is trivial).
Case 3: o(x ) = 2α · γ , o( y ) = 2β · δ, α > β ≥ 0
In this case, the orbit of (x, y ) contains the element (−1, 1) and is symmetric with
respect to the vertical axis. Similar to case 2, for each pair (2α , 2β ) with α > β ≥
0 and α ≤ a, β ≤ b, one can choose elements x, y of order o(x ) = 2α · γ and
o( y ) = 2β ·δ (γ and δ odd), respectively, which thus produce a symmetric orbit with
respect to one of the two axes. This then has length lcm(o(x ), o( y )) = 2α ·lcm(γ , δ ).
Elaborated proofs of this can be found in [16].
Case 4: o(x ) = 2α · γ , o( y ) = 2β · δ, 0 ≤ α < β
Here you have symmetry about the horizontal axis, you argue analogous to case 3.
Axis Points
If we consider the horizontal axis, it is pointwise fixed by τ ; that is, τ reduced to
this axis, is the identical mapping. Moreover, ρ and σ have the same action when
restricted to the horizontal axis, so it is sufficient to speak of symmetry, since there is
no difference between point and axis symmetry in this case. The path of an element
(x, 0) on the horizontal axis is symmetric if and only if the order of x is even. So,
again, for every even divisor t of p − 1, one can choose an element of order t and
i i
i i
i i
Figure 6.27 Point symmetric orbits of 10 (upper) and 6 (lower) in the (11, 7)-plane.
then construct a symmetric orbit of length t with it. The same is true for the vertical
axis with elements of the form (0, y ) and even divisors of q − 1. This can be read
in more detail in [16].
Theorem 6.5 The RSA orbit of an inner point (x, y ) ∈ Z∗p × Zq∗ is symmetric with
respect to a given reflection if and only if the full orbit of (x, y ) is symmetric with
respect to that reflection and the order of (x, y ) is a multiple of 4.
The RSA orbit of an axis point (x, 0) ∈ Z∗p × Zq∗ (different from the origin
(0, 0)) is symmetric if and only if the full orbit of (x, 0) is symmetric and the order
of x in Z∗p is a multiple of 4.
For (0, y ) the same is true, but the order of y of course has to be the order
in Zq∗ .
i i
i i
i i
Table 6.5 Partition of the (11,7)-Plane into Disjoint Nonsymmetric RSA Orbits
1 orbit: {1} 13 orbit: {17, 19, 24, −37, −25, −16, −9, −4}
2 orbit: {2, 18, 30, −38, −31, −26, −5, −3} 14 orbit: {20, 27, −29, −8}
3 orbit: {3, 5, 26, 31, 38, −30, −18, −2} 15 orbit: {21}
4 orbit: {4, 9, 16, 25, 37, −24, −19, −17} 16 orbit: {22}
5 orbit: {6, 13, −36, −15} 17 orbit: {23, −10}
6 orbit: {7, 28, 35, −14} 18 orbit: {32, −12}
7 orbit: {8, 29, −27, −20} 19 orbit: {33, −11}
8 orbit: {10, −23} 20 orbit: {34}
9 orbit: {11, −33} 21 orbit: {−34}
10 orbit: {12, −32} 22 orbit: {−22}
11 orbit: {14, −35, −28, −7} 23 orbit: {−21}
12 orbit: {15, 36, −13, −6} 24 orbit: {−1}
These correspond to the following points, respectively:
1 orbit: {(1, 1)}
2 orbit: {(2, 2), (−4, −3), (−3, 2), (−5, −3), (2, −3), (−4, 2), (−5, 2), (−3, −3)}
3 orbit: {(3, 3), (5, −2), (4, −2), (−2, 3), (5, 3), (3, −2), (4, 3), (−2, −2)}
4 orbit: {(4, −3), (−2, 2), (5, 2), (3, −3), (4, 2), (−2, −3), (3, 2), (5, −3)}
5 orbit: {(−5, −1), (2, −1), (−3, −1), (−4, −1)}
6 orbit: {(−4, 0), (−5, 0), (2, 0), (−3, 0)}
7 orbit: {(−3, 1), (−4, 1), (−5, 1), (2, 1)}
8 orbit: {(−1, 3), (−1, −2)}
9 orbit: {(0, −3), (0, 2)}
10 orbit: {(1, −2), (1, 3)}
11 orbit: {(3, 0), (−2, 0), (5, 0), (4, 0)}
12 orbit: {(4, 1), (3, 1), (−2, 1), (5, 1)}
13 orbit: {(−5, 3), (−3, −2), (2, 3), (−4, −2), (−3, 3), (−5, −2), (2, −2), (−4, 3)}
14 orbit: {(−2, −1), (5, −1), (4, −1), (3, −1)}
15 orbit: {(−1, 0)}
16 orbit: {(0, 1)}
17 orbit: {(1, 2), (1, −3)}
18 orbit: {(−1, −3), (−1, 2)}
19 orbit: {(0, −2), (0, 3)}
20 orbit: {(1, −1)}
21 orbit: {(−1, 1)}
22 orbit: {(0, −1)}
23 orbit: {(1, 0)}
24 orbit: {(−1, −1)}
i i
i i
i i
Figure 6.28 Partition of the (11, 7)-plane (except the origin) into RSA orbits. None of them have any kind
of symmetry; the dark square is always the first element of the corresponding RSA orbit listed in Table 6.5.
i i
i i
i i
After these geometric examinations of the inner workings of RSA with a pure
mathematical focus, which are described nowhere else in the literature as far as
we know, we now return to something widely known among cryptographers: The
algorithm of Pollard.
Or more precisely:
• With p-coordinate = 1 is an axis point on the q-axis. These are all points
corresponding to a multiple of p in the linear model. Therefore, p divides the
number z k ! − 1 mod n in this case. Then the Euclidean algorithm produces
gcd(z k ! − 1 mod n, n ) = p.
• With q-coordinate = 1 is an axis point on the p-axis. These are all points
corresponding to a multiple of q in the linear model. Therefore, q divides
the z k ! − 1 mod n in this case. Then the Euclidean algorithm produces
gcd(z k ! − 1 mod n, n ) = q.
If p − 1 as well as q − 1 have only small prime factors, we can expect that for
the most inner points z the series z, z 2 , z 3! , z 4! , . . . will reach an element whose p-
or q-coordinate is going to stabilize on 1. The latter follows quite easily from the
isomorphism between Zn and Z p × Zq :
If π (z ) = (x, y ) = (z mod p, z mod q ), then also π (z k ! ) = (x k ! mod p, y k ! mod
q ). As soon as either p − 1 or q − 1 divides k ! for the first time, the p-coordinate
or q-coordinate of z k ! equals 1 because of z k ! ≡ 1 mod p or z k ! ≡ 1 mod q. This
follows from the fact that Z∗p is a cyclic group of order p − 1 (the same for q) in
i i
i i
i i
which the p − 1th power of any element must be equal to the unit element. In other
words, the shadow of an element path will meet 1 quite fast in most cases.
The groups Z∗p and Zq∗ are cyclic, but the number of elements of maximal order
p − 1 or q − 1 in these groups is small because φ ( p − 1) as well as φ (q − 1) are
small since p − 1 and q − 1 have only small prime divisors. So if one chooses z
arbitrarily, the order of the element π (z ) will have only small divisors—say d—of
p − 1 or q − 1. Then π (z ) will take 1 as p- or q-coordinate as soon as d|k ! is true.
To summarize, the p − 1-algorithm of Pollard for the case n = pq goes through
these steps:
We illustrate this with the example p = 97 and q = 73, which we already used
in Figure 6.16.
We have n = 97 · 73 = 7081, p − 1 = 96 = 25 · 3, and q − 1 = 72 = 23 · 32
and therefore only small prime divisors of n.
We choose z = 3 and first look at those points of the RSA plane that corre-
spond to the set {z, z 2 , z 2·3 } = {3, 9, 729}. Since π (3) = (3, 3), π (9) = (9, 9) and
π (729) = (50, 72) we are not yet finished with k = 3!; see Figure 6.30 without the
point (96, 1).
If we add the next step, we get {z, z 2 , z 2·3 , z 2·3·4 } = {3, 9, 729, 6498}. Since
π (6498) = (96, 1) we find a point lying exactly 1 above the horizontal axis, and
so (cf. step 4 from above) we are done; see Figure 6.30 with point (96, 1). Indeed,
gcd(6497, 7081) = 73.
Taking an even closer look at the orbit of 3, one has the following ordered list
with 48 = 24 · 3 elements in Z7081 :
(3, 3) (9, 9) (27, 27) (81, 8) (49, 24) (50, 72) (53, 70) (62, 64) (89, 46) (73, 65) (25, 49) (75, 1)
(31, 3) (93, 9) (85, 27) (61, 8) (86, 24) (64, 72) (95, 70) (91, 64) (79, 46) (43, 65) (32, 49) (96, 1)
(94, 3) (88, 9) (70, 27) (16, 8) (48, 24) (47, 72) (44, 70) (35, 64) (8, 46) (24, 65) (72, 49) (22, 1)
(66, 3) (4, 9) (12, 27) (36, 8) (11, 24) (33, 72) (2, 70) (6, 64) (18, 46) (54, 65) (65, 49) (1, 1)
Being projected onto the q-axis, the series π (3i ) takes the y-coordinate (or q-
coordinate) 1 every 12th time. By allowing only factorials as powers in the Pollard
i i
i i
i i
p − 1 algorithm one misses the first candidate π (312 ) = (75, 1) and the first hit is
π (323 ) = (96, 1).
i i
i i
i i
6.6 Outlook
Several other modern asymmetric methods exist. Some are presented in Chapters
Elliptic Curves (Chapter 8), Homomorphic Ciphers (Chapter 10), Lattices
(Chapter 11), Solving Discrete Logarithms and Factoring (Chapter 12), and Long-
Term Cryptographic Perspectives (Chapter 13). Elliptic curves for instance provide
useful groups for public-key encryption procedures, which offer shorter key lengths.
References
[1] Balcazar, J. L., J. Daaz, and J. Gabarr, Structural Complexity I, Berlin: Springer Verlag,
1998.
[2] Hesselink, W. H., The Borderline between P and NP, February 2001, https://www
.cs.rug.nl/∼wim/pub/whh237.pdf.
[3] Merkle, R., and M. Hellman, “Hiding Information and Signatures in Trapdoor Knap-
sacks,” IEEE Transactions on Information Theory, Vol. 24, No. 5, 1978.
[4] Kellerer, H., U. Pferschy, and D. Pisinger, Knapsack Problems, Berlin: Springer, 2004.
[5] Shamir, A., “A Polynomial Time Algorithm for Breaking the Basic Merkle-Hellman
Cryptosystem,” in Symposium on Foundations of Computer Science, 1982, pp. 145–152.
[6] Adleman, L., “On Breaking the Iterated Merkle-Hellman Public-Key Cryptosystem,” in
Advances in Cryptology, Proceedings of Crypto 82, Plenum Press, 1983, pp. 303–308.
[7] Lagarias, J.C., “Knapsack Public Key Cryptosystems and Diophantine Approximation,”
Advances in Cryptology Proceedings of Crypto 83, Plenum Press, 1983.
[8] Brickell, E. F., “Breaking Iterated Knapsacks,” in Advances in Cryptology: Proceedings of
CRYPTO’84, Vol. 196, Berlin: Springer, 1985, pp. 342–358.
[9] Rivest, R. L., A. Shamir, and L. Adleman, “A Method for Obtaining Digital Signatures and
Public-Key Cryptosystems,” Communications of the ACM, Vol. 21, No. 2, April 1978,
pp. 120–126.
[10] Stinson, D. R., Cryptography–Theory and Practice, Third Edition, Boca Raton, FL:
Chapman & Hall/CRC, 2006.
[11] Schneier, B., Applied Cryptography, Protocols, Algorithms, and Source Code in C, 20th
Anniversary Edition, Second Edition, New York: John Wiley, & Sons, 2015.
[12] NMBRTHRY Archives, https://listserv.nodak.edu/cgi-bin/wa.exe?A2=NMBRTHRY;fd
743373.1912.
[13] Lang, S., Algebra, Third Edition, Reading MA: Addison-Wesley, 1993.
[14] Lang, S., Introduction to Linear Algebra,Second Edition, New York: Springer, 1986.
[15] Hungerford, T. W., Algebra, Springer Verlag, 1974.
[16] Quade, L., “RSA Studies in a Two-Dimensional Group-Theoretic Model,” BA thesis,
Universität Siegen, 2023.
i i
i i
i i
i i
i i
i i
i i
i i
i i
CHAPTER 7
CHAPTER 7
Hash Functions, Digital Signatures,
and Public-Key Infrastructures
This chapter mainly gives a high-level overview about hash functions and their
application in digital signatures and certificates.
A hash function maps a message of any length to a bit sequence of constant size
(like 128 bit). The function value is called hash value or message digest. Outside of
cryptography, hash functions are used to quickly retrieve stored data.
We consider here only cryptographic hash functions1 fulfilling the requirements
laid out in Section 7.1.1.
They have a multitude of uses such as in message authentication codes (MACs),
pseudorandom number generators (PRNGs), digital signatures, blockchain, and
cryptocurrencies. To store password verification values or derive keys from pass-
words, special hash functions or key derivation functions (KDFs) are used, which
were created to slow brute-force searches and other guessing attacks. A current
KDF recommendation is Argon2.
361
i i
i i
i i
There are several common concepts to build hash functions; for example,
they can be based on block cipher components (like with SHA-1 and SHA-2) or
sponge functions (like with Keccak), or they can use a so-called Merkle-Damgård
construction to process an arbitrary-length message into a fixed-length output.
Figure 7.1 shows how a small change in the input (“Hello World!” becomes
“Hello World.”) drastically changes the output. This is the so-called avalanche
effect.
i i
i i
i i
The output length of the SHA algorithms was enhanced for the SHA-2 family
because of the possibility of birthday attacks: these make n-bit AES and a 2n-bit
hash roughly equivalent: 128-bit AES – SHA-256, 192-bit AES – SHA-384, 256-
bit AES – SHA-512.3
At Crypto 2004 (August 2004) this safety-feeling was disputed: Chinese
researchers published collision attacks against MD4, SHA-0, and parts of SHA-1.
This globally caused new motivation to engage in new hash attack methods.
The initially published result reduced the expected complexity for one SHA-1
collision search from 280 (brute-force) to 269 [3]. Further announcements claimed
to reduce the required effort to 263 [4] and 252 [5]. This would bring collision
attacks into the practical realm, as similar efforts have been mastered in the past
(see Section 1.2.2).
Already before Crypto 2004, the U.S. National Institute of Standards and Tech-
nology (NIST) decided to discontinue SHA-1 and to standardize new methods with
longer hash values.
So in 2008 NIST opened a competition to develop a new cryptographic hash
algorithm beyond the SHA-2 family [6]. In October 2012, Keccak was announced
as “SHA-3.”
i i
i i
i i
SHA-3 (Secure Hash Algorithm 3) was released by NIST in August 2015. SHA-
3 is a subset of the cryptographic family Keccak. This current NIST standard is
described in FIPS Publication 202.
The Keccak algorithm is based on a relatively new approach called sponge con-
struction. Given a state vector (sponge) of b bit, and a message in blocks of size
r < b. The sponge then absorbs the message blockwise into a subset of the state,
which is then transformed as a whole using a random permutation function f (this
is the inputting part). Then the result is squeezed out (outputting). This construc-
tion leads to great flexibility. For SHA-3, four instances are defined: SHA3-224,
SHA3-256, SHA3-384, and SHA3-512.
In CT2, there are 3 templates showing the Keccak component—as a stream
cipher, for SHA-3, and as a PRNG. The individual steps within the Keccak algo-
rithm are animated in detail in the Keccak component. Figure 7.2 shows the
visualization of Keccak in CT2.
Figure 7.2 SHA-3: Keccak hash function: Theta part of the permutation function f in CT2.4
i i
i i
i i
i i
i i
i i
• Message integrity: It can be checked whether the message has been changed
(en route).
An asymmetric technique is used again (see Chapter 6). Participants who wish
to generate a digital signature for a document must possess a pair of keys. They use
their secret key to generate signatures and the recipient uses the sender’s public key
to verify whether the signature is correct. As before, it must be impossible to use
the public key to derive the secret key.
In detail, a signature procedure looks like this: Senders use their message (or
document) and secret key to calculate the digital signature for the message. Com-
pared to handwritten signatures, digital signatures have the advantage that they
also depend on the document to be signed. Signatures from one and the same par-
ticipant are different unless the signed documents are completely identical. Even
inserting a blank in the text would lead to a different signature.
The document is sent to the recipient together with the signature. The recipient
can then use the sender’s public key in order to determine whether the received
document fits with the received signature. So he/she checks whether the signature
is correct. Thus, the recipient can detect any injury to the message integrity.
The procedure we just described has in practice, however, a decisive disadvan-
tage. The signature of the message (like an encryption) would be approximately as
long as the document itself. To prevent an unnecessary increase in data traffic, and
also for reasons of performance, a cryptographic hash function is applied to the
document before signing.
i i
i i
i i
Other digital signature schemes where developed exclusively for this purpose,
as the DSA (digital signature algorithm), and are not directly connected with a
corresponding encryption scheme.
The two signature methods that are probably still most frequently used, RSA
and DSA, are discussed in more detail in the following Sections 7.3 and 7.4. After
that we explain shortly how digital signatures can be used to create the digital
equivalent of ID cards. This is called public-key certification.
As mentioned at the end of Section 5.10.3, it is also possible to perform the RSA
private and public-key operation in reverse order: If H = hash (message), then
raising H first to the power of d (mod N ) and then to the power of e (mod N )
yields H again. Therefore, RSA can be used as a signature scheme.
The RSA signature S for a message hash H is created by performing the private
key operation:
S ≡ H d (mod N )
S e ≡ ( H d )e ≡ ( H e )d ≡ H (mod N )
If the result matches the message hash H , then the signature is accepted by the
verifier; otherwise the message has been tampered with, or was never signed by the
holder of d.
Figure 7.3 shows a step-by-step visualization creating RSA signatures with
CT1.6
To prevent certain attacks on the RSA signature procedure (alone or in com-
bination with encryption) it is necessary to format the hash value before doing the
exponentiation, as described in the PKCS#1 (Public-Key Cryptography Standard
#1 [7]). The fact that this standard had to be revised after several years of use can
serve as an example of how difficult it is to define cryptographic details correctly.
In August of 1991, the U.S. NIST proposed a DSA, which was subsequently adopted
as a U.S. Federal Information Processing Standard (FIPS 186 [2]).
The algorithm is a variant of the ElGamal scheme. Its security is based on the
discrete logarithm problem (see Chapter 6). The DSA public and private key and its
procedures for signature and verification are summarized in Crypto Procedure 7.1.
While DSA was specifically designed so that it can be exported from countries
regulating export of encryption software and hardware (like the U.S. at the time
i i
i i
i i
when it was specified), it has been noted [8, p. 490], that the operations involved
in DSA can be used to emulate RSA and ElGamal encryption.
i i
i i
i i
Private key
x < q (a 160-bit number)
Signing
m the message to be signed
k choose at random, less than q
r = (g k mod p ) mod q
s = (k −1 (SHA-1(m ) + xr )) mod q
Remark:
• (s, r ) is the signature.
• The security of the signature depends not only on the mathematical
properties, but also on using a good random source for k.
• SHA-1 is a 160-bit hash function.
Verifying
w = s −1 mod q
u 1 = (SHA-1(m )w) mod q
u 2 = (r w) mod q
v = (g u 1 y u 2 ) mod p ) mod q
Remark: If v = r , then the signature is verified.
Public-key infrastructure (PKI) is the term used to describe a system that issues,
distributes, and verifies digital certificates. The certificates issued within a PKI can
be used to enable computers and people in entire organizations to authenticate each
other and to secure their communication.
The aim of public-key certification is to guarantee the connection between a
public key and a user and to make it traceable for external parties. This trust anchor
is confirmed by the so-called certificate. In cases in which it is impossible to ensure
that a public key really belongs to a particular person, many protocols are no longer
secure, even if the individual cryptographic components cannot be broken.
Another area using PKIs are internet-connected devices (IoT). The cybersecurity
of IoT affects not only smart home and consumer electronics products, but also
vehicles and industrial plants. PKI is particularly suitable for the provisioning of
digital identities during production and operation.
i i
i i
i i
i i
i i
i i
step that your request needs to take through the different parts of the PKI. After
the certificate was issued, you can create and check signatures for texts or files.
Also, you can revoke your certificate. Every step is accompanied by additional
explanations and online help.
A digital certificate is nothing more than binding an email address to a public
key and is used for authentication. The term has nothing to do with the certificates
(often risky products) from the financial world or with other official documents
relating to a person.
Anyone can now use the CA’s public key to verify whether a certificate is falsi-
fied. The CA therefore guarantees with the certificate that a public key belongs to
a particular user.
This procedure is only secure as long as it can be guaranteed that the CA’s
public key is correct and that the registration process is handled seriously. For this
reason, each CA has its public key certified by another CA that is superior in the
hierarchy. In the uppermost hierarchy level (root CA) there is usually only one CA,
which of course then has no higher CA to certify its key. It must therefore transfer
its key securely in another way. In the case of many software products (such as the
Microsoft, Mozilla, or Google web browsers), the certificates of these root CAs are
permanently embedded in the program right from the start and cannot be changed
by users at a later stage. However, (public) CA keys, particularly those of the root
entity, can also be secured by means of making them available publicly (at websites
or newspapers).
i i
i i
i i
i i
i i
i i
determined by the validity models. Figure 7.6 shows how the the same topic is
implemented in CTO.10
You may notice that depending on the validity model, a signature can be eval-
uated as invalid if just the validation point of time is changed. It is astonishing that
even if the message and the corresponding signature didn’t change, you today can
get the evaluation result that the signature is valid, and tomorrow that the signature
is invalid. Especially with software signing, even signatures that become invalid in
this way are often immediately associated with malware warnings by the Windows
operating system. This is an example of counterproductive security warnings and
false awareness. The developers should include the reason for the invalidation result
in their warning to enable a user to take appropriate measures.
This is particularly relevant for contract documents, where it is often the case
that—in contrast to e-mails and SSL—the signature is subject to legal regulations,
and the verification of the signature (also called validation) can take place much
later after the signature has been created.
References
[1] Menezes, A. J., P. C. van Oorschot, and S. A. Vanstone, Handbook of Applied Cryptog-
raphy, 5th ed., Series on Discrete Mathematics and Its Application, CRC Press, 2001,
https://cacr.uwaterloo.ca/hac/.
i i
i i
i i
[2] Digital Signature Standard (DSS), Federal Information Processing Standards (FIPS) 186-4,
National Institute of Standards and Technology (NIST), Gaithersburg: U.S. Department
of Commerce, July 19, 2013, https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf;
https://csrc.nist.gov/publications/fips; https://www.nist.gov/publications/digital-signature-
standard-dss-2.
[3] Wang, X., Y. Yiqun, and H. Yu, “Finding Collisions in the Full SHA-1,” in Advances in
Cryptology-Crypto, LNCS 3621, 2005, pp. 17–36.
[4] Wang, X., A. Yao, and F. Yao, New Collision Search for SHA-1, Tech. rep., Crypto 2005,
Rump Session, 2005, https://www.iacr.org/conferences/crypto2005/rumpSchedule.html.
[5] McDonald, C., P. Hawkes, and J. Pieprzyk, “Differential Path for SHA-1 with Complexity
O(252 ),” in Cryptology ePrint Archive, 2012, https://eprint.iacr.org/2009/259.
[6] Dang, Q. H., Secure Hash Standard (SHS), Federal Information Processing Standards
(FIPS) 180-4, National Institute of Standards and Technology (NIST), Gaithersburg: U.S.
Department of Commerce, 2015, https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-
4.pdf; https://csrc.nist.gov/publications/fips.
[7] RSA Labs, PKCS #1 v2.1 Draft 3: RSA Cryptography Standard, Tech. rep., RSA
Laboratories, April 2002.
[8] Bruce Schneier. Applied Cryptography, Protocols, Algorithms, and Source Code in C., 2nd
ed., Wiley, 1996.
[9] ITU-T,“ITU-T Recommendation X.509 (1997 E): Information Technology—Open Systems
Interconnection—The Directory: Authentication Framework,” Tech. rep., International
Telecommunication Union ITU-T, June 1997.
[10] Let’s Encrypt, Let’s Encrypt Stats, https://letsencrypt.org/stats/.
i i
i i
i i
CHAPTER 8
CHAPTER 8
Elliptic-Curve Cryptography
1. We write elliptic-curve cryptography with a hyphen like public-key cryptography. In the literature this isn’t
used consistently.
2. Further information about key length comparison by Arjen Lenstra and Eric Verheul, plus more modern
evaluations can be found in the interactive BlueKrypt website [1]. Also see Figure 13.1.
375
i i
i i
i i
Figure 8.1 Prognosis of the key lengths regarded to be safe for RSA and for elliptic curves.
Figure 8.2 Comparison between signing and verification time for RSA and elliptic curves.
i i
i i
i i
have recently started standardization initiatives. While the IEEE only describes the
different implementations, the ASC has explicitly stated 10 elliptic curves and rec-
ommends their usage. The advantage of the ASC approach is that one needs only
a single byte to indicate which curve is meant. However, it is not yet clear whether
the ASC curves will become a de facto standard.
Although there is no need to replace RSA in applications running today, one
seriously should take the usage of ECC into consideration where key space is limited
[3]. Current information about the security of the RSA algorithm can be found in
Section 5.12 and in Chapter 12. Discussions about the security of ECC can be found
in Chapter 12.
Mathematicians have been researching elliptic curves for over 100 years. Over the
course of time, many lengthy and mathematically complex results have been found
and published that are connected to elliptic curves. A mathematician would say
that elliptic curves (or the mathematics behind them) are widely understood. This
research was originally purely mathematical. That is to say, elliptic curves were
investigated, for example, in the mathematical areas of number theory and algebraic
geometry, which are generally highly abstract. Even in the recent past, elliptic curves
played an important role in pure mathematics. In 1993 and in 1994, when the gaps
in the first proof have been closed, Andrew Wiles published mathematical works
that triggered enthusiasm far beyond the specialist audience. In these works, he
proved a conjecture put forward in the 1960s. To put it short, this conjecture was
concerned with the connection between elliptic curves and what are called module
forms.
What is actually interesting for many people is that Wiles’ work also proved the
famous second or last theorem of Fermat (see Section 5.2). Mathematicians spent
centuries trying to find a strict proof of this theorem. Understandably, Wiles’ proof
therefore got a good response. Fermat formulated his theorem as follows (written
in the borders of a book from Diophantus) [4]:
i i
i i
i i
therefore make it obvious that elliptic curves are generally based on highly complex
mathematics.
So much for the role of elliptic curves in pure mathematics. In 1985 Neal
Koblitz and Victor Miller independently suggested using elliptic curves in cryptog-
raphy. Elliptic curves have thus also found a concrete practical application. Another
interesting area of application for elliptic curves is for factorizing integers: The RSA
cryptographic system is based on the difficulty/complexity of finding prime factors
of an extremely large number (see Section 5.12). In this area, procedures based on
elliptic curves have been investigated and used since 1987 (see Section 8.8). There
are also prime number tests based on elliptic curves.
So, elliptic curves are used differently in the various areas: Encryption proce-
dures based on elliptic curves are based on the difficulty of the problem known as
elliptic curve discrete logarithm. The factorization of natural composite numbers n
uses the fact that numerous elliptic curves can be generated for n.
This section provides information about groups and fields. (See Section 5.7.) Didac-
tically very well-prepared introductions into elliptic curves can be found in [5] and
via the CTO plugin “Elliptic Curves” shown in Figure 8.5.
8.3.1 Groups
Because the term group is used differently in everyday language than in mathe-
matics, we will, for reasons of completeness, begin by introducing the essential
statement of the formal definition of a group:
i i
i i
i i
8.3.2 Fields
In mathematics, one is often interested in sets on which at least two (group)
operations are defined, frequently called addition and multiplication. The most
prominent are so-called fields.
A field is understood to be a set K with two operations (denoted as + and ·)
which fulfills the following conditions:
• The set K forms an abelian group together with the operation + (addition),
where 0 is the neutral element of the operation +.
• The set K \ {0} also forms an abelian group together with the operation ·
(multiplication).
• For all elements a, b, and c in K , we have c · (a + b) = c · a + c · b and
(a + b) · c = a · c + b · c (distributive law).
Fields may contain an infinite number of elements (e.g., the field of real num-
bers). They are called infinite fields. In contrast, we call a field finite, if it contains
i i
i i
i i
+ 0 1 a b · 0 1 a b
0 0 1 a b 0 0 0 0 0
1 1 0 b a and 1 0 1 a b
a a b 0 1 a 0 a b 1
b b a 1 0 b 0 b 1 a
i i
i i
i i
One can show that the order of any field is a prime power (i.e., the power of
a prime number). We can construct a field with p n elements for any given prime
p and positive integer n and denote it by G F ( p n ) or by Fnp . Here G F stands for
Galois Field to commemorate the French mathematician Galois.
Two fields that have the same number of elements cannot be distinguished in
the following sense: If K , K 0 are fields with k = p n elements, then there is a one-
to-one map ϕ : K → K 0 , that respects the arithmetic of the field. Such a map
is called an isomorphism. Isomorphic fields mathematically behave in the same
way so that it makes no sense to distinguish between them. For example, Z2 and
K 0 = {Z E R O, O N E} with zero-element Z E R O and one-element O N E are iso-
morphic. We note that mathematical objects are only defined by their mathematical
properties.
The fields G F ( p ) of prime order play a prominent role. They are called prime
fields and are often denoted by Z p . For prime fields, both additive and multiplica-
tive group are cyclic. Furthermore, each field G F ( p n ) contains a subfield that is
isomorphic to the prime field Z p .
In general, expressions of the form P = i1 ,...,in ai1 ...in x1i1 . . . xnin with i 1 , . . . , i n ∈ N
P
with coefficients ai1 ...in ∈ K are called polynomials in n variables x1 , . . . , xn with
underlying field K , if deg P := max{i 1 + · · · + i n : ai1 ...in 6= 0} is finite [i.e., the sum
has only finitely many nonzero terms (monomials)]. The sum of the exponents of
the variables of each term of the sum is at most 3, and at least one term of the sum
has a single variable with 3 as value of the corresponding exponent.
We now consider a curve given by the zeros of a polynomial F of degree 3 in 3
variables.
In cryptography, elliptic curves are a useful tool. Such curves are described as
solutions of an equation of the form
F (x1 , x2 , x3 ) = −x13 + x22 x3 +a1 x1 x2 x3 −a2 x12 x3 +a3 x2 x32 −a4 x1 x32 −a6 x33 = 0. (8.1)
i i
i i
i i
only one that contains a point with x3 = 0. For all points on the curve that are not
equivalent to (0, 1, 0), we may apply the following transformation
x1 x2
K × K × ( K \ {0}) 3 (x1 , x2 , x3 ) 7→ (x, y ) := , ∈K×K,
x3 x3
which reduces the number of variables from three to two. We note that with the
basic equation (8.1), F (x1 , x2 , x3 ) = 0 was chosen in a way that this transformation
leads to the famous so-called Weierstrass equation holds:
y 2 + a1 x y + a3 y = x 3 + a2 x 2 + a4 x + a6 (8.2)
Since all but one point (i.e., equivalence class) of the elliptic curve can be described
using (8.2), this equation is often called the elliptic equation, and its solutions
written as
E = (x, y ) ∈ K × K | y 2 + a1 x y + a3 y = x 3 + a2 x 2 + a4 x + a6 ∪ {O}.
Here, O represents the point (0, 1, 0) that is loosely speaking mapped to infinity by
the transformation (division by x3 ) that reduces the three variables to two.
In contrast to Figure 8.3 only finite fields K = G F ( p n ) are used in elliptic-
curve cryptography. The reason is that in modern communication engineering, data
processing is always based on discrete data (simply because computers accept only
discrete data).
For practical reasons, it turned out to be useful to take either G F ( p ) with a
large prime p or G F (2n ) with a (large) positive integer n. Using G F ( p ) has the
advantage of providing a relatively simple arithmetic; on the other hand, G F (2n )
allows a binary representation of each element that supports the way computers
work. Other fields like G F (7n ) do not have any of these advantages and are, thus,
not considered, although there is no mathematical reason why they should not be.
Figure 8.3 Example of an elliptic curve with the real numbers as an underlying field.
i i
i i
i i
y 2 = x 3 + ax + b (8.3)
with 4a 3 + 27b2 6= 0.
• In case of G F (2n ) the elliptic curve equation of the form
y 2 + x y = x 3 + ax 2 + b
with b 6= 0.
These conditions on the parameters a, b ensure that the elliptic equation can be used
in the context of cryptography. Formally we call such curves nonsingular.
The form (8.3) is called the standard form of the Weierstrass equation. If the
characteristic of the field is 2 or 3, we obtain 4 = 0, respectively, 27 = 0, which
means that the condition on parameters a, b collapse. Loosely speaking, this is the
reason why the transformation to the standard form does not work in these cases.
Let |E| denote the number of elements of an elliptic curve E given an underlying
field G F (k ) (for practical reasons either k = √p with p prim or k = 2n ). Then
Hasse’s theorem
√ [6] yields | |E| −√k − 1 | ≤ 2 · k. This inequality is equivalent to
k + 1 − 2 k < |E| < k + 1 + 2 k. In particular, this means that the number of
elements of an elliptic curve is approximately k (for large k).
i i
i i
i i
x3 := −x1 + x2 + λ + λ2 + a , y3 := y1 + x3 + λ(x1 + x3 )
y1 + y2
if P1 6= P2 ,
x1 + x2
λ :=
y1
x1 + if P1 = P2 .
x1
i i
i i
i i
Figure 8.5 shows a screenshot from CTO: In the GUI, a curve type can be
selected and different operations on the curve are available. In the screenshot, a
chaining is performed: First, two points P and Q are added. Then the resulting
point R is multiplied with a scalar, which leads to the point R2 . All resulting points
are again on the curve.
As mentioned in Section 8.4, we only consider elliptic curves over the finite fields
G F (2n ) or G F ( p ) (for a large prime p). This means that all parameters that describe
i i
i i
i i
the curve are taken from this underlying field. If E is an elliptic curve over such a
field and P is a point on the curve E, then we can derive for all positive integers m
{z· · · + P} .
m P := |P + P +
m times
Looking at this operation from the cryptographic point of view, it turns out to be
very interesting because of the following reason: On the one hand, one needs only
log m operations to calculate m P—one simply has to calculate P, 2 P, 22 P, 23 P,
…, write m in a binary form, and finally add all these multiples 2k P of P with
respect to the binary representation of m. On the other hand, it seems to be very
hard to find m given P and Q = m P on E. Of course, we may simply calculate
P, 2 P, 3 P, 4 P, 5 P, . . . and compare each of them with Q. But this will take as much
as m operations.
Yet there is no algorithm known that efficiently derives m given P and G. The
√
best algorithms known so far need about q operations where q is the (largest)
prime factor of p − 1, in case the underlying field is G F ( p ); here m should be
between 1 and q so that √
one needs at most log q operations to calculate m P.
q
However, the quotient log q tends to +∞ very fast for large q.
If we choose sufficiently large parameters (for example, let p be prime and at
least 160 bits long), a computer will easily be able to calculate m P (in less than a
second). The inverse problem, however, to derive m from m P and P, can (still) not
be solved in reasonable time.
This problem is known as the elliptic curve discrete logarithm problem
(ECDLP).
In elliptic-curve cryptography we formally look at points on the elliptic curve as
elements of a group with point addition + as operation. Furthermore, we use only
elliptic curves that have a sufficiently large number of points. However, in special
cases curves may be weak and not useful due to other reasons. For such special
cases the ECDLP can be much easier to solve than in the general case. This means
that one has to look carefully at the parameters when choosing an elliptic curve for
cryptographic applications.
Not useful for cryptography are a-normal (curves over Z p for which the set
E consists of exactly p elements) and supersingular curves (curves for which the
ECDLP can be reduced to the “normal” discrete logarithms in another, smaller
finite field). This means that there are cryptographically useful and nonuseful ellip-
tic curves. Given the parameters a and b, it is possible to determine whether a curve
is useful or not. In many publications one can find parameters that turned out to
be useful for cryptography. The open (scientific) discussion guarantees that these
results take into account latest research.
Given a secure curve, the time that is needed to solve the ECDLP is strongly
correlated with parameter p in case G F ( p ), respectively, n in case of G F (2n ).
The larger these parameters become, the more time an attacker needs to solve the
ECDLP—at least with the best algorithms known so far. Experts recommend bit-
lengths of 200 for p for secure curves. A comparison with the RSA modulus length
shows why elliptic curves are so interesting for applications. We note that the com-
putation effort for signing and encryption is closely related to the bit-length of the
i i
i i
i i
parameters. In addition, the initiation process (i.e., the generation of the private-
public-key-pair) becomes more complicated the larger p is. Thus, one looks for the
smallest parameters that still come along with the security required. It is remarkable
that a length of 200 bits for p is sufficient to construct a good elliptic curve that is as
secure as RSA with a 1024-bit RSA modulus (as far as we know today). In short, the
reason for this advantage of ECC lies in the fact that the best algorithms known for
solving the ECDLP need exponential time while the best algorithms for factorizing
are subexponential (number field sieve quadratic sieve or factorizing with elliptic
curves). Hence, the parameters for a cryptosystem that is based on the problem of
factorizing large integers have to be larger than the parameters for a system based
on ECDLP.
The elliptic curve discrete logarithm problem is the basis for elliptic-curve cryptog-
raphy. Based on this problem, there are different signature schemes. In order to
apply one of these, we need:
The parameters mentioned are often called domain parameters. They describe
the elliptic curve E and the cyclic subgroup of E on which the signature scheme is
based.
8.7.1 Encryption
Using elliptic curves, one can construct a key exchange protocol based on the
Diffie-Hellman protocol (see Section 6.4.2). The key exchanged can be used for
a subsequent symmetric encryption. We note that in contrast to RSA there is no
pair of private and public key that can be used for encryption and decryption!
In the notation of elliptic curves, the Diffie-Hellman protocol reads as follows:
First, both partners (A and B) agree on a group G and an integer q. Then they choose
r A , r B ∈ {1, 2, . . . , q − 1} at random, derive the points R A = r A G, R B = r B G
on the elliptic curve, and exchange them (using an insecure channel). After that,
A easily obtains R = r A R B ; B gets the same point (R = r A r B G) by calculating
r B R A = r B r A G = r A r B G = R. We note that R A , R B are easy to derive as long as r A
respectively r B are known G. However, the inverse operation, to get R A respectively
R B from r A respectively r B is hard.
Using the best algorithms known so far, it is impossible for any attacker to
obtain R without knowing either r A or r B —otherwise he would have to solve the
ECDLP.
In order to prohibit a man-in-the-middle attack, one may sign the values
G, q, R A , R B as described in Section 7.5.1.
i i
i i
i i
8.7.2 Signing
Using the DSA signature scheme, one can proceed as follows: The signing party
chooses a (nontrivial) number s ∈ Zq , which will be the private key, and publishes
q, G and R = sG. We note that s cannot be obtained from G and R sufficiently—a
fact on which the security of the signature scheme is based.
Given the message m, which should be signed, one first constructs a digital fin-
gerprint using a hash-algorithm h such that h (m ) has its values in {0, 1, 2, . . . , q − 1}.
Thus, h (m ) can be considered as an element of Zq . Then the signing party chooses a
random number r ∈ Zq and derives R = (r1 , r2 ) = r G. We note that the first com-
ponent r1 of R is an element of G F ( p n ). This component will then be projected
onto Zq (i.e., in the case of n = 1 it is interpreted as the remainder of an element of
{0, 1, . . . , p − 1} divided by q. This projection of r1 onto Zq is denoted by r̄1 . Then
one determines x ∈ Zq such that
r x − s r̄1 − h (m ) = 0.
Since R = r G, we obtain v̄1 = r̄1 (i.e., R and V coincide modulo the projection
onto Zq ).
There are factorization algorithms based on elliptic curves. The biggest factor found
by factoring compound numbers with elliptic curves (GMP-ECM) has 83 decimal
digits (state July 2023); see the ECMNET project [12]. More precisely, these pro-
cedures exploit the fact that elliptic curves can be defined over Zn (n composite
number). Elliptic curves over Zn do not form a group, because not every point on
such an elliptic curve has an inverse point. This is connected with the fact that, if n
is a composite number, there exist elements in Zn that do not have an inverse with
respect to multiplication mod n. In order to add two points on an elliptic curve over
Zn , we can calculate in the same way as on elliptic curves over Z p .
Addition of two points (on an elliptic curve over Zn ), however, fails if and only
if a factor of n has been found. The reason for this is that the procedure for adding
i i
i i
i i
points on elliptic curves gives elements in Zn and calculates the inverse elements
for these (with respect to multiplication mod n) in Zn . The extended Euclidean
algorithm is used here. If the addition of two points (that lie on an elliptic curve
over Zn ) gives an element in Zn that does not have an inverse element in Zn , then
the extended Euclidean algorithm delivers a genuine factor of n.
Factorization using elliptic curves thus principally works as follows: Random
curves over Zn are selected, as well as random points (that lie on this curve),
and added; you thus obtain points that also lie on the curve or find a factor
of n. Factorization algorithms based on elliptic curves therefore work proba-
bilistically. The opportunity of defining a large number of elliptic curves over
Zn allows you to increase the probability of finding two points that you can
add to obtain a factor of n. These procedures are therefore highly suitable for
parallelization.
Besides the web programs listed in Section 8.5.1, there are not many free didac-
tic programs offering especially ECC under a graphical user interface. Sections
8.9.1 and 8.9.2 explain shortly which corresponding functionality is available in
CrypTool and in SageMath.
8.9.1 CrypTool
CT1 offers elliptic curves for the digital signature function4 and for ECC-AES
hybrid encryption.5 Also implemented are the basic algorithms for group opera-
tions, for generating elliptic curves, and for importing and exporting parameters
for elliptic curves over finite fields with p elements ( p prime). The implemen-
tation in CT1 complies with draft number 8 of the IEEE P1363 work group
Standard Specifications for Public-Key Cryptography [14]. The point addition on
elliptic curves is visualized for two types of elliptic curves in CT1 and for 3 types
in JCT.6
Figure 8.6 shows the visualization of the point addition in JCT (the imple-
mentation in JCT is much more mature than that in CT1). Figure 8.5 shows a
visualization of elliptic curves in CrypTool-Online (CTO).
4. The dialog box in CT1 Digital Signatures/PKI F Sign Message offers the EC methods ECSP-DSA and
ECSP-NR (these Nyberg-Rueppel and DSA signatures are based on elliptic curves).
5. See CT1 Encrypt/Decrypt F Hybrid.
6. - CT1 Indiv. Procedures F Number Theory -- Interactive F Point Addition on Elliptic Curves.
- JCT Default Perspective F Visuals F Elliptic Curve Calculations.
i i
i i
i i
8.9.2 SageMath
There are many functions around elliptic curves in SageMath. See [15–20].
By Johannes Bauer there is a very nice tutorial (as of 2015) with SageMath and
OpenSSL code [15].
If the field G F (2n ) is used instead of the prime field G F ( p ), one has to make sub-
stantial changes in the implementation. The advantage of G F (2n ) lies in the fact that
calculations in G F (2n ) can be implemented very efficiently using the binary repre-
sentation. In particular, divisions are much easier to process compared to G F ( p )
(this is particularly important in the signature scheme mentioned previously where
a division is needed for processing a signature as well as for the verification).
In order to achieve maximal gain in efficiency, one may choose a field that
allows a special basis like a polynomial basis (useful for software implementations)
or a normal basis (best for hardware implementations). For special n (like, for
i i
i i
i i
example, n = 163179181) one may even combine both advantages. However, they
are still nonstandard.
Sometimes only the first component and one additional bit is used as represen-
tation of a point on the elliptic curve instead of the full two components. Since the
first component together with the additional bit is sufficient to derive the full point,
this representation minimizes the memory capacity needed. In particular, for a nor-
mal basis, this point compression can be implemented efficiently. In addition, the
cryptographic protocols themselves become more effective. A disadvantage is, how-
ever, that point compression can be used for about half of all elliptic curves only and
is protected under U.S. patent (US Patent 6141420, Certicon), causing additional
costs. In the general case G F ( p n ) (and also in case n = 1) often so-called affine or
projective coordinates are used. Depending on the application, these coordinates
may result in a gain in efficiency as well.
A comprehensive description of all implementations and their advantages and
disadvantages would go far beyond the scope of this book. We only want to state
that there is a variety of possible implementations for elliptic-curve cryptography,
much more than for RSA. Therefore, there are serious efforts to reduce this large
number of implementation to a few standard implementations. Some standardiza-
tion committees even try to reduce the complexity by focusing on some (prescribed)
curves (ASC approach).
It is still not clear whether these standardization initiatives will be successful
or not. However, without agreed standards, ECC is not likely to become a real
alternative for RSA.
References
[1] Lenstra, A. K., and E. R. Verheul, “Selecting Cryptographic Key Sizes (1999 + 2001),”
Journal of Cryptology, Vol. 14, 2001, pp. 255–293, https://www.cs.ru.nl/E.Verheul/
papers/Joc2001/joc2001.pdf.
[2] Merkle, J., Elliptic-Curve Cryptography Workshop. 2001.
[3] BSI,“Cryptographic Mechanisms: Recommendations and Key Lengths (Version 2022-
01),” Tech. rep., Technical Guideline TR-02102-1, 2022, https://www.bsi.bund.de/Shared
Docs/Downloads/EN/BSI/Publications/TechGuidelines/TG02102/BSI-TR-02102-1.pdf.
[4] Nagell, T., Introduction to Number Theory, Wiley, 1951.
i i
i i
i i
[5] Bauer, J., “ECC-Tutorial (with Python and SagemathCode),” 2015, https://www.johannes-
bauer.com/compsci/ecc/.
[6] Silverman, J.,The Arithmetic of Elliptic Curves, 2nd ed., Graduate Texts in Mathematics,
Springer, Vol. 106, 2009.
[7] Certicom, “ECC Tutorial,” https://www.certicom.com/content/certicom/en/ecc-tutorial
.html.
[8] Laubrock, T.,“Tutorial mit Java Applets – Krypto-Verfahren basierend auf elliptischen Kur-
ven,” 1999, http://www.warendorf-freckenhorst.de/elliptische-kurven/frame.html (visited
on07/26/2023).
[9] Kebekus, S., “Elliptic Curve Plotter,” https://cplx.vm.uni-freiburg.de/storage/software/
ellipticcurve/wasm/ellipticcurve.
[10] Corbellini, A., “Elliptic Curve Point Addition and Multiplication in R and Fp ,” https://an-
drea.corbellini.name/ecc/interactive/reals-add.html.
[11] Driscoll, M.,“The Animated Elliptic Curve,” https://curves.xargs.org/ (visited on
07/26/2023).
[12] Zimmermann, P., “The ECMNET Project,” 2023, https://members.loria.fr/PZimmer
mann/records/ecmnet.html.
[13] Shene, C.-K., “ECvisual,” 2012, https://pages.mtu.edu/∼shene/NSF-4/.
[14] Working Group P1363, The IEEE P1363 Home Page: Standard Specifications for Public-
Key Cryptography, https://web.archive.org/web/20150405005140/; http://grouper.ieee
.org/groups/1363/.
[15] The Sage Development Team,“Constructions: Elliptic Curves,” https://doc.sagemath.org/
html/en/constructions/elliptic_curves.html.
[16] Stein, W., “An Elliptic Curve Cryptography (ECC) Tutorial,” 2006, http://www
.williamstein.org/simuw06/notes/notes/node12.html.
[17] The Sage Development Team,“Thematic Tutorials: Elliptic Curves,” https://doc.sagemath
.org / html /en / thematic_tutorials/explicit_methods_in_number%20_theory/elliptic_curves
.html.
[18] Stein, W., “Elliptic Curves in Sage—Presentation at Microsoft Research,” 2011. url: https://
www.youtube.com/watch?v=9j_Lj071vek.
[19] De Feo, L.,“Using Elliptic Curves and Isogenies in Sage,” in Jupyter notebook, 2017,
https://defeo.lu/jupyter/notebooks/example.html.
[20] Mastermath, “Elliptic Curves,” worksheet with exercises, 2011, https://cocalc.com/share/
public_paths/9ba3432cea2b7afaa75e400a2bf7815f8c6e64ee/3701-3801%2F3755-Elliptic
%20curves.sagews.
[21] Giry, D., “BlueKrypt: Cryptographic Key Length Recommendation,” Version 32.3, May
2020, https://www.keylength.com/.
i i
i i
i i
CHAPTER 9
CHAPTER 9
Foundations of Modern Symmetric
Encryption
While number theoretic methods prevail for the construction and analysis of asym-
metric encryption algorithms, modern symmetric encryption algorithms almost
always rely on Boolean algebra, that is on the manipulation of bits. This involves
a quite different kind of mathematics and might be unfamiliar to beginners. There-
fore, in this chapter we attempt a smooth introduction into this mathematical
subject. As previous knowledge, we assume elementary mathematical notions such
as variable and function, and a small knowledge of elementary algebra and number
theory.
Nevertheless, this chapter quickly becomes very mathematical—and is more
mathematical than most of the other chapters in this book. We try to compensate
for this by elaborating on the ideas and making them comprehensible by means of
examples, so that readers can skip the mathematics and still understand the connec-
tions anyway. Extensive use is made of SageMath for this purpose. On the website
(see Section 9.4) there is quite a bit more material for deepening.
Let us start with the description on how to interpret and process bits, and how
to apply functions to them. Such functions are called Boolean functions, named
after George Boole who formalized logic by introducing the elementary logical
operations, and thereby made logic a part of mathematics (logical calculus). Most
modern symmetric ciphers, as well as hash functions, can be expressed as systems
of Boolean functions.
The focus of this chapter is on introducing the mathematical foundations of
ciphers that operate on bits. We won’t define single ciphers in detail but instead
recommend the books by Menezes/Orschot/Vanstone [1], Oppliger [2, 3], Paar and
Pelzl [4], Schmeh [5, 6], and Stamp [7].
A word on nomenclature: In the existing literature these ciphers usually are
called block ciphers or stream ciphers without the prefix “bit.” Sometimes this
usage might cause a misunderstanding since, in particular for stream ciphers,
ciphers could operate on other character sets (alphabets, letters) as their basic
units. For clarity, in case of doubt it’s better to make the “bits” explicit parts of
the notations.
The explanations in this chapter are supported by almost 20 code exam-
ples in SageMath. These are available in separate SageMath scripts of the form
chap09_sample<nnn>.sage that can be executed directly. Within them, functions
and classes written by ourselves are used, which come from the small library
bitciphers.sage which is included in the SageMath examples if necessary. See
Section 9.4.
393
i i
i i
i i
In Boolean functions, the independent variables xi can only take the values 0 and 1
and the result is 1 bit. n different independent variables can be combined in at most
n
22 different ways. If the result is a bit vector instead of one bit, one speaks of a
vector Boolean function (like an S-box in cryptography).
i i
i i
i i
Logic to Algebraic
x∨y = x+y+x·y
x∧y = x·y
¬x = 1+x
with quite different meanings like direct sum and tensor product of vector spaces.
Therefore, in this chapter we avoid them except in diagrams.
For clarification, we explicitly hint at some special aspects of algebraic calcu-
lations in the binary case (or in characteristic 2):
• Two equal summands in a sum cancel out, that is, together give 0. As a
general rule: x + x = 0, or 2x = 0.
• More generally, an even number of equal summands always gives 0 and an
odd number of equal summands gives exactly this summand. As a general
rule: (
0 for even m
m x := |x + ·{z
· · + x} =
x for odd m.
m
from three bits x1 , x2 , x3 . The mechanism inside this black box can be described
from several different points of view:
i i
i i
i i
• Mathematically by a formula;
• Informatically by an algorithm;
• Technically by a circuit (or plugging diagram);
• Pragmatically by a truth table (that is the complete lookup table of its
values).
i i
i i
i i
(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1).
We often use the abbreviation x for (x1 , . . . , xn ). This short form highlights the
fact that we consider bitblocks as objects of their own.
The 2n different bitblocks of length n are the elements of the Cartesian product
F2 = F2 × · · · × F2 . This Cartesian product has a natural structure as a vector space
n
over the field F2 ; bitblocks x and y ∈ Fn2 may be added or multiplied by scalars
a ∈ F2 :
(x1 , . . . , xn ) + ( y1 , . . . , yn ) = (x1 + y1 , . . . , xn + yn ),
a · (x1 , . . . , xn ) = (a · x1 , . . . , a · xn ).
f : Fn2 −→ F2 .
i i
i i
i i
a = x1 · 2n−1 + · · · + xn−1 · 2 + xn
f (x ) = s1 (x ) ∧ . . . ∧ sr (x )
with some index r where the s j (x ) for j = 1, . . . , r each have the form (disjunctions)
s j (x ) = t j 1 (x ) ∨ . . . ∨ t jn j (x )
i i
i i
i i
that already has the conjunctive form from Theorem 9.2 with
f 0 (x ) = (x1 ∧ x2 ) ∨ (x1 ∧ x3 )
This example doesn’t display negated input bits. However, in Table 9.4 we see some
of them.
The form of a Boolean function according to Theorem 9.2 is called conjunctive
normal form (CNF). It is not unique.1 Without further explanation we remark that
there is a further simplification as a canonical CNF that guarantees a certain unique-
ness. There is also an analogous disjunctive normal form (DNF) (a “disjunction of
conjunctions”).
i i
i i
i i
in other words it is a product of some of the variables where the subset I specifies
the choice of “some.” Here is an illustrative example with n = 3:
I = {2, 3} =⇒ x I = x2 x3 .
I = ∅ =⇒ x I = 1
where all coefficients a I are 0 or 1. In other words we add a subset of the 2n potential
n
monomial expressions, and for this we have 22 choices. All these expressions give
different Boolean functions, but we have yet to prove this. First, we must prove that
each Boolean function has a polynomial expression.
Theorem 9.3 (ANF) For each Boolean function f : Fn2 −→ F2 there are coefficients
a I ∈ F2 (that is = 0 or 1), where I runs through all subsets of {1, . . . , n}, such that
f may be written as a polynomial expression in n variables of the form:
X
f (x1 , . . . , xn ) = aI x I . (9.3)
I ⊆{1,...,n}
Proof
(Induction on n) Start with n = 1. The four Boolean functions of one variable x
are the constants 0 and 1 and the functions given by x and 1 + x (= the negation of
x). They all have the claimed form.
1
Now let n ≥ 1. For x = (x1 , . . . , xn ) ∈ Fn2 we abbreviate (x2 , . . . , xn ) ∈ Fn−
2 as
x . Then we can also write x = (x1 , x ) instead of x = (x1 , . . . , xn ).
0 0
Now take a function f ∈ Fn . For each fixed value b of the first variable x1 , the
choices being b = 0 or b = 1, we consider the function x 0 7→ f (b, x 0 ) of the n − 1
variables that x 0 consists of. By induction (for b = 0 as well as for b = 1) we know
1
f (b, x 0 ) = pb (x 0 ) for all x 0 ∈ Fn−
2
i i
i i
i i
Therefore,
(
p0 (x 0 ), if x1 = 0,
f (x1 , x ) =
0
for all x = (x1 , x 0 ) ∈ Fn2
p1 (x 0 ), if x1 = 1,
since x1 assumes the values 0 or 1 only. We combine this conditional formula into
f (x1 , x 0 ) = p0 (x 0 ) + x1 ( p0 (x 0 ) + p1 (x 0 ))
X X
= bJ x J + (b J + c J ) x 1 x J .
J ⊆{2,...,n} J ⊆{2,...,n}
| {z } | {z }
all monomials without x1 all monomials withx1
The wording of this theorem is mathematically compact. As an illustration
look at the second column of Table 9.4, where the variables are x and y instead of
x1 and x2 , and the coefficients are a, b, c, d instead of a∅ , a{1} , a{2} , a{1,2} . Each
row of the table describes a Boolean function of two variables. The corresponding
polynomial expression is the sum of the terms 1, x, y, x y that have a coefficient
1 in the representation by (9.3), whereas terms with coefficients 0 don’t show up
explicitly.
Theorem 9.3 provides a representation of a Boolean function as a polynomial
expression. This expression is called the algebraic normal form (ANF).2 The ANF
n
is unique: Since the total number of polynomial expressions is 22 , and since they
n
represent all 22 different Boolean functions, all these polynomial expressions must
differ as functions, and furthermore this representation of a Boolean function as a
polynomial expression must be unique. We have shown:
Theorem 9.4 The representation of a Boolean function in algebraic normal form
is unique.
Definition 9.2 The (algebraic) degree of a Boolean function f ∈ Fn is the degree
of its polynomial expression in algebraic normal form,
It is always ≤ n.
2. The transformation of ANF to truth table and vice versa is provided by the (internal) function
__convert() of the class BoolF(), which comes from the file bitciphers.sage. SageMath’s own module
sage.crypto.boolean_function also provides initialization by a truth table or by a Boolean polynomial,
and functions algebraic_normal_form() and truth_table() for the transformations.
i i
i i
i i
The degree indicates how many different variables maximally occur in a monomial
of the ANF.
Example Independently of the number of variables there are exactly two Boolean
functions of degree 0: the two Boolean constants 0 and 1.
Functions of degree ≤ 1 are called affine functions. They are a sum of a constant and
a Boolean linear form; see Section 9.1.9. If the degree is > 1 the function is called
nonlinear, even though the denomination “nonaffine” would be more accurate.
Remark Boolean functions have a high degree not by high powers of some variables
but only by large products of different variables. Each single variable occurs with
exponent at most 1 in each monomial of the ANF. Another way to express this fact
is to say that all partial degrees (the degrees in the single variables xi without regard
for the other variables) are ≤ 1.
i i
i i
i i
Remark The analogous form3 of the ANF for a Boolean function of three variables
x, y, z is
Example What is the ANF of the function f 0 from Section 9.1.2, written as
f 0 (x, y, z ) = x ∧ ( y ∨ z ) and using the variables x, y, z? By Table 9.4 we have
( y ∨ z ) = y + z + yz, whereas ∧ simply is the multiplication in the field F2 . Hence,
f 0 (x, y, z ) = x · ( y + z + yz ) = x y + x z + x yz,
Remark From Table 9.4 we might directly read off a naive algorithm for translating
logical expressions into (binary) polynomial expressions, and vice versa.
q
f : Fn2 −→ F2
3. In this formula, the letter f (in contrast with the common use in this text) denotes a coefficient, not a func-
tion. Mathematicians almost always use letters as symbols relative to the context, and only in exceptional
cases with an absolute meaning. Such exceptions are the numbers e, i, and π. But even i often denotes (in
contexts without complex numbers) some other object, for example an index in a sum. Or sometimes e is
used as exponent, or coefficient.
4. The distinction between the concepts of function and map is somewhat arbitrary. Mathematicians often use
them to indicate whether the values belong to a one-dimensional or multi-dimensional domain. Boolean
maps (as systems of Boolean functions) are often denoted as vector valued Boolean functions or vectorial
Boolean functions (VBF).
i i
i i
i i
q
we see that we may interpret a Boolean map to F2 as a q-tuple (or system) of Boolean
functions
f 1 , . . . , f q : Fn2 −→ F2 .
q
Definition 9.3 The (algebraic) degree of a Boolean map f : Fn2 −→ F2 is the
maximum of the algebraic degrees of its components,
q
Theorem 9.6 Each Boolean map f : Fn2 −→ F2 has a unique representation as
X
f (x1 , . . . , xn ) = x I aI
I ⊆{1,...,n}
q
with a I ∈ F2 , and monomials x I as in Theorem 9.3.
This representation of a Boolean map is also called algebraic normal form.
It results from combining the algebraic normal forms of its component functions
f 1 , . . . , f q . Compared with Theorem 9.3 the x I and a I occur in reversed order. This
follows the convention that usually scalars (here the x I ∈ F2 ) precede vectors (here
q
the a I ∈ F2 ). The a I are the q-tuples of the respective coefficients of the component
functions.
Example
Define a Boolean map g: F32 −→ F22 by a pair of logical expressions in three variables
x, y, z: !
x ∧ ( y ∨ z)
g (x, y, z ) :=
x∧z
where the components are written below each other, in column form, for clarity.
We recognize the function f 0 as the first component. The second component is the
product x · z. Hence, the ANF of g is
! ! ! !
x y + x z + x yz 1 1 1
g (x, y, z ) = = xy · + xz · + x yz · .
xz 0 1 0
The algebraic degree is 3, and the value table is in Table 9.5. Here the values
g (x, y, z ) ∈ F22 of g are written as bitstrings of length 2.
n
X
f (x ) = si xi for all x = (x1 , . . . , xn ) ∈ Fn2
i =1
i i
i i
i i
I = {i | si = 1}.
In particular there are exactly 2n Boolean linear forms in n variables, and they
correspond in a natural way to the power set P({1, . . . , n}).
Other common notations are (for I = {i 1 , . . . , ir }):
f (x ) = α I (x ) = x [ I ] = x [i 1 , . . . , ir ] = xi1 + · · · + xir .
Theorem 9.7 relates the definition with the notion of linear forms from linear
algebra:
Theorem 9.7 A Boolean function f : Fn2 −→ F2 is a linear form if and only if the
following two conditions hold:
(i) f (x + y ) = f (x ) + f ( y ) for all x, y ∈ Fn2 .
(ii) f (ax ) = a f (x ) for all a ∈ F2 and all x ∈ Fn2 .
Proof
The representation by partial sums shows that each linear form meets the two
conditions mentioned.
For the reverse direction let f be a Boolean function with (i) and (ii). Let e1 =
(1, 0, . . . , 0), …, en = (0, . . . , 1) be the canonical unit vectors. Then each x =
(x1 , . . . , xn ) ∈ Fn2 is a sum
x = x1 e1 + · · · + xn en .
Hence,
is the partial sum of the xi over the index set consisting of the i for which the
constant value f (ei ) is 1. Therefore, f is a linear form in the sense of the previous
definition.
i i
i i
i i
q
A Boolean map f : Fn2 −→ F2 is called linear if all of its component functions
f 1 , . . . , f q are linear forms. As in the case q = 1 we can show Theorems 9.8 and 9.9.
q
Theorem 9.8 A Boolean map f : Fn2 −→ F2 is linear if and only if the following
two conditions hold:
(i) f (x + y ) = f (x ) + f ( y ) for all x, y ∈ Fn2 .
(ii) f (ax ) = a f (x ) for all a ∈ F2 and all x ∈ Fn2 .
q
Theorem 9.9 A Boolean map f : Fn2 −→ F2 is linear if and only if it has the form
n
X
f (x ) = xi si
i =1
q
with si ∈ F2 .
(Here again the xi and si are written in reverse order.)
Affine (Boolean) maps are maps of algebraic degree ≤ 1. They result from
adding linear maps and constants.
In the case q = 1, that is for functions, the only possible constants are 0 and
1. Adding the constant 1 effects a logical negation, that is a flipping of all bits.
Therefore we can say the affine Boolean functions are the linear forms and their
negations.
Ax = b
x1 + 2x2 + 3x3 = 0
3x1 + 2x2 + x3 = −4
x1 + x2 + x3 = −1
i i
i i
i i
and study how to handle this in SageMath. The complete solution is in SageMath
Example 9.1. Here are the single steps:
1 2 3
1. Define the coefficient matrix A = 3 2 1.
1 1 1
2. Define the image vector b = (0, −4, 1).
3. Let SageMath calculate a solution vector x. Since we wrote the left-hand
side of the system as matrix product Ax we have to use the method
solve_right().
4. Our system of linear equations could admit several solutions. We find them
all by solving the corresponding homogeneous system Az = 0 replacing the
right-hand side b by 0. If z is a solution of the homogeneous system, then
A · (x + z ) = Ax + Az = b + 0 = b, so x + z is a solution of the original
(inhomogeneous) system. In this way we get all solutions. This is because if
Ax = b and Ay = b, then A· ( y −x ) = 0, hence the difference y −x solves the
homogeneous system. For the solution of the homogeneous system we use
the SageMath method right_kernel(). In SageMath, the default kernel of
a matrix A is the left kernel, (i.e., the space of vectors z, such that z A = 0).
Therefore, the right kernel is needed here.
5. The output appears somewhat cryptic. It says that all solutions of the
homogeneous system are multiples of the vector z = (1, −2, 1). Since all
coefficients were integers SageMath worked over Z (= Integer Ring).
6. We verify the solution y = x − 4z by checking that Ay = b.
A = Matrix ([[1,2,3],[3,2,1],[1,1,1]])
b = vector ([0 ,-4 ,-1])
x = A.solve_right(b)
print ("x = ", x)
i i
i i
i i
#------------------------------------
# CHAP09 -- Sage -Script -SAMPLE 010: =========
# x = (-2, 1, 0)
# LK = Free module of degree 3 and rank 1 over Integer Ring
# Echelon basis matrix:
# [ 1 1 -4]
# RK = Free module of degree 3 and rank 1 over Integer Ring
# Echelon basis matrix:
# [ 1 -2 1]
# vec_REBM = (1, -2, 1)
# y = (-6, 9, -4)
# A*y = (0, -4, -1)
# A*y==b : True
i i
i i
i i
From the first equation we get x6 = x1 + x3 + 1 (using the rule that plus
and minus are the same). Elimination results in a reduced system consisting of the
equations 2 to 5 (note x1 + x1 = 0, etc.):
x2 +x3 +x4 = 1
x1 +x2 +x5 = 1
x1 +x4 +x5 = 1
x2 +x4 +x5 = 1
Solving the second equation of the reduced system for x5 and substituting x5 =
x1 + x2 + 1 in the other ones gives
x2 +x3 +x4 = 1
x2 +x4 = 0
x1 +x4 = 0
Now the last two equations yield x4 = x2 = x1 , and then the first one yields
x3 = 1. Thus, the complete solution is
x1 = x2 = x4 = x6 = a with a ∈ F2 arbitrary, x 3 = 1, x 5 = 1.
Since a may assume the values 0 and 1 our result consists of exactly two
solutions: (0, 0, 1, 0, 1, 0) and (1, 1, 1, 1, 1, 1).
i i
i i
i i
#------------------------------------
# CHAP09 -- Sage -Script -SAMPLE 020: =========
# A :
# [1 0 1 0 0 1]
# [1 1 0 1 0 1]
# [0 1 1 0 1 1]
# [1 0 0 1 1 0]
# [0 1 0 1 1 0]
# x1 : (0, 0, 1, 0, 1, 0)
# K : Vector space of degree 6 and dimension 1 over Finite Field of �
� size 2
# Basis matrix:
# [1 1 0 1 0 1]
# x2 : (1, 1, 1, 1, 1, 1)
i i
i i
i i
Theorem 9.10 The number N (n ) of needed bit comparisons and bit additions
for solving a system of n Boolean linear equations with n unknowns is upper
bounded by
1
N (n ) ≤ · n · (n + 1) · (2n + 1).
6
A somewhat more sloppy wording of this result expresses the cost as O(n 3 ). In
any case it is polynomial of small degree in terms of the problem size n.
Remark The notation by “O” obscures the difference with the cost over arbitrary
fields that is generally bounded by O(n 3 ). The “felt” much better performance in
the Boolean case is partly founded by the exact estimate in Theorem 9.10 that even
in the worst case is about 13 · n 3 . Moreover, in the Boolean case we count simple bit
operations only, and not arithmetic operations or floating point instructions that
are significantly more expensive.
5. The SageMath method binary() transforms an integer to a bitstring, suppressing leading zeros. Example:
10.binary() yields '1010'.
i i
i i
i i
This might look entangled, but it simply means: Interpret x as the base-2 represen-
tation of an integer i (x ), and set f (x ) as the bit at position i (x ) from the bitblock
b. An additional column i (x ) in the truth table of the function f 0 ( f 0 was defined
in Formula 9.1) illustrates this procedure (see Table 9.7). The last column of this
table, written in row form, is the bitblock b.
In this way, the bitblock (0, 0, 0, 0, 0, 1, 1, 1) or, even more parsimoniously, the
bitstring
00000111
i i
i i
i i
with e1 (i ), . . . , en (i ) = 0 or 1.
This formula means: Interpret the n-tuple e of exponents of a monomial as the base-
2 representation of an integer i. The ith element of the bitblock a indicates whether
this monomial occurs in the ANF of f or not.
For the sample function f 0 (see Table 9.7) we already saw (or can easily check,
because f (1, 1, 1) = 1 + 1 + 1 = 1 since we add mod 2) that the ANF is
f 0 (x ) = x1 x3 + x1 x2 + x1 x2 x3 .
It involves the monomials with exponent triples 101, 110, 111 that correspond to
the integers 5, 6, 7. Therefore, we set the bits at the positions 5, 6, 7 to 1, and
the remaining bits to 0, and get the parsimonious representation of the ANF by
a bitstring:
00000111.
Warning This is the same bitstring as for the truth table by pure chance—a spe-
cial property of the function f 0 ! The function f (x1 , x2 ) = x1 has truth table
0011 (it takes the value 1 if and only if x1 = 1, or if the argument has the form
x = (1, any bit)) and ANF 0010 (since it contains the single monomial x1 ).
The SageMath class BoolF() has a method for calculating the ANF6 . SageMath
Example 9.3 demonstrates its application to f 0 .
SageMath Example 9.3: A Boolean Function with Truth Table and ANF
print ("\n# CHAP09 -- Sage -Script -SAMPLE 030: =========")
6. This transformation that converts a bitstring of length 2n (the truth table) into another bitstring of length
2n (the coefficient list of the ANF) is sometimes called Reed-Muller transformation or binary Moebius
transformation.
i i
i i
i i
#------------------------------------
# CHAP09 -- Sage -Script -SAMPLE 030: =========
# x : [0, 0, 0, 0, 0, 1, 1, 1]
# y : [0, 0, 0, 0, 0, 1, 1, 1]
# z : [0, 0, 0, 0, 0, 1, 1, 1]
Remark Evaluating a Boolean function f at all arguments x ∈ Fn2 the naive way
costs 2n evaluations f (x ), each with at most 2n summands, each of which need-
ing at most n − 1 multiplications. Thus, the costs have an order of magnitude of
about n · 2n · 2n . If we relate the costs to the input size N = 2n they are essentially
quadratic: N 2 · log2 ( N ). A common method, binary recursion, or “divide-and-
conquer,” divides a problem into two subproblems of half the input size, and leads
to a significantly more efficient algorithm. Starting from (9.4), finally we achieve a
reduction to almost linear costs 3 N · log2 N . This algorithm, also denoted as fast
binary Moebius transformation, an analogue of the fast Fourier transformation
(FFT), is implemented in the class BoolF().
• Block ciphers split bitstrings into blocks of a fixed length and encrypt one
complete block per step.
• Stream ciphers encrypt bit by bit, each one by another substitution (so each
single bit is either unchanged or flipped by a position-dependent rule).
No mathematically complete proof exists for the security of any block or stream
cipher. Thus, the situation is even worse than for asymmetric ciphers where the
proof of security often reduces to a well-studied, if not solved, mathematical prob-
lem. The best we can do is to consider a symmetric cipher as secure if none of the
known attacks is significantly faster than a complete exhaustion of the key space
(also known as “brute-force attack”).
i i
i i
i i
where Fk (a ) = F (a, k ).
i i
i i
i i
Example 1 Let n = l = 2,
F (a1 , a2 , x1 , x2 ) = (a1 + a2 x1 , a2 + a1 x2 + x1 x2 ),
a = (0, 1), c = (1, 1) ∈ F22 . The equations for the key (x1 , x2 ) ∈ F22 are
! !
1 0 + x1
= .
1 1 + 0 + x1 x2
Example 2 Linear maps: If F is a linear map, then the system of equations is acces-
sible by the efficient solution algorithms of linear algebra; see Section 9.1.10. We
have n linear equations for l unknowns. If l < n the attacker needs some additional
blocks of known plaintext, or she executes an exhaustion of the remaining n − l
key bits. For this method to work F needs to be linear only in x.
Example 3 Substitution: Often polynomial equations look complex at first sight but
aren’t so. Here is an example (over F2 )
x 1 x 2 x 3 + x 1 x 2 + x 1 x 3 + x 2 x 3 + x 2 + x 3 = 0.
i i
i i
i i
z1 z2 z3 + z1 = 0
(for an easy proof look in the reverse direction). This has the solutions
z 1 = 0, z 2 , z 3 arbitrary or z 1 = z 2 = z 3 = 1.
x1 = 1, x2 , x3 arbitrary or x1 = x2 = x3 = 0.
There are two powerful general approaches for solving systems of (polynomial)
equations over F2 :
Both methods work well for a few unknowns. With a growing number of
unknowns their complexity becomes unmanageable (in fact, SAT was the first prob-
lem in history shown to be NP-complete). Of course, we always find a solution
by searching through the complete value table. But this naive method is ineffi-
cient (exponential in the number of unknowns, and so hopeless for 80 or more
unknowns). But also the costs of SAT solvers and Groebner-basis methods grow
exponentially with the number of unknowns. Not even the fact that all partial
degrees are ≤ 1 is of vital help.
i i
i i
i i
We won’t explain the notion NP-complete but only mention that the (up to now
unproven) P 6= NP conjecture implies that an NP-complete problem admits no effi-
cient algorithmic solution, or that there is no solution algorithm whose execution
time grows at most polynomially with the number of input variables.
A common interpretation of this theorem is: For an appropriately chosen block
cipher F : Fn2 × Fl2 −→ Fn2 the attack with known plaintext (against the key k ∈ Fl2 )
is not efficient. However, from a strict mathematical point of view the theorem
doesn’t prove anything of practical relevance:
Despite these critical comments the theorem raises hope that there are secure
block ciphers, and the designers of block ciphers follow the:
Rule of thumb Systems of linear equations for bits admit very efficient solutions.
Systems of nonlinear equations for bits in almost all cases admit no efficient
solution.
for realistic values of the block length n and the key length l, say of an order of
magnitude of 128 bit or more.
In fact, we know explicit measures of security, for example the linear poten-
tial, or the differential potential, that quantify the deviation from linearity, or the
algebraic immunity, or others. Unfortunately all of these only give necessary, not
sufficient, conditions for security; and moreover the efficient computability of these
measures is limited to small block lengths n, about 8 or slightly larger.
Lacking a general efficient approach to security, the design of block ciphers usu-
ally relies on a structure that, although not obligatory, in practice seems to provide
plausible security (according to verifiable criteria). Most of the generally approved
standard ciphers, such as DES and AES, follow this approach.
This common design scheme starts by constructing Boolean maps of small
dimensions and then extending them to the desired block length in several steps:
i i
i i
i i
1. Define one or more Boolean maps of small dimension q (block length of the
definition domain), say q = 4, 6, or 8, that are good for several security
criteria. These maps are called S-boxes, and are the elementary building
blocks of the cipher. (“S” stands for substitution.)
2. Mix the round input with some of the key bits and then apply m S-boxes in
parallel (or apply the one S-box m times in parallel) to get a map with the
desired input width n = mq.
3. Then permute the complete resulting bitblock over its total width.
4. These steps together are a round of the complete scheme. Assess the weak-
nesses of the round map, that mainly result from using S-boxes of small
dimension. Then reduce these weaknesses in a reasonably controlled way
by iterating the scheme over several rounds of the same structure but with a
changing choice of key bits.
5. Don’t stop as soon as the security measures give satisfying values but add
some surplus rounds to get a wide security margin.
Diffusion The bits of the plaintext block “smear” over all parts of the block. This
is achieved by permutations.
Figure 9.2 A single round of a block cipher (with S-boxes S, permutation P, and key k).
i i
i i
i i
S1 (•,k ) P1 (•,k )
Fn2 −→ Fn2 −→ Fn2 −→ . . .
Sr (•,k ) Pr (•,k )
. . . −→ Fn2 −→ Fn2 −→ Fn2
Si = ith substitution
Pi = ith permutation
Pi ◦ Si = ith round
i i
i i
i i
• An even more alarming case is provided by image files with large single-color
areas. They contain many identical blocks such that structures of the image
may appear in the ciphertext file.7
Each ciphertext block depends on all previous plaintext blocks (diffusion), and
identical plaintext blocks in general encrypt to different ciphertext blocks.
The formula for decryption is
7. - For a convincing example see the Wikipedia entry “Block cipher mode of operation.”
- The template in CT2 Startcenter F Templates F Cryptography F Modern F Symmetric F Block
Modes of Symmetric Ciphers allows you to try this with your own pictures.
i i
i i
i i
Question Does it make sense to keep the initialization vector c0 secret and use it as
an additional key component? (Then, for the example of DES, we had 56 proper
key bit plus a 64-bit initialization vector, making a total of 120 key bit.)
Answer No!
Reason In the decryption process only a1 depends on c0 . This means that keeping
c0 secret conceals known plaintext only for the first block. If the attacker knows the
second or any later plaintext block, then she may attack the key as in ECB mode
(by an attack with known plaintext).
There are several other modes of operation. Worth mentioning is that the modes
OFB (output feedback) and CTR (counter) convert a block cipher into a stream
cipher.
All these statistical attacks hardly break a cipher in the sense of classical crypt-
analysis. They usually assume lots of known plaintexts, much more than an attacker
could gather in a realistic scenario. Therefore, a more adequate term is analysis
instead of attack. The analyses make sense for finding measures for some partial
aspects of security of block ciphers. They measure security for example by the num-
ber of known-plaintext blocks needed for the attack. If a cipher resists an attacker
even with exaggerated assumptions on her capabilities, then we feel safe to trust it
in real life.
Given an SP network, the analysis starts with the nonlinear components of
the single rounds, in particular with the S-boxes. The next step is extending the
potential attack over several rounds. This shows how the cost of the attack grows
with the number of rounds. In this way we find criteria for the number of rounds
for which the cipher is secure—at least from this special attack.
SageMath scripts applying linear cryptanalysis methods to Lucifer’s S-
box, to Mini-Lucifer, and to two other toy block ciphers can be found at
https://www.cryptool.org/en/documentation/ctbook/sagemath.
i i
i i
i i
Figure 9.5 CT2 template “Differential Cryptanalysis Tutorial 3” performing DCA of a toy cipher.
i i
i i
i i
Figure 9.6 Presentation view of the DCA KeyRecovery component showing the final state after a successful
differential cryptanalysis of a toy cipher (in CT2).
◦ The linear potential should be as low as possible, and the linear profile
as balanced as possible.
◦ The differential potential should be as low as possible, and the differential
profile as balanced as possible.
Some of these criteria are compatible with each other; some criteria contradict
other ones. Therefore, the design of a block cipher requires a balance between
different criteria. Instead of optimizing a map for a single criterion the designer
should aim at a uniformly high level for all criteria.
9.2.7 AES
The current standard for modern symmetric ciphers is AES (see Section 1.2.1).
i i
i i
i i
Figures 9.7 and 9.8 show the design of AES9 and the realization of the design
principles derived in Section 9.2.3.
• The block length is n = 128, the key length, l = 128, 192, or 256, the
number of rounds, r = 10, 12, or 14.
• At the beginning of each round and after the last round a partial key is added
to the current bitblock. The complete algorithm involves r + 1 partial keys.
• The 128-bit “partial keys” k (i ) are not partial keys in the proper sense but
extracted from the master key k by a somewhat involved algorithm (key
schedule). They are not independent.
• Each round starts by splitting the current 128-bit block into 16 parts
each consisting of 8 bits. Each of these parts is fed into the same S-box
S : F82 −→ F82 . This S-box has a mathematically quite elegant description that
however assumes some advanced knowledge of abstract algebra, hence it is
omitted here. The linear potential of the S-box is 64
1
.
• The diffusion step consists of a permutation followed by a linear map. This
step is slightly more complex than for a pure SP network as in Figure 9.2.
9. - Using CTO (cryptool-online.org) in the browser, AES can be seen in 2 plugins: as animation and via
“AES (step-by-step).”
- Using CT1 Indiv. Procedures F Visualization of Algorithms F AES you can find 3 visualizations
for this cipher.
- Using the search string AES in CT2 Startcenter F Templates you can find a plugin performing AES
step-by-step.
i i
i i
i i
i i
i i
i i
promising ones were applied to the ciphers Present, Katan, ChaCha, and Skinny.
For this purpose, round-reduced versions of these ciphers as well as versions with
smaller block length were used.
10. The default SageMath method ascii_to_bin() from the module sage.crypto.util converts ordinary
texts to bitstrings. The inverse method is bin_to_ascii(). However, these bitstrings belong to the class
StringMonoidElement, and are cumbersome to process further. Therefore, corresponding own functions
are defined in the file bitciphers.sage.
11. In CT2 Templates F Cryptography F Classical F XOR Cipher you can try this directly.
i i
i i
i i
In its strongest form, the one-time pad (OTP), XOR encryption is an example
for perfect security in the sense of Shannon. As algorithm A5 or E0 , XOR is used
to secure mobile phones or the Bluetooth protocol for wireless data transmission.
As RC4 it was part of the SSL protocol that encrypts client-server communication
between browser and web server, and of the PKZIP compression software. There
are many other current applications, not all of them fulfilling the expected security
requirements.
The scope of XOR encryption ranges from simple ciphers that are trivially
broken to unbreakable ciphers.
i i
i i
i i
A remark on the first disadvantage, the vulnerability for attacks with known
plaintext: The common ISO character set for texts has a systematic weakness. The
8-bit codes of the lower-case letters a…z all start with 011, of the upper-case letters
A…Z, with 010. A supposed sequence of six lower-case letters (no matter which)
reveals 6 · 3 = 18 key bits. The occurrence of many zeros in the leading bits of the
bytes is an important recognition feature for natural texts in European languages.
In other words we cannot prevent the attacker from getting or guessing a good
portion of the plaintext. Thus, the security against an attack with known plaintext
is a fundamental requirement for an XOR cipher, even more than for any other
cryptographic procedure.
• Pseudorandom sequence
and leads to really useful procedures. The essential criterion is the quality of the
pseudorandom generator.
D | u | | b | i | s |
a: 01000100|01110101|00100000|01100010|01101001|01110011|
k: 10010110|10010110|10010110|10010110|10010110|10010110|
-------- -------- -------- -------- -------- --------
c: 11010010|11100011|10110110|11110100|11111111|11100101|
t | | d | o | o | f
01110100|00100000|01100100|01101111|01101111|01100110
10010110|10010110|10010110|10010110|10010110|10010110
-------- -------- -------- -------- -------- --------
11100010|10110110|11110010|11111001|11111001|11110000
i i
i i
i i
Òã¶ôœåâ¶òùùð
This might bedazzle laypersons. An expert immediately notes that all characters
are from the upper half of the possible 256 bytes. This observation suggests that
the plaintext is in natural language, encrypted with a key whose leading bit is 1. If
the attacker guesses that the conspicuous character ¶ = 10110110 corresponds to
the space character 00100000, she derives the key as the difference 10010110. This
breaks the cryptogram.
#------------------------------------
# CHAP09 -- Sage -Script -SAMPLE 130: =========
# 010001000111010100100000011000100110100101110011
# 011101000010000001100100011011110110111101100110
# key: 10010110
# 110100101110001110110110111101001111111111100101
# 111000101011011011110010111110011111100111110000
Note that these frequencies relate to the binary files, heavily depend on the type of
the document, and may change with every software version. The variation is large,
i i
i i
i i
we often find unexpected peaks, and all bytes 00–FF occur. But all this doesn’t
matter here since we observe long chains of 00 bytes.
For a Microsoft Word file that is XOR encrypted with a periodically repeated
key, the ubiquity of zeros suggests an efficient attack. First, determine the length of
the key. If the length of the period is unknown, you can determine it by the methods
for periodic polyalphabetic substitutions from classical cryptanalysis named after
Kasiski, Friedman, or Sinkov. Or simply try all possible lengths. Then split the
stream of ciphertext bits into blocks corresponding to the length of the period and
add the blocks pairwise. If one of the plaintext blocks essentially consists of zeros,
then the sum is readable plaintext. Why? Consider the situation
ci + ci0 = ai + ki + ki = ai for i = 1, . . . , s,
that is, a plaintext block. If she realizes this (for example recognizing typical
structures), then she sees the key k1 , . . . , ks .
Should it happen that the sum of two ciphertext blocks is zero then the cipher-
text blocks are equal, and so are the corresponding plaintext blocks. The probability
that both of them are zero is high. Thus, the key could immediately show through.
To summarize: XOR encryption with a periodic key stream is quite easily broken
for messages with a known structure.
This is true also for a large period, say 512 bytes = 4096 bits, in spite of the
hyperastronomically huge key space of 24096 different possible keys.
i i
i i
i i
here12 but summarize: XOR encryption with running-text keys is fairly easily
broken.
12. In JCT Default Perspective F Analysis F Viterbi Analysis an automatic recognition of the two
plaintexts is offered, where only the running-key ciphertext is needed.
i i
i i
i i
Figure 9.12 XOR encryption of a hazardous message, and an alleged alternative plaintext.
i i
i i
i i
There are other, useful, cryptographic applications of true random bits: Gen-
erating keys for arbitrary encryption algorithms that are unpredictable for the
attacker. Many cryptographic protocols rely on nonces that have no meaning
except for being random; for example, the initialization vectors of the block cipher
modes of operation, or the challenge for strong authentication (challenge-response
protocol).
For XOR encryption—as approximation to the OTP—algorithmically gener-
ated bit sequences are much more practicable. But the attacker should have no
means to distinguish them from true random sequences. This is the essence of
the concept pseudorandomness, and generating pseudorandom sequences is of
fundamental cryptologic relevance.
XOR encryption with a pseudorandom key stream spoils the perfect secu-
rity of the one-time pad. But if the pseudorandom sequence is cryptograph-
ically strong (see Section 9.3.8) the attacker has no chance to exploit this
fact.
For classical random generators that are popular in statistical applications and
simulations the answer is yes (see Section 9.3.4). But we’ll learn about random gen-
erators that (presumably) are cryptographically secure. The cipher designer faces
the problem of finding a good trade-off between efficiency and security.
The two main serious methods of generating pseudorandom bit sequences, or
key streams, are:
i i
i i
i i
and serve as components of the key. The initial state (start value) is a true random
value and likewise secret. With each step the random generator outputs a value,
depending on its current inner state, until an exterior intervention stops it.
Thus, the random generator transforms a short, truly random, bit sequence,
the initial state, into a long pseudorandom sequence. Cryptologists call this effect
key expansion.
represents the complete sequence. For use with SageMath we define a general FSR
with feedback function f by implementing a method fsr() for the class BoolF, see
SageMath Example 9.5 (also contained in the file bitciphers.sage).
Figure 9.14 An FSR during the first iteration step. The Boolean function f calculates a new bit from
the current state of the register. This new bit is slid in from the left.
i i
i i
i i
i i
i i
i i
load ("./ bitciphers.sage ") # for txt2bbl() and classes BoolF + LFSR
print ("\n-- Using f.fsr() with coeff from LFSR () as input x: --")
x = coeff
print (" Input x:"); print(x)
f = BoolF(x)
i i
i i
i i
g : M −→ M.
For each element (initial state) x0 ∈ M define a sequence (xi )i≥0 in M by the recur-
sive formula xi = g (xi−1 ) for i ≥ 1. After a previous period (preperiod) of length
µ the sequence runs into a period of length ν (see Figure 9.15).
Since the set M is finite the states must eventually repeat. Thus, there are small-
est integers µ ≥ 0 and ν ≥ 1 such that xµ+ν = xµ . To see this, simply take µ as the
first index such that the element xµ reappears in the sequence at another position,
and µ + ν as the first index where this repetition occurs. Then also (by induction)
Definition: µ is called the (length of the) preperiod, ν, the (length of the) period.
i i
i i
i i
13. Within, it uses the function binScPr() from the file bitciphers.sage, which defines the “scalar product”
of two binary vectors.
14. For a more systematic approach, a class LFSR is defined in the file bitciphers.sage. Alternatively, we can
reproduce the result of lfsr() by using fsr(). To this end we represent the linear feedback function by its
truth table (or by its ANF), and then instantiate a Boolean function of the class BoolF. Instead of n bits (that
define the taps) we need 2n bits for the truth table. This is quite uneconomical. Thus, the separate definition
of lfsr() makes sense. Another alternative is the default function sage.crypto.lfsr.lfsr_sequence of
SageMath.
i i
i i
i i
object of the class LFSR, the taps being defined by the bitblock coeff. Then we
set the initial state of the register as the bitblock start, and generate 1024 bits of
output. Figure 9.17 shows this output (printed without parantheses or delimiters).
We could apply a series of statistical tests to this bitstream, for example tests of
uniform distribution, and would always see good results. Instead, we visualize the
sequence in Figure 9.18 for optical inspection—of course an even more insufficient
proof. However, the superficial impression shows a quite random sequence. The
function visualize in SageMath Example 9.8 generated this picture.
Don’t take offense at the sequence of nine (black) ones in the third to last row;
the probability of nine ones in nine random bits is (1/2)9 = 1/512. Therefore, in a
random bitstream of length 1024 a run of this kind occurs with high probability.
Neither the usual statistical tests nor the visual impression are valid
testimonials of the quality of a pseudorandom sequence.
As we’ll see, the random properties of LFSR sequences are poor. Cryptanalysis
detects deficiencies that evade standard statistical tests.
i i
i i
i i
Figure 9.18 Visualization of the pseudorandom bit sequence from Figure 9.17, generated by Sage-
Math Example 9.8 (1 = black, 0 = white).
l = len(s)
assert l == len(x), "lfsr_Error: Bad length of start vector ."
u = x # in Python use u = x.copy ()
outlist = []
for i in range (0,n):
b = binScPr(s, u)
c = u.pop()
u.insert(0,b)
outlist.append(c)
return outlist
i i
i i
i i
l = len(lst)
p = polygon ([(0,0), (w,0), (w,h), (0,h)], color = "grey ")
for j in range(h+1):
p += line ([(0,j) ,(w,j)], color =" black ")
for i in range(w+1):
p += line ([(i,0) ,(i,h)], color =" black ")
for j in range(h):
for i in range(w):
if (j*w + i < l):
if (lst[j*w + i] == 0):
p += polygon ([(i,h-1-j) ,(i+1,h-1-j) ,(i+1,h-j) ,(i,h-j)], color = "white ")
else:
p += polygon ([(i,h-1-j) ,(i+1,h-1-j) ,(i+1,h-j) ,(i,h-j)], color = "black ")
p.axes(False)
return p
p2 = visualize(bitlist ,32,32)
# show(p2) # works in Jupyter notebook
# Display(p2, "LFSRsquare ") # works in script called from CLI if Display () is defined
p2.save (" LFSRseq.png")
print (" Graphic saved to LFSRseq.png")
Figure 9.19 shows how LFSR is implemented in CT2. On the right of the
screenshot you can see the settings for the LFSR component.
LFSRs have been implemented many times. A very nice implementation is avail-
able in the Python package “pylfsr” [22]. Section 9.3.3.3 shows an example with
pylfsr. This code also contains the conversions between the input at CT2 and at
pylfsr—because there is no generally accepted standard in which order the bits
of the seed have to be entered and how to enter the coefficients of the feedback
polynomial.
i i
i i
i i
i i
i i
i i
s1 u l−1 + · · · + sl u 0 = u l .
Each additional known plaintext bit yields one more relation, and having l
relations, from 2l bits of known plaintext, the easy linear algebra over the field F2
(in nondegenerate cases) finds a unique solution. The l · l coefficient matrix of this
linear equation system is essentially the matrix U of Section 9.3.4.1.
Theorem 9.12 An LFSR of length l is completely predictable from the first 2l bits
for the cost of about 13 · l 3 bit operations.
u (i ) = (u i , . . . , u i +l−1 ) for i = 0, 1, . . .
The vector u (i ) is the register content for step i (in reversed order compared with
Figure 9.14). Thus, the analysis focuses on the states, not directly on the output.
The recursion formula (9.6) in matrix form (for n ≥ l) is
u n−l +1 0 1 ... 0 u n−l
. . .. .
.. .. ..
. .. ..
= . .
u n−1 0 0 . . . 1 u n−2
un sl sl−1 . . . s1 u n−1
i i
i i
i i
u (m ) = S · u (m−1) for m ≥ 1
V = S·U
S = V · U −1 .
The matrix S explicitly displays the coefficients s1 , . . . , sl . We’ll discuss the invert-
ibility later on.
Example
Assume we are given a ciphertext:
10011100 10100100 01010110 10100110 01011101 10101110
01100101 10000000 00111011 10000010 11011001 11010111
00110010 11111110 01010011 10000010 10101100 00010010
11000110 01010101 00001011 11010011 01111011 10110000
10011111 00100100 00001111 01010011 11111101
We suspect that the cipher is XOR with a key stream from an LFSR of length l = 16.
The context suggests that the text is in German and begins with the word “Treff-
punkt” (meeting point). To solve the cryptogram we need 32 bits of plaintext, that
is the first four letters only, presupposed that the theory applies. This gives 32 bits
of the key stream:
01010100 01110010 01100101 01100110 = T r e f
10011100 10100100 01010110 10100110 cipher bits
-------- -------- -------- --------
11001000 11010110 00110011 11000000 key bits
SageMath Example 9.9 determines the coefficient matrix. Its last row tells us that
all si = 0 except s16 = s5 = s3 = s2 = 1.
Now we know the LFSR and the initial state, and can reconstruct the complete
key stream—yes, it is the same as in Figure 9.17—and write down the plaintext
(that by the way begins a bit differently from our guess).
i i
i i
i i
l = 16
kbits = [1,1,0,0,1,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0,0,1,1,1,1,0,0,0,0,0, �
� 0]
ulist = []
for i in range(0,l):
state = kbits[i:(l+i)]
ulist.append(state)
U = matrix(GF(2),ulist)
print ("det(U) =", det(U))
W = U.inverse ()
vlist = []
for i in range(1,l+1):
state = kbits[i:(l+i)]
vlist.append(state)
V = matrix(GF(2),vlist)
S = V*W
print(S)
#------------------------------------
# CHAP09 -- Sage -Script -SAMPLE 160: =========
# det(U) = 1
# [0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
# ...
# [1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 0]
9.3.4.2 Proof of Theorem 9.12: How Many Bits Must be Known to Predict an LFSR
We showed that the coefficients are uniquely determined assuming the state matrix
U = U(0) is invertible. As a consequence in this case the LFSR is completely known,
and all output bits are predictable. We have yet to discuss the case where the matrix
U is singular.
If one of the first l state vectors (= rows of the matrix U ) is zero, then all
following state vectors are zero too, and prediction is trivial.
Thus, we may assume that none of these vectors are zero, but that they are
linearly dependent. Then there is a smallest index k ≥ 1 such that u (k ) is contained
in the subspace spanned by u (0) , . . . , u (k−1) , and we find coefficients t1 , . . . , tk ∈ F2
such that
u (k ) = t1 u (k−1) + · · · + tk u (0) .
i i
i i
i i
Discussion
• For a singular state matrix this consideration yields a shorter LFSR (of length
k < l) that generates exactly the same sequence. Then our method doesn’t
determine the coefficients of the original register but nevertheless correctly
predicts the sequence.
• If the bits the attacker knows aren’t just the first ones but 2l contiguous
ones at a later position, then the theorem yields only the prediction of the
following bits. In the main case of an invertible state matrix U the LFSR is
completely known and may be run backwards to get the previous bits. For
a singular state matrix we achieve the same effect using the shorter LFSR
constructed previously.
• The situation where 2l bits of the key stream are known but at noncontigu-
ous positions is slightly more involved. We get linear relations that contain
additional (unknown) intermediate bits. If m is the number of these then we
get l + m linear equations for l + m unknown bits.
• What if the length l of the LFSR is unknown? Exhaustively trying all values
l = 1, 2, 3, . . . is nasty but feasible. A better approach is provided by the
Berlekamp-Massey15 algorithm that is efficient also without knowledge of
l. We won’t treat it in this chapter.
Summary
Given a random generator as in Figure 9.13 cryptanalytic, targets are:
• Secret parameters
• Initial state
• Additional parts of the output (prediction problem)
given some parts of the output. As we saw for LFSRs the prediction problem has a
solution even when the internal parameters remain unknown. Thus:
i i
i i
i i
But unfortunately from a cryptological view they are completely insecure if used
naively. To capitalize their positive properties while escaping their cryptological
weakness there are several approaches.
16. With CT2 Templates F Mathematics F LFSR or NLFSR you can try this directly.
i i
i i
i i
• Output selection takes the current output bit of exactly one of the LFSRs
from the battery, depending on the state of the auxiliary register, and outputs
it as the next pseudorandom bit. More generally we could choose r from n.
• For decimation one usually takes n = 1 and outputs the current bit of the one
battery register only if the auxiliary register is in a certain state, for example
its own current output is 1. Of course this kind of decimation applies to
arbitrary bit sequences in an analogous way.
• For clocking we look at the state of the auxiliary register and, depending on
it, decide which of the battery registers to step in the current cycle (and by
how many positions), leaving the other registers in their current states. This
is reminiscent of the control logic of rotor machines in classical cryptography.
i i
i i
i i
clocked. It linearly (by simple binary addition) combines the three output streams.
The (even weaker) algorithm A5/2 controls the clocking by an auxiliary register.
Both variants can be broken on a standard PC in real-time.
The Bluetooth encryption standard E0 uses four LFSRs and combines them in
a nonlinear way. This method is somewhat stronger than A5, but also too weak for
real security [5].
#------------------------------------
# CHAP09 -- Sage -Script -SAMPLE 170: =========
# Value at 000 is 0
# Value at 001 is 0
# Value at 010 is 0
# Value at 011 is 1
# Value at 100 is 1
i i
i i
i i
# Value at 101 is 0
# Value at 110 is 1
# Value at 111 is 1
Class LFSR:
Attributes:
• length: The length of the register;
• taplist (constant): The list of coefficients (or taps) that define the bits for
feedback;
• state (variable): The state of the register.
Methods:
• setLength: Define the length (used only implicitly for initialization);
• setTaps: Define the list of taps (used only implicitly for initialization);
• setState: Set the state of the register;
• getLength: Output the length;
• nextBits: Generate a given number of output bits, and set the next state.
i i
i i
i i
#------------------------------------
# CHAP09 -- Sage -Script -SAMPLE 180: =========
# n15 = 32767 = 7 * 31 * 151
# n16 = 65535 = 3 * 5 * 17 * 257
# n17 = 131071 = 131071
# lcm = 281459944554495
# period = 281459944554495
#------------------------------------
# CHAP09 -- Sage -Script -SAMPLE 190: =========
# Length: 15 | Taps: 100000000000001 | State: 011010110001001
# Length: 16 | Taps: 0110100000000001 | State: 0110101100010011
# Length: 17 | Taps: 00100000000000001 | State: 01101011000100111
nofBits = 100
outlist15 = reg15.nextBits(nofBits)
print (" outlist15:\n", outlist15)
outlist16 = reg16.nextBits(nofBits)
print (" outlist16:\n", outlist16)
outlist17 = reg17.nextBits(nofBits)
print (" outlist17:\n", outlist17)
i i
i i
i i
nofBits = 100
outlist15 = reg15.nextBits(nofBits)
outlist16 = reg16.nextBits(nofBits)
outlist17 = reg17.nextBits(nofBits)
outlist = []
for i in range(0,nofBits):
x = [outlist15[i], outlist16[i], outlist17[i]]
outlist.append(geff.valueAt(x))
print(outlist)
#------------------------------------
# CHAP09 -- Sage -Script -SAMPLE 210: =========
# [1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1,
# 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1,
# 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0,
# 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1,
# 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1]
How long should the battery registers be? There are some algorithms for fast cor-
relation attacks using the Walsh transformation, in particular against sparse linear
feedback functions (that use only a few taps) [24]. These don’t reduce the com-
plexity class of the attack (exponential in the length of the shortest register) but
reduce the cost by a significant factor. So they are able to attack registers whose
feedback functions have up to 100 monomials with coefficients in their ANF. As a
consequence
• The single LFSRs should have a length of at least 200 bits, and use about
100 taps each.
i i
i i
i i
To assess the number n of LFSRs we bear in mind that the combining function
should be correlation immune, in particular have a low linear potential. A well-
chosen Boolean function of 16 variables should suffice. To us, there are no known
recommendations in the literature.
Rainer Rueppel found an elegant way out to make the correlation attack break
down: Use a time-dependent combining function, that is a family ( f t )t∈N . The bit u t
of the key stream is calculated by the function f t . We won’t analyze this approach
here.
Observing that the correlation attack needs knowledge of the taps, the security
could be somewhat better if the taps are secret. Then the attacker has to perform
additional exhaustions that multiply the complexity by factors such as 2l1 for the
first LFSR alone. This scenario allows choosing LFSRs of somewhat smaller lengths.
But bear in mind that for a hardware implementation the taps are parts of the
algorithm, not of the key, so they are public parameters in the sense of Figure 9.13.
Efficiency
LFSRs and nonlinear combiners allow efficient realizations by special hardware that
produces one bit per clock cycle. This rate can be enlarged by parallelization. From this
point of view, estimating the cost of execution on a usual PC processor is somewhat
inadequate. Splitting each of the ≥ 200 bit registers into 4 parts of about 64 bits
shifting a single register requires at least 4 clock cycles, summing up to 64 clock
cycles for 16 registers. Add some clock cycles for the combining function. Thus, one
single bit would take about 100 clock cycles. A 2-GHz processor, even with optimized
implementation, would produce at most 2 · 109 /100 = 20 million bits per second.
As a summary we note: Using LFSRs and nonlinear combining functions, we
can build useful and fast random generators, especially in hardware.
Unfortunately there is no satisfying theory for the cryptologic security of this
type of random generators, even less a mathematical proof. Security is assessed
by plausible criteria that—as for block ciphers—are related to the nonlinearity of
Boolean functions.
i i
i i
i i
a true random sequence. Thus, on the theoretical side, we have a very appropriate
model for random generators that are absolutely strong from a statistical viewpoint,
and invulnerable from a cryptological viewpoint. In other words:
Example
Of course an example with small numbers is practically irrelevant, but it illustrates
the algorithm. Take p = 7, q = 11, m = 77, s = 53. Then s 2 = 2809, hence
x0 = 37, and u 0 = 1 since x0 is odd. The naive SageMath Example 9.15 shows the
beginning of the sequence of states:
i 0 1 2 3 ...
xi 37 60 58 53 ...
ui 1 0 0 1 ...
i i
i i
i i
p = 7; q = 11; m = p*q; s = 53
print ("m =", m, ", s =", s)
x0 = (s^2) % m; print ("x0 =", x0)
x1 = (x0^2) % m; print ("x1 =", x1)
x2 = (x1^2) % m; print ("x2 =", x2)
x3 = (x2^2) % m; print ("x3 =", x3)
Treating the Blum primes p and q as secret is essential for the security of the BBS
generator. They serve for forming m only; afterward they may even be destroyed.
In contrast with RSA there is no further use for them. Likewise, all the nonoutput
bits of the inner states xi must be secret.
The standard distribution of SageMath contains the BBS generator. It consists
of the procedures:
• random_blum_prime() in the module sage.crypto.util. To generate a
random Blum prime p with a given number k of bits (= digits of the binary
representation) call it as p = random_blum_prime(2**(k-1), 2**k). The
correctness of this algorithm is only empirically founded: In fact there is
always a prime between 2k−1 and 2k , but this doesn’t need to be a Blum
prime. This is a special case of Bertrand’s postulate, proved by Chebyshev
in 1850: There is a prime between n and 2n (for all n ≥ 2). Nevertheless,
empiricism tells us that there are lots of Blum primes in this interval, namely
about 2k /(k log(2)). Thus, an attack by exhaustion will fail.
• blum_blum_shub() from sage.crypto.stream. To generate a sequence
of r pseudorandom bits first generate two random Blum primes p and
q and an initial value x0 = s 2 mod pq, and then call the procedure as
blum_blum_shub(r,x_0,p,q).
SageMath Example 9.16 demonstrates the procedure. The intermediate results
p, q, and x0 are shown in Tables 9.10, 9.11, and 9.12, the result in Table 9.13. By
convention s as well as the factors p and q must be kept secret. Moreover, there
is no reason to reveal the product m = pq. However, considering the progress of
factorization algorithms we should better use Blum integers of at least 2048 bit (see
Section 9.3.10). And in any case s must be a true random value! We neglected this
duty by choosing s as a pure power.
i i
i i
i i
q = random_blum_prime(2^511, 2^512)
x0 = 11^248 % (p*q) # s = 11^124 % (p*q)
print(blum_blum_shub(sl ,x0,p,q))
print ("\ nUsing the fixed values from the given table as start values :")
no = "8 445 834 617 855 090 512 176 000 413 196 767 417 799 332\
626 936 992 170 472 089 385 128 414 279 550 732 184 808 226\
736 683 775 727 426 619 339 706 269 080 823 255 441 520 165\
438 397 334 657 231 839 251"
p = ZZ(no.replace ("\n", "").replace ("\r", "").replace (" ", ""))
no = "12 580 605 326 957 495 732 854 671 722 855 802 182 952 894\
232 088 903 111 155 705 856 898 413 602 721 771 810 991 595\
365 229 641 230 483 180 760 744 910 366 324 916 344 823 400\
588 340 927 883 444 616 787"
q = ZZ(no.replace ("\n", "").replace ("\r", "").replace (" ", ""))
no = "1 842 408 460 334 540 507 430 929 434 383 083 145 786 026\
412 146 359 363 362 017 837 922 966 741 162 861 257 645 571\
680 482 798 249 771 263 305 761 292 545 408 040 659 753 561\
970 871 645 393 254 757 072 936 076 922 069 587 163 804 708\
256 246 366 137 431 776 175 309 050 064 068 198 002 904 756\
218 898 942 856 431 647 438 473 529 312 261 281"
x0 = ZZ(no.replace ("\n", "").replace ("\r", "").replace (" ", ""))
s= str(blum_blum_shub(sl ,x0,p,q))
bl=4 # blocklength
split = [s[i:i+bl] for i in range (0, len(s), bl)]
print (" Number of blocks = len(split) =", len(split))
for i in range(len(split)):
print ("%s " % (split[i]), end = '' )
print ()
Table 9.10 A Blum Prime p with 512 Bits (154 Decimal Places)
8 445 834 617 855 090 512 176 000 413 196 767 417 799 332
626 936 992 170 472 089 385 128 414 279 550 732 184 808 226
736 683 775 727 426 619 339 706 269 080 823 255 441 520 165
438 397 334 657 231 839 251
Table 9.11 A Blum Prime q with 512 Bits (155 Decimal Places)
12 580 605 326 957 495 732 854 671 722 855 802 182 952 894
232 088 903 111 155 705 856 898 413 602 721 771 810 991 595
365 229 641 230 483 180 760 744 910 366 324 916 344 823 400
588 340 927 883 444 616 787
i i
i i
i i
i i
i i
i i
For example, LFSRs don’t pass the prediction test: We constructed an efficient
next bit predictor in Theorem 9.12.
Here stated without proof. Unfortunately, this approach only gives qualitative
results, and so it is somewhat dissatisfying. However, as often in complexity theory,
this is the best we can achieve.
We omit the proof (that is quite involved). Sloppily expressed, the theorem
says:
This statement assumes that the attacker knows the modulus m of the BBS generator.
However, the modulus might also be secret, that is, considered as a part of the key.
Assuming this, the cryptographic security of BBS should even be better—but no
proof of this stronger statement seems to be known, not even an informal one.
i i
i i
i i
i i
i i
i i
use 11 bits per step. Calculating x 2 mod m for an n bit number m takes ( 64 ) mul-
n 2
tiplications of 64-bit integers and subsequently the same number of divisions of the
type 128 bits by 64 bits.
For n = 2048 this makes a total of 2 · (25 )2 = 2048 multiplicative opera-
tions to generate 11 bits, or about 200 operations per bit. A well-established rule
of thumb says that a modern CPU executes one multiplicative operation per clock
cycle. Remark: Special processors that use pipelines and parallelism are significantly
faster. Thus, on a 2-GHz CPU with 64-bit architecture we may expect roughly
2 · 109 /200 ≈ 10 million bits per second, provided the algorithm is implemented in
an optimized way. This consideration shows that the BBS generator is almost com-
petitive with a software implementation of a sufficiently secure nonlinear combiner
of LFSRs, and is fast enough for many purposes if executed on a present day CPU.
The cryptographic literature offers several pseudorandom generators that
follow similar principles as BBS:
The Elliptic Index Generator (Kaliski) It works like the index generator, but replaces
the group of invertible elements of the field F p by an elliptic curve over F p (such a
curve is a finite group in a canonical way).
i i
i i
i i
But why may we hope that this random generator is perfect? This depends on
the hypothesis: There is no efficient test that distinguishes the uniform distribution
on {1, . . . , m − 1} from the distribution of x d mod m for uniformly distributed x ∈
{1, . . . , 2h (n ) }. If this hypothesis is true, then the Micali-Schnorr generator is perfect.
This argument seems tautological, but heuristic considerations show a relation with
the security of RSA and with factorization. Anyway we have to concede that this
proof of security seems considerably more airy than that for BBS.
How fast do the pseudorandom bits tumble out of the machine? As elemen-
tary operations we again count the multiplication of two 64-bit numbers, and the
division of a 128-bit number by a 64-bit number with 64-bit quotient. We multi-
ply and divide by the classical algorithms. Remark: Multiplication by fast Fourier
transformation (FFT) has an advantage only for much larger numbers. Thus, the
product of s (64-bit) words and t words costs s · t elementary operations. The cost
of division is the same as the cost of the product of divisor and quotient.
The specific recommendation by the inventors is: d = 7, n = 512. Today we
would choose a larger n. The output of each step consists of 384 bits, withholding
128 bits as the new state. The binary power algorithm for a 128-bit number x with
exponent 7 costs several elementary operations:
This makes a total of 124 elementary operations; among them only one reduction
mod m (for x 7 ). Our reward consists of 384 pseudorandom bits. Thus, we get about
3 bits per elementary operation, or, by the assumptions in Section 9.3.11, about 6
i i
i i
i i
American billions (European milliards) bits per second. Compared with the BBS
generator this amounts to a factor of about 1000.
Parallelization increases the speed virtually without limit: The Micali-Schnorr
generator allows complete parallelization. Thus distributing the work among k
CPUs brings a profit by the factor k since the CPUs can work independently of
each other without need of communication.
In contrast with block ciphers where we have the accepted standard AES (and
the outdated standard DES) for stream ciphers there is no established standard.
Closest to standardization is the eSTREAM portfolio developed in a European
project from 2004 until 2008. It recommends a bunch of several ciphers [5].
Unfortunately, several proprietary ciphers, mostly stream ciphers developed in
back rooms, found their way into security critical applications. Despite the fact that
they relied on security through obscurity, they could (easily) be analyzed by reverse
engineering, and teared to shreds by cryptologists. Therefore, we finish this chapter
with the advice that in an analogous form applies to all parts of cryptography:
Never trust a random generator whose algorithm is kept secret, or for which
no analysis results are publicly available. Statistical analyses are insufficient
as security proofs, just as little as gargantuan periods, or a gigantic choice
of initial states.
i i
i i
i i
References
[1] Menezes, A. J., P. C. van Oorschot, and S. A. Vanstone, Handbook of Applied Cryptog-
raphy, 5th ed., Series on Discrete Mathematics and Its Application, CRC Press, 2001,
https://cacr.uwaterloo.ca/hac/.
[2] Oppliger, R., Contemporary Cryptography, Second Edition, Norwood, MA: Artech
House, 2011, https://www.esecurity.ch/Books/cryptography2e.html.
[3] Oppliger, R., Cryptography 101: From Theory to Practice, First Edition, Norwood, MA:
Artech House, 2021, https://rolf.esecurity.ch/?page_id=465.
[4] Paar, C., and J. Pelzl, Understanding Cryptography—A Textbook for Students and
Practioners, Springer, 2009, https://www.crypto-textbook.com/.
[5] Schmehl, K.,Cryptography and Public Key Infrastructure on the Internet, in German, the
6th edition was published in 2016. John Wiley, 2003.
[6] Schmeh, K., Kryptographie—Verfahren, Protokolle, Infrastrukturen, 6th ed., Written in
German, dpunkt.verlag, 2016.
[7] Stamp, M., and R. M. Low, Applied Cryptanalysis: Breaking Ciphers in the Real World.
Wiley-IEEE Press, 2007, https://www.cs.sjsu.edu/∼stamp/crypto/.
[8] Lenstra, A. K., and E. R. Verheul, “Selecting Cryptographic Key Sizes,” in Lecture Notes
in ComputerScience 558—PKC, 2000, pp. 446–465.
[9] Bard, G. V., Algebraic Cryptanalysis, Springer, 2009.
[10] Garey, M. R., and D. S. Johnson, Computers and Intractability, Freeman, 1979.
[11] Brickenstein, M., “Boolean Gröbner Bases—Theory, Algorithms and Applications;”
See also “BRiAl, the successor to PolyBoRi (Polynomials over Boolean Rings),” 2010,
https://github.com/BRiAl/BRiAl.
[12] Cox, D., J. Little, and D. O’Shea, Ideals, Varieties, and Algorithms, 3rd ed., Springer,
2007.
[13] von zurGathen, J., and J. Gerhard, Modern Computer Algebra, Cambridge University
Press, 1999.
[14] Segers, A. J. M., “Algebraic Attacks from a Gröbner Basis Perspective,” TU Eindhoven,
2004, https://www.win.tue.nl/∼henkvt/images/ReportSegersGB2-11-04.pdf.
i i
i i
i i
[15] Lazard, D., “GröbnerBases, Gaussian Elimination and Resolution of Systems of Algebraic
Equations,” in Lecture Notes in Computer Science 162, EUROCAL ’83, Springer, 1983,
pp. 146–156.
[16] Pommerening, K., Fourier Analysis of Boolean Maps—A Tutorial, last revision on
August 11, 2014; German equivalent: Linearitätsmaße für BoolescheAbbildungen, 2014,
https://www.staff.uni-mainz.de/pommeren/Cryptology/Bitblock/Fourier/Fourier.pdf.
[17] Stinson, D. R., Cryptography—Theory and Practice, 3rd ed., Chapman & Hall/CRC,
2006.
[18] Gohr, A., “Improving Attacks on Round-Reduced Speck32/64 Using Deep Learning,” in
Advancesin Cryptology–CRYPTO 2019: 39th Annual International Cryptology Confer-
ence, Santa Barbara, CA, USA, August 18–22, 2019, Proceedings, Part II, Vol. 11693,
Springer. 2019, pp. 150–179, https://eprint.iacr.org/2019/037.pdf.
[19] Gohr, A., G. Leander, and P. Neumann. “An Assessment of Differential-Neural Distin-
guishers,” in Cryptology ePrint Archive, 2022, https://eprint.iacr.org/2022/1521.pdf.
[20] BSI, and Leander, et al., AI-Supported Analysis Methods for Symmetric Cryptography,
Tech. rep. 2022, https://www.bsi.bund.de/SharedDocs/Downloads/EN/BSI/Publications/S-
tudies/Cryptography/KIMSK_Final-Report.html.
[21] Golomb, S. W., Shift Register Sequences,revised edition, Aegean Park Press, 1982.
[22] Bajaj, N., Nikeshbajaj/Linear_Feedback_Shift_Register: 1.0.7, Version 1.0.7, January
2023, https://zenodo.org/record/7501241.
[23] Pommerening, K., “Cryptanalysis of Nonlinear Shift Registers,” in Cryptologia, Vol. 40,
No. 4, 2016, https://www.tandfonline.com/doi/abs/10.1080/01611194.2015.1055385.
[24] Meier, W., and O. Staffelbach, “Fast Correlation Attacks on Certain Stream Ciphers,” in
Journal of Cryptology, Vol. 1, 1989, pp. 159–176.
i i
i i
i i
i i
i i
i i
C H A P T E R 10
C H A P T E R 10
Homomorphic Ciphers
We first clarify the meaning and the origin of the term homomorphic. This term
in cryptography is derived from its counterpart in mathematics: In mathematics, a
homomorphism is a structure-preserving map between two algebraic structures. In
the common sense, this means that a homomorphism f : X → Y maps the structure
of X to the structure of Y . Using an example, this can be easily illustrated: Let ( X, +)
and (Y, ∗) two algebraic groups with group operations + and ∗, respectively. A
homomorphism f : X → Y maps any given x ∈ X to a value y ∈ Y , in a way that
it holds (additive homomorphic system):
for any two x1 , x2 in X . This means that for any two values x1 , x2 it does not matter
whether we first compute their sum (group operation of X ) and then apply f (this
is the left side of (10.1)) or, whether we first apply f to the values x1 , x2 , and then
compute their product in Y , thus applying the group operation of Y . Please note
that the operations + and ∗ were chosen here only as an example; they always
depend on the algebraic group they belong to. Naturally, the same relation holds
for homomorphisms between groups with the same group operation.
Example: Let X = Z be the set of integer values. The set Z together with the addi-
tion operation forms an algebraic group G 1 = (Z, +). Similarly, the real values
R without the value zero together with the multiplication operation form a group
G 2 = (R\{0}, ∗). The function f : Z→R\{0}, z→e z is a homomorphism, since for
467
i i
i i
i i
i i
i i
i i
10.4.1.2 Encryption
Let m be the message which will be encrypted, where m is taken from the plain-
text space Zn . For each encryption, we first choose a random element r from the
plaintext space Zn . Subsequently, using the public key, we compute the ciphertext
n as:
c = E (m, r ) = (n + 1)m ∗ r n mod n 2
i i
i i
i i
10.4.1.3 Decryption
Given the private key λ and a ciphertext c ∈ Z∗n 2 , we first compute S = cλ mod n 2
and subsequently T = φ (n )(−1) mod n 2 , where φ denotes the Euler function.
Finally, we compute the plaintext m = D (c) = ( S − 1)/n · T mod n.
Thus, the product of two given ciphertexts is in fact a valid ciphertext, namely the
encryption of the sum of the originally encrypted messages. Now it is straightfor-
ward to see that the decryption function is a homomorphism. Given two plaintexts
m 1 , m 2 it holds
D ( E (m 1 , r1 ) · E (m 2 , r2 )) = D ( E (m 1 + m 2 , r1r2 )) = m 1 + m 2
= D ( E (m 1 , r1 )) + D ( E (m 2 , r2 ))
10.4.2.1 RSA
Let (e, n ) be the public RSA key (e the public encryption exponent, n the RSA
modulus). For any two messages m 1 , m 2 we obtain the ciphertexts c1 = m 1 e mod n
and c2 = m 2 e mod n. For the product of these two ciphertexts, it holds: c1 · c2 =
m 1 e · m 2 e mod n = (m 1 · m 2 )e mod n. Thus, we obtain an encryption of the product
of the two messages m 1 and m 2 . As it is straightforward to see, this property holds
for any two plaintexts m 1 , m 2 and similar as for Paillier, the decryption function is
a homomorphism. As we have seen here, RSA is an example for a homomorphism,
where both groups have the same group operation.
10.4.2.2 ElGamal
Similar to RSA, we can also show the homomorphic properties of the ElGamal
cryptosystem. Let ( p, g, K ) be the public key while the private key is k (thus, it holds
i i
i i
i i
10.5 Applications
The homomorphic property can be used to add two encrypted values or to multiply
any value under encryption with a known constant (note that the multiplication
corresponds to the repeated application of the addition operation). This makes
homomorphic ciphers important and easy to use base primitives in cryptographic
applications.
i i
i i
i i
• At the end, the result of the election is determined and published; this hap-
pens by decrypting the sum that was computed using the homomorphic
property.
2. A second application of homomorphic ciphers is secure multiparty com-
putation. Here, two or more parties can compute any commonly known
function. Each of the parties provides one or more of the inputs for the
function to be computed. The goal of the secure computations is to keep
all private inputs secret, while only the result of the function is revealed.
The use of homomorphic encryption helps to perform these computations
on encrypted data. However, since the Paillier encryption only allows one to
compute additions of encrypted values (e.g., no multiplications can be per-
formed), a number of additional methods and techniques have to be applied.
The Wikipedia page [11] offers a good start for reading more about this topic
and more advanced techniques for secure multiparty computation.
3. Furthermore, it is expected that homomorphic encryption will provide
great advantages in the area of cloud computing. Using fully-homomorphic
encryption [12] it is possible to run applications on external servers only
on encrypted data. For this, one needs to be able to perform both arith-
metic operations, the addition, and the multiplication on encrypted data
(in contrast to Paillier encryption, which only allows one to perform addi-
tions). Such a cryptosystem was first presented in 2009 [13] and since then
continuously improved [12].
Homomorphic methods are contained in the three CrypTool variants CT2, JCT,
and CTO. Further implementations in Python or SageMath can be found on
the internet. A curated list of homomorphic encryption libraries can be found
at https://github.com/jonaschn/awesome-he, for example the open-source
libraries HEAAN, HElib, SEAL, TFHE, and PALISADE.
i i
i i
i i
i i
i i
i i
References
i i
i i
i i
[2] Gentry, C., A. Sahai, and B. Waters, “Homomorphic Encryption from Learning with
Errors: Conceptually-Simpler, Asymptotically-Faster, Attribute-Based,” in Cryptology
ePrint Archive, 2013, https://eprint.iacr.org/2013/340.
[3] Ducas, L., and D. Micciancio. “FHEW: Bootstrapping Homomorphic Encryption in Less
Than a Second,” in Advances in Cryptology–EUROCRYPT 2015: 34th Annual Inter-
national Conference on theTheory and Applications of Cryptographic Techniques, Sofia,
Bulgaria, April 26-30, 2015, Proceedings, Part I 34, Springer, 2015, pp. 617–640.
[4] Chillotti, I., et al., “TFHE: Fast Fully Homomorphic Encryption Over the Torus,” Journal
of Cryptology, Vol. 33, No. 1, 2020, pp. 34–91.
[5] Cheon, J. H., et al., “Homomorphic Encryption for Arithmetic of Approximate Numbers,”
in International Conference on the Theory and Application of Cryptology and Information
Security, Springer, 2017, pp. 409–437.
[6] Wikipedia, Homomorphic Encryption, https://en.wikipedia.org/wiki/Homomorphic
_encryption.
[7] Schneider, J., Awesome Homomorphic Encryption, https://github.com/jonaschn
/awesome-he.
[8] FHE.org, Libraries, https://fhe.org/resources/libraries.
[9] Döttling, N., et al., Encrypted Computing Compass, v 1.0, Tech. rep., November 2022,
https://www.cyberagentur.de/encrypted-computing-compass/.
[10] Paillier, P., “Public-Key Cryptosystems Based on Composite Degree Residuosity Classes,”
in Advancesin Cryptology—EUROCRYPT ’99, 1999.
[11] Wikipedia contributors, Secure Multiparty Computation, https://en.wikipedia.org/wiki/
Secure_multi-party_computation.
[12] Wikipedia contributors, Homomorphic Encryption and Homomorphismus, Wikipedia,
The Free Encyclopedia, https://en.wikipedia.org/wiki/Homomorphic_encryption; https://
de.wikipedia.org/wiki/Homomorphismus.
[13] Gentry. C., “Fully Homomorphic Encryption Using Ideal Lattices,” in 41st ACM Sympo-
sium on Theory of Computing (STOC), 2009.
[14] Damgard, I., M. Geisler, and M. Kroigard. “Homomorphic Encryption and Secure Com-
parison,” in: International Journal of Applied Cryptography, Vol. 1, No. 1, 2008, pp.
22–31.
[15] Bastian, M., The State of Homomorphic Encryption, 2023, https://www.cryptool.org/
assets/ctp/documents/BA_Heep.pdf (visited on 08/09/2023).
i i
i i
i i
i i
i i
i i
C H A P T E R 11
C H A P T E R 11
Lightweight Introduction to Lattices
In this chapter, our goal is to cover the basic theory behind lattices in a lightweight
fashion. The theory covered is accompanied by many practical examples, SageMath
code, and cryptographic challenges.
Sections 11.1 through 11.7 introduce the notation and methods needed to
work with and understand lattices (this makes up about a third of this chapter).
Sections 11.8 and 11.9 cover lattices in more detail and their application to attack
RSA. Section 11.10 is intended as a deeper look, providing some algorithms for
lattice basis reduction and their use to break cryptosystems. Section 11.12 contains
screenshots of where lattice algorithms can be found in the CrypTool programs.
11.1 Preliminaries
11.2 Equations
0=0
1=1
1+1=2
1.9 = 2
477
i i
i i
i i
x + x = 10
x + y = 10
x+y=z
x1 + x2 + x3 + · · · + x10 = z
In some cases, the solution is straightforward and unique, but in some other cases
we have a set of possible solutions. The domain is the set of input values for which
the equation is defined. For example, the equation x + 1 = −10 has no solution
over N, but has one solution over Z. From now until the end of this chapter, we
will work only with the set of integers Z as the domain.
SageMath makes it easy to define variables. The following declaration defines
the special symbol x as a variable:
sage: x = var('x')
Here is an example of a polynomial: If a coefficient is explicitly written down
(only those different from ±1, such as 5 in the following listing), the multiplication
operator ∗ must be used between the coefficient and the variable term. The symbols
∗∗ mean “to the power of” in both SageMath and Python (i.e., exponentiation).
sage: pol = x + 5*x**2 + x**3
Now, we are ready to construct our equation. Let’s say that we want to find
the solution to the following equation x + x 2 + x 3 = 100. First, we need to define
our left side of the equation. Using SageMath, the declaration is straightforward.
We will refer to the left side of our equation as leq.
For our example we are using a term with no explicitly written coefficients (i.e.,
the coefficients are 1 or 0):
sage: leq = x + x**2 + x**3
We are ready to solve the equation and find the solutions.
sage: eq_sol = solve(leq ==100 , x)
The SageMath command solve() tries to find all x for which x + x 2 + x 3 = 100.
If you run this on your computer, you will see a list of possible solutions that don’t
look like integers. This is because we have defined x as a variable without any
restrictions on its domain. So, let’s define the symbol x as a variable in the domain
of integers, ZZ in SageMath. Integers in SageMath can be further restricted to
Boolean (true or false) or to integers modulo n (IntegerModRing(n) or GF(n) if n
is prime).
sage: x = var('x', domain =ZZ)
i i
i i
i i
Now, when we try to solve the equation, we get as set of solutions the empty set
([] in Python defines an empty list). This means that there is no such x that satisfies
the defined equation.
Instead of using solve(), it is easier and more stable to work with the polynomial
ring: x = polygen(ZZ). This is equivalent to polynomialRing(ZZ, 'x').gen().
sage: x = polygen (ZZ)
sage: p = x + x^2 + x^3
sage: (p - 10^2).roots (ZZ , multiplicities = False )
[]
sage: (p - 14).roots (ZZ , multiplicities = False )
[2]
Here is a reasoning that there is no such integer x that satisfies the defined
equation leq==100. Let’s see the values of the polynomial function x 7→ x + x 2 + x 3
for consecutive values of x:
sage: for i in range (-6 ,6):
....: print(leq(x=i), "for", "x =", i)
-186 for x = -6
-105 for x = -5
-52 for x = -4
-21 for x = -3
-6 for x = -2
-1 for x = -1
0 for x = 0
3 for x = 1
14 for x = 2
39 for x = 3
84 for x = 4
155 for x = 5
258 for x = 6
We can see two characteristics of our equation. First, the left-hand side of the
equation becomes larger as the variable x increases. Second, the solution to our
equation is a noninteger between 4 and 5.
Note: Normally, the term on the left-hand side also includes the number on the
right-hand side if it’s not 0. So the usual way to write this equation is as follows:
x 3 + x 2 + x − 100 = 0.
i i
i i
i i
https://www.cryptool.org/en/documentation/ctbook/sagemath
x110 − 177 x19 + 9143 x18 − 228909 x17 + 3264597 x16 − 28298835 x15 +
+152170893 x14 − 502513551 x13 + 974729862 x12 − 995312448 x1 + 396179424 = 0
x210 − 196 x29 + 12537 x28 − 397764 x27 + 7189071 x26 − 77789724 x25 +
+506733203 x24 − 1941451916 x23 + 4165661988 x22 − 4501832400 x2 + 1841875200 = 0
x56 − 169 x55 + 7702 x54 − 153082 x53 + 1477573 x52 − 6672349 x5 + 11042724 = 0
x79 − 206 x78 + 13919 x77 − 467924 x76 + 8975099 x75 − 102829454 x74 +
+699732361 x73 − 2673468816 x72 + 4956440220 x7 − 2888395200 = 0
We have already introduced the concepts of variables, equations, and the domain
of an equation. We have shown how to declare variables in SageMath and how to
automatically find solutions to single-variable equations using solve(). What if we
have two different variables in our equation? Let’s take the following equation as
an example: x + y = 10. Again we will try to solve this equation using SageMath.
This time we need the tuple (x, y ) as the solution of solve().
sage: x = var('x', domain =ZZ)
sage: y = var('y', domain =ZZ)
sage: solve(x+y==10, (x,y))
(t_0, -t_0 + 10)
We get as a solution x = t0 and y = −t0 +10 and indeed x + y = t0 +(−t0 +10) =
t0 − t0 + 10 = 10. The notation with t0 is used by SageMath to show us that there
are infinitely many integer solutions to the given equation. In correct mathematical
notation, the solution is the following so-called parameterized set. The parameter t0
is used by SageMath to indicate that there is only one degree of freedom, counting
the first degree of freedom as number zero as usual. Outside SageMath we don’t
use this index and write just t:
i i
i i
i i
one, so we can form a system of equations (in a system of equations, the individual
equations are not independent of each other):
(
x + y = 10
x=y
Let’s solve this system of equations. We can easily organize all the equations from
this two-equation system using a list array.
sage: x,y = var('x y', domain =ZZ)
sage: solve ([x+y==10 ,x==y], (x,y))
[[x == 5, y == 5]]
As we can see, we have only the one solution (x, y ) = (5, 5).
A rich collection of mathematical problems can be solved by using systems of
linear equations. For example, let’s take the simple puzzle in Figure 11.1 and solve
it using SageMath.
As usual, each row consists of three items and their total price. Usually, the goal
in such puzzles is to find the price of each individual item. We have three different
items. Let’s define the price of each pencil as x, the price of each computer display
as y, and the price of each bundle of servers as z. From the previous declarations
we can write down the following system of linear equations:
2x + y = 15
x + y + z = 20
3z = 30
We can also solve this puzzle using only pen and paper. The last equation gives the
value of z = 10. If we eliminate the variable z by replacing its value in the previous
equations, we reduce the system to system of two unknown variables:
2x + y = 15
x + y = 10
(z = 10 not unknown anymore)
i i
i i
i i
We can now subtract the second equation from the first to get:
2x + y − (x + y ) = 15 − 10 = 5
⇒ x =5
In the next sections, we will introduce the definition of matrices, which will
help us describe a given system of linear equations in a much more compact way.
i i
i i
i i
11.4 Matrices
Is there a more convenient way to write large systems of linear equations? We will
introduce this way by using augmented matrices. You can think of a matrix as a
rectangular or square array of numbers. The numbers are arranged in rows and
columns. For example, let’s analyze the following matrix:
" #
1 2 3
M=
3 4 5
We have two rows and three columns, and a total of six elements. We define an
element as ai j if we want to emphasize that the element is located in the ith row
and jth column. For example, a11 = 1, a13 = 3, a22 = 4.
Note that here we are using indexing starting from 1, as usual in mathematics.
However, later in the SageMath examples, the index of row and column starts from
0 (as usual in computer languages such as C or Python).
In the following system of linear equations, the independent variables are
labeled a, b, c, d, e, and f .
6a + 7b + 11c + 18d + 4e + 7 f = 5
8a + 14b + 2c + 13d + 2e + f = 19
a + b + 3c + 4d + 4e + 7 f = 15
3a + 4b + c + d + 14e + 17 f = 1
5a + 5b + 2c + 2d + 2e + 6 f = 2
11a + 17b + c + d + e + f = 9
We can easily write this system of linear equations as a matrix. Let’s write all the
coefficients before the variable a in the first column of our new matrix, all the coef-
ficients before the variable b in the second column, and so on. This is the coefficient
matrix.
The right side of each equation forms another column—the last one. For clarity,
we will separate it from the other columns with a vertical line. We call such a matrix
an augmented matrix.
6 7 11 18 4 7 5
8 14 2 13 2 1 19
1 1 3 4 4 7 15
3 4 1 1 14 17 1
5 5 2 2 2 6 2
11 17 1 1 1 1 9
Let’s analyze the behavior of a system of linear equations. We can make the
following observations:
• Swapping the positions of two equations doesn’t affect the solution of the
system of linear equations.
i i
i i
i i
We can easily transform this system of linear equations into an augmented matrix.
4 8 3 10
5 6 2 15
9 5 1 20
Then we begin to transform the matrix into row echelon form. First, we divide the
first row by 4.
4 8 3 10 1 2 0.75 2.5
5 6 2 15 → 5 6 2 15
9 5 1 20 9 5 1 20
The reason for dividing the first row by 4 is simple—we need the first element of
the first row to be equal to 1, which allows us to multiply the first row by 5 and 9
and to subtract it from the second and third rows, respectively. Let’s recall that we
are trying to transform the augmented matrix into the reduced row echelon form.
Now, let’s apply the previous observations.
1 2 0.75 2.5 1 2 0.75 2.5 1 2 0.75 2 .5
5 6 2 15 → 0 −4 −1.75 2.5 → 0 −4 −1.75 2 .5
9 5 1 20 9 5 1 20 0 −13 −5.75 −2.5
We now divide the second row by −4. This will transform the second element of
the second row to 1 and allow us to continue with our strategy of reducing the
i i
i i
i i
And again, following the previous strategy we applied to the first row, we multi-
ply the second row by 2 and subtract it from the first row. Immediately after this
operation, we multiply the second row by 13 and add it to the last row.
1 2 0.75 2 .5 1 0 −0.125 3.75
0 1 0.4375 −0.625 → 0 1 0.4375 −0.625
0 −13 −5.75 −2.5 0 −13 −5.75 −2.5
1 0 −0.125 3.75 1 0 −0.125 3.75
0 1 0.4375 −0.625 0
→ 1 0.4375 −0.625
0 −13 −5.75 −2.5 0 0 −0.0625 −10.625
We are almost done. Now we normalize the last row by dividing it by −0.0625.
1 0 −0.125 3.75 1 0 −0.125 3.75
0 1 0.4375 −0.625 → 0 1 0.4375 −0.625
0 0 −0.0625 −10.625 0 0 1 170
We follow the same steps as in the previous operations. First, we multiply the last
row by 0.125 and add it to the first row. Then, we multiply the last row by 0.4375
and subtract it from the second row.
1 0 −0.125 3.75 1 0 0 25
0 1 0.4375 −0.625 → 0 1 0.4375 −0.625
0 0 1 170 0 0 1 170
1 0 0 25 1 0 0 25
0 1 0.4375 −0.625 → 0 1 0 −75
0 0 1 170 0 0 1 170
We have reduced the augmented matrix to the reduced row echelon form. Let’s
transform the problem back into a system of linear equations.
1 · x + 0 · y + 0 · z = x = 25
0 · x + 1 · y + 0 · z = y = −75
0 · x + 0 · y + 1 · z = z = 170
We now have a tool (algorithm) for solving a system of linear equations. How to
do this with SageMath is described in Section 11.6.
i i
i i
i i
Definition 11.1 Some, but not all, quadratic matrices have inverses; that is, for
A = (ai, j ) there exits a matrix A−1 such that
1 0 ... 0
0 1 ... 0
A · A−1 = .. .. . . ..
. . ..
0 0 ... 1
i i
i i
i i
sage: ~A
[ 0 1/3 0 0]
[1/2 0 0 0]
[ 0 0 1/5 0]
[ 0 0 0 1/7]
sage: B= matrix ([[1,0],[0 ,0 ]])
sage: B. inverse ()
#... lines of error info , ending with:
ZeroDivisionError : matrix must be nonsingular
11.5 Vectors
i i
i i
i i
−→ −→
Let’s express the vectors P Q and R Q with the three points P (0, 1), Q (2, 2),
and R (1.5, 1.5) as shown in Figure 11.4.
We can easily do this by following the definition:
−→
P Q = (2 − 0, 2 − 1) = (2, 1)
−→
R Q = (2 − 1.5, 2 − 1.5) = (0.5, 0.5)
Furthermore, if we define the origin as O (0, 0) and some random point Z (x, y )
−→
we can easily define the vector O Z = (x − 0, y − 0) = (x, y ). Using this observation
we can easily calculate the desired vectors using SageMath.
sage: vOP = vector ([0,1 ])
sage: vOQ = vector ([2,2 ])
sage: vOR = vector ([1.5 ,1.5 ])
sage: vPQ = vOQ - vOP
sage: vRQ = vOQ - vOR
sage: print(vPQ , vRQ)
(2,1) (0.5, 0.5)
−→
Intuitively, we can easily check the results. P Q = (2, 1) means that if we start
at point P and move two times to the right and one time up, we will reach point
−→
Q. Following the same interpretation, R Q = (0.5, 0.5) means that if we start from
point R and move 0.5 to the right and 0.5 up, we will reach point Q.
Figure 11.4 Finding vectors (defining them via start and end points).
i i
i i
i i
Definition 11.5 The zero vector is a vector where all its components are equal to 0
(its origin is the origin of the coordinate system).
xn
i i
i i
i i
x = c1 v1 + c2 v2 + · · · + ck vk
x1 y1 + x2 y2 + · · · + xn yn
is called the dot product, or scalar product, or inner product of x and y and is
denoted by x · y.
We will not use the Definitions 11.10 to 11.12 in the following sections, but
they are useful consequences of the previous definitions.
Definition 11.10 For nontrivial vectors x = (x1 , x2 , . . . , xn ), y = ( y1 , y2 , . . . , yn )
x·y
in R n there exists θ with 0 ≤ θ ≤ π or 0◦ ≤ θ ≤ 180◦ and ||x||·||y|| = cos θ. Then θ
is called the angle between x and y.
Definition 11.11 If x · y = 0, then x is orthogonal to y. If x is a scalar multiple of
y, then x is parallel to y.
We can easily calculate the inner product of two vectors using SageMath.
sage: x = vector ([5,4,1 ,3 ])
sage: y = vector ([6,1,2 ,3 ])
sage: x*y
45
sage: x. inner_product (y)
45
We can either use the multiply operator or be more strict and use the second
syntax. In fact, x · y = 5 · 6 + 4 · 1 + 1 · 2 + 3 · 3 = 45.
Now it’s time to define the building blocks of a vector space.
Definition 11.12 For any arbitrary, nonzero vector v ∈ R n , u = 1
kvk · v is a unit
vector. In R n , unit vectors of the form:
i i
i i
i i
x = x1 e1 + x2 e2 + · · · + xn en
We introduced the concept of matrices, more specifically the coefficient matrix and
the augmented matrix (see Section 11.4). We studied the Gaussian elimination and
how to use it to solve a system of linear equations.
So, let’s solve the following system of linear equations using SageMath:
i i
i i
i i
We have already defined operations for dealing with vectors (see Defini-
tion 11.4 and Definition 11.9). Let’s use the same operations when dealing with
matrices.
Definition 11.13 (Addition) Given two matrices A = [ai j ]m×n and B = [bi j ]m×n ,
the sum of A + B is defined by
A + B = [ai j + bi j ]m×n
Definition 11.14 Given a matrix A = [ai j ]m×n and a real number k, the scalar
multiple k A is defined by
k A = [kai j ]m×n
Definition 11.15 Given two matrices A = [ai j ]m× p and B = [bi j ] p×n , we define the
product AB of A and B, so that AB = [ci j ]m×n = C, where
ci j = ai 1 b1 j + ai 2 b2 j + ai 3 b3 j + · · · + ai p b pj
Note that the number of columns of the first factor must be equal to the number of
rows in the second factor.
i i
i i
i i
sage: A*B
[128 59 32]
[ 40 10 16]
[ 32 11 11]
From the definition of a product of two matrices, we can make the following
observations: The inner product (see Definition 11.9) of the ith row vector of A
and the jth column vector of B is the (i, j ) entry of C = AB. To demonstrate this
observation we first must introduce another simple definition:
Definition 11.16 The transpose of a matrix is a new matrix whose rows are the
columns of the original; that is, if A = [ai j ]m×n , then A T , the transpose of A, is
A T = [a ji ]n×m .
40
10
16
32
11
11
Note the preference of SageMath operators:
A*B.transpose() = A*(B.transpose()) and not (A*B).transpose()
In order to introduce the concept of a lattice, we need some more definitions.
Let’s look at the next system of equations and try to express each of the variables
x, y, and z as an expression of the coefficients a, b, c, d, e, f, g, h, i, r1 , r2 , r3 .
ax + by + cz = r1
d x + ey + f z = r2 (11.1)
gx + hy + i z = r3
i i
i i
i i
Let’s multiply the first equation in (11.1) by ei, the second equation by hc, and the
last equation by b f .
Again, using (11.1), we multiply the first line by f h, the second line by bi, and the
last line by ce.
a f hx + b f hy + c f hz = f hr1
dbi x + ebi y + f bi z = bir2 (11.3)
gcex + hcey + icez = cer3
Now we derive a new equation by subtracting from the sum of all (11.2) and the
sum of all (11.3):
Following the same procedure, and carefully choosing the coefficients with
which to multiply the equations, we can also express y and z. But what if we have
a system of 100 equations with 100 variables? Moreover, how does one use a more
elegant way to recover the variables? It’s time to introduce the definitions of minors
and determinants.
i i
i i
i i
Example
a b c
Let’s have a matrix A = d e f . By the definition of minors we have M11 =
g h i
d f a c
e f
, M12 = g i or M22 = i .
h i g
Let’s take the general case of a matrix A with size n.
a1,1 a1,2 a1,3 . . . a 1, j . . . a1,n
a2,1 a2,2 a2,3 . . . a 2, j . . . a2,n
. . . a 3, j . . . a3,n
a3,1 a3,2 a3,3
... ... ... ... ... ... ...
A=
a
i,1 ai,2 ai,3 . . . ai, j . . . ai,n
... ... ... ... ... ... ...
an,1 an,2 an,3 . . . an, j . . . an,n
Then the minor Mi j of A is equal to
a b
det ( B ) = = (−1)1+1 · a · d + (−1)1+2 · b · c = ad − bc
c d
i i
i i
i i
Note that in the above calculation, |d| and |c| do not denote the absolute values of
the numbers d and c, but the determinants of the 1 × 1 matrices consisting of d or
c, the minors d = M11 and c = M12 of the matrix B. Note also that det(x ) = x for
every 1 × 1 matrix with entry x, so |d| = d and |c| = c in the last step.
Example
Expansion along column 2:
a b c
det (C ) = d e f
g h i
d f a c a c
= (−1)1+2 · b · + (−1)2+2 · e · + (−1)3+2 · h ·
g i g i d f
= −b(di − f g ) + e(ai − cg ) − h (a f − cd ) =
= aei + dhc + gb f − a f h − dbi − gce
The determinant of this example is exactly equal to the denominator of the right
side of (11.4). What about the numerator? We can easily verify that the numerator
r1 b c
is equal to the determinant of the matrix B1 = r2 e f . If we define the matrices
r3 h i
a r1 c a b r1
B2 = d r2 f and B3 = d e r2 , we can easily calculate the solutions x, y
g r3 i g h r3
and z of the given system of linear equations:
i i
i i
i i
i i
i i
i i
13
3
7
This gives the final solutions x = 13, y = 3, and z = 7.
72 82 88 83 23
i i
i i
i i
Example Let’s define the set M of all 2 × 2 matrices with entries of real numbers.
Furthermore, we choose the operator ⊕ as a regular additive operator on matrices;
that is, ! ! !
a1 a2 b1 b2 a1 + b1 a2 + b2
⊕ = .
a3 a4 b3 b4 a3 + b3 a4 + b4
We can easily check that all the conditions hold and that this is indeed a vector
space, in which the zero vector is ( 00 00 ).
Example The set P of polynomials with real coefficients is a vector space with
the operator ⊕ defined as the
P regular P
additive operator on polynomials and the
operator defined via r ( ai x i ) := rai x i . For example, if ai , bi , r ∈ R, then:
(a0 + a1 x + · · · + an x n ) ⊕ (b0 + b1 x + · · · + bn x n ) =
= (a0 + b0 ) + (a1 + b1 )x + · · · + (an + bn )x n
r (a0 + a1 x + · · · + an x n ) = (ra0 ) + (ra1 )x + · · · + (ran )x n
Definition 11.20 For any vector space V with operations ⊕ and , a subspace U
is a subset of V which is itself a vector space over the same field under the inherited
i i
i i
i i
operations ⊕ and . This means that U is closed under addition ⊕ and scalar
multiplication .
Example A trivial subspace of R2 is the 1-element set of the zero vector {(0, 0)}.
Cu = {a + bx + cx 2 + d x 3 | a, b, c, d ∈ R}
Note that S itself need not be a subspace, but span( S ) is always a subspace of V . If
span( S ) = U , we say that S generates (or spans) U .
Example For any nonzero vector xE ∈ R3 , the span of xE is a line through the origin
(0, 0, 0), or, more precisely, a one-dimensional subspace containing the zero vector.
Note that a point (e.g., the origin) is not the same as a vector (e.g., the zero vector).
r 2 = 2. ! ! ! ! !
5 2 2 5 4 9
· +2· = + =
2 2 −2 5 −4 1
The previous example is one way of spanning R2 . Can the set R2 be spanned
by three or more vectors? Sure, we can just duplicate one
of the
elements in the
previous example, namely we can take the set ( 22 ), −22 , −11 . But can R2 be
spanned by only one vector? The answer is of course no, because one vector can
only span a 1-dimendional space.
Definition 11.22 A subset of a vector space is said to be linearly independent if
none of its elements is a linear combination of the others. Otherwise it is said to be
linearly dependent.
i i
i i
i i
Definition 11.23 A basis of a vector space is a set B of vectors that is linearly inde-
pendent and spans the space. If |B| = n for some n ∈ N, we define the dimension
of span( B ) as dim (span( B )) := n. If |B| = ∞, the notion of dimension is also
well defined, but the theory is a bit more complicated because of different types of
infinity in mathematics. We will not go into detail here.
Example We have already shown that the set , 2 is a basis of R2 . Another
2
( 2 ) −2
one is ( 0 ), ( 1 ) .
1 0
i i
i i
i i
[2, 1, 3]
sage: per. inverse ()
[2, 3, 1]
sage: per. complement ()
[1, 3, 2]
sage: matrix (per)
[0 1 0]
[0 0 1]
[1 0 0]
sage: grelt= PermutationGroupElement ([1 ,3 ,2 ])
sage: grelt. matrix ()
[1 0 0]
[0 0 1]
[0 1 0]
An interesting thing about these permutation matrices is that their inverse is
identical to their transposed matrix:
sage: matrix (per). inverse () == matrix (per).T
True
E (encode( M ), km ) = km · encode( M ).
i i
i i
i i
1. The length of the encrypted message uniquely defines the key km that
Bob should use.
2. Bob constructs the decryption key dm by replacing every element
greater than zero in the secret key km with its reciprocal value.
3. Bob then performs the decryption; that is, D ( E (encode( M ), km )) =
E (encode( M ), km ) · dm .
4. Bob decodes the decrypted message to recover the original message.
Can you verify the correctness of this encryption scheme? Why does this
decryption work or why does it not? Can you recover the following encrypted
ciphertext (one word):
(6852, 3475, 17540, 3076, 12217, 6383, 745, 1347, 661, 6088, 15354, 2384,
2097, 11415, 3143)
Note the third step from Bob in the Challenge 11.6: The matrix dm is not the inverse
of km . The matrix km can be written as a product km = P · D with a diagonal
matrix D and a permutation matrix P. Then km −1 = ( P · D )−1 = D −1 · P −1 =
Instead of using the matrix dm on a column vector from the left, we can let the
T
matrix dm operate on a row vector from the right, since in general for matrices A
and column vectors v and b there is an equivalence Av = b ⇔ ( Av )T = b T ⇔
v T A T = b T . This corresponds to the notation from above, where in the encryption
process, E (encode( M ), km ) = km · encode( M ) means km · encode( M ) as well as
encode( M ) is treated as a column vector while in the decryption process, dm is
written on the right of E (encode( M ), km ), so in this case E (encode( M ), km ) as
well as E (encode( M ), km ) · dm is treated as a row vector.
11.8 Lattices
Now we have all the building blocks to introduce the concept of lattices.
Definition 11.24 Let v1 , . . . , vn ∈ Zm , m ≥ n be linearly independent vectors. An
integer lattice L spanned by {v1 , . . . , vn } is the set of all integer linear combinations
of v1 , . . . , vn , such that:
n
( )
X
L = v ∈ Zm | v = ai vi , ai ∈ Z (11.6)
i =1
Note: Linear combination means that all ai are integers. Integer lattice means that
all vi j (components of vectors vi ) are integers, and thus all points in the infinite
graph have integer coordinates.
i i
i i
i i
SageMath uses the notion of an integral lattice, which is a slightly more com-
plicated concept. Roughly speaking, the components of the vectors v1 , . . . , vn are
not restricted to Z, but can be arbitrary real numbers, while the allowed linear com-
binations
Pn still have to be integer linear combinations; that is, the coefficients ai in
v
i =1 i i have to be integers. Every integer lattice is an integral lattice.
a
The set of vectors B = {v1 , . . . , vn } is called a basis of the lattice L. We also say
that L = L ( B ) is spanned by the vectors of the basis B.
We define the dimension of L as dim( L ) := n.
In the case where n = m, we can canonically construct a quadratic matrix
from the vectors of a lattice basis by writing them down row by row (or column
by column). If we denote this matrix by M, we can compute the product M · M T ,
which is sometimes called the Gram matrix of the lattice. If this Gram matrix has
only integer entries, the lattice is integral. Note that to go into detail here we would
have to introduce some more mathematics, in particular the theory of quadratic
forms, symmetric bilinear forms, and so on, which are a kind of generalization of
the vector product introduced earlier.
The example in Figure 11.6(a) shows a two-dimensional lattice with
Figure 11.6 Example of 2D lattices with different basics: (a) ba and (b) Bb .
i i
i i
i i
i i
i i
i i
Definition 11.25 Any set of distinct nonzero natural numbers is called a knapsack.
Furthermore, if this set can be arranged in an increasing list in such a way that
each number is greater than the sum of all previous numbers, we call this list a
superincreasing knapsack.
0, 0, 1, 2, 3, 6, 12, 25, 49, 98, 197, 394, 787, 1574, 3148, 6296,
12593, 25185, 50371, 100742, 201484, 402967, 805935, 1611870,
3223740, 6447479, 12894959, 25789918, 51579835, 103159670,
206319340, 412638681, 825277361, 1650554722, 3301109445,
6602218890, 13204437779, 26408875558, 52817751117, 105635502233,
211271004467, 422542008933, 845084017867, 1690168035734,
3380336071467, 6760672142934, 13521344285869, 27042688571737,
54085377143475
• Public key, used only for encryption. It’s called a hard knapsack.
• Private key, used only for decryption. It consists of a superincreasing knap-
sack, a multiplier, and a modulus. The multiplier and modulus can be used
to transform the superincreasing knapsack into the hard knapsack.
i i
i i
i i
Example Let’s assume that Alice wants to encrypt and send the message crypto to
Bob using the Merkle-Hellman knapsack cryptosystem. Throughout this example,
each letter is treated independently. Thus, n is always 8, because each letter has an
8-bit binary representation.
First, Bob must generate his private and public keys. Bob initiates the process
of generating the private key by first generating a superincreasing knapsack W :
r = 2333 < q
(2333, 48433) = 1
Pr = ([11, 28, 97, 274, 865, 2567, 7776, 23253], 2333, 48433)
i i
i i
i i
The final step for Bob is to generate the hard knapsack H and the public key Pu =
( H ) and deliver it to Alice:
Before encrypting the message M = crypto, Alice divides the message into
individual letters and replaces each letter with its own bit representation; that is:
c = 01100011
r = 01110010
y = 01111001
p = 01110000
t = 01110100
o = 01101111
Now, Alice computes the corresponding encrypted number for the bit representa-
tion of each letter using the public key H . Thus, the algorithm must be applied six
times. Finally, the list of encrypted numbers C of the word crypto is:
The largest element less than 7901 is 7776. We continue with this algorithm
until we reach 0.
i i
i i
i i
i i
i i
i i
H = [h 1 , h 2 , · · · , h 8 ]
All rows are linearly independent. Furthermore, we add another row to the lattice
by inserting the encrypted number c as the last element.
1 0 0 0 0 0 0 0 h1
0 1 0 0 0 0 0 0 h2
0 0 1 0 0 0 0 0 h3
0 0 0 1 0 0 0 0 h4
L=
0 0 0 0 1 0 0 0 h5
0 0 0 0 0 1 0 0 h6
0 0 0 0 0 0 1 0 h7
0 0 0 0 0 0 0 1 h8
0 0 0 0 0 0 0 0 c
Again, all the rows are linearly independent. However, we know that c is an exact
sum of some h’s. Our strategy is to find another basis of this lattice that contains
at least one vector with a last element equal to 0. Moreover, since it can be repre-
sented as a linear combination of the vectors of the current basis, we know that this
particular vector will only have elements equal to 0 or −1. A value of 0 in column
i tells us that h i doesn’t participate in the decomposition of c, while −1 indicates
that h i is used in the construction of c.
But how to find such a basis? The following algorithm will help us:
i i
i i
i i
Theorem 11.1 (Lenstra, Lenstra, Lovász [4, 5]) Let L ∈ Zn be a lattice spanned by
B = {b1 , . . . , bn }. The L 3 algorithm returns a reduced lattice basis {v1 , . . . , vn } with
n (n−1) 1
kvi k ≤ 2 4(n−i +1) det( L ) n−i +1 for i = 1, . . . , n (11.7)
in time polynomial in n and in the bit size of the entries of the basis matrix B.
In other words, the L 3 algorithm will produce another basis of the lattice con-
sisting of vectors with restrained norms given by the inequality in Theorem 11.1.
The L 3 algorithm is already built into SageMath.
Example Let’s say Eve intercepts a message between Alice and Bob that is encrypted
using the Merkle-Hellman knapsack cryptosystem. Since everyone has access to the
public key of the cryptosystem, Eve also has it. The intercepted message C is:
To recover the message, Eve must decrypt each element c in C. For example, let’s
start with c = 318668.
sage: H = [106507, 31482 , 107518 , 60659 ,
80717, 81516 , 117973 , 87697]
sage: c = 318668
Then we start to construct the lattice by first building the identity matrix:
sage: I = identity_matrix (8)
sage: I
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1
We add another row full of zeros:
sage: I = I. insert_row (8 , [0 for x in range (8)])
sage: I
i i
i i
i i
1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0
Finally, we add the last column with H transposed and c. However, we will
flip the sign of c; so the first vector of the reduced basis should have a last element
equal to 0 and all other elements equal to 1 (instead of −1).
sage: L_helper = [[x] for x in H] # vector of vectors
sage: L_helper . append ([-c])
sage: L = I. augment ( matrix ( L_helper ))
sage: L
1 0 0 0 0 0 0 0 106507
0 1 0 0 0 0 0 0 31482
0 0 1 0 0 0 0 0 107518
0 0 0 1 0 0 0 0 60659
0 0 0 0 1 0 0 0 80717
0 0 0 0 0 1 0 0 81516
0 0 0 0 0 0 1 0 117973
0 0 0 0 0 0 0 1 87697
0 0 0 0 0 0 0 0 −318668
To reduce the basis, we will now apply the L 3 algorithm by simply calling the
SageMath LLL() function.
sage: L.LLL ()
0 1 0 0 0 1 1 1 0
−1 1 0 1 −1 −2 −2 2 1
3 1 2 −1 1 1 −1 1 1
1 −1 −2 −1 −3 −1 1 1 1
2 −2 −1 1 0 2 −3 1 1
0 0 3 −4 −2 1 0 0 0
−1 3 −1 3 0 0 −1 −3 2
0 −1 1 4 0 0 0 0 4
−2 −1 −2 −3 1 −1 2 1 3
The first candidate (the shortest vector in the reduced basis) is the one we were
looking for:
sage: L.LLL ()[0][:-1]. dot_product ( vector (H))
318668
i i
i i
i i
RSA is one of the first asymmetric cryptosystems. The inner workings of RSA
have been thoroughly explained and demonstrated in Chapter 5 of this book. This
section assumes that you are already familiar with how the RSA cryptosystem
works. However, we will briefly review the basics of key generation for the RSA
algorithm using SageMath. Then we show how RSA can be attacked using lattices.
i i
i i
i i
strings into numbers). Throughout this section, we will use the following encoding
procedure:
For example, let’s encode the word asymmetric. First, we replace each symbol
of S with its corresponding decimal ASCII value:
sage: S = " asymmetric "
sage: S_ascii = [ord(x) for x in S]
sage: S_ascii
[97, 115, 121, 109, 109 , 101 , 116 , 114 , 105 , 99]
Then we replace each element in S_ascii with its binary equivalent. To get rid
of the leading 0b of the binary strings, we use [2:].
sage: S_bin = [bin(x)[2 :]. zfill (8) for x in S_ascii ]
sage: S_bin
['01100001 ', '01110011 ', '01111001 ', '01101101 ', '01101101 �
� ',
'01100101 ', '01110100 ', '01110010 ', '01101001 ', '01100011 �
� ']
Finally, we concatenate all the elements in S_bin and convert this concatenation
to a decimal number:
sage: SS = Integer (''. join( S_bin ),2)
sage: SS
460199674176765747685731
To check the reversibility of the encoding procedure, let’s decode the result
back:
sage: SS_bin = bin(SS)[2 :]
sage: SS_bin
'110000101110011011110010110110101101101011001010111010001 �
� 1100100110100101100011 '
sage: len( SS_bin )
79
i i
i i
i i
b−In the previous example, we generated a random prime number in the interval
1 + 2 , 2 − 1 . Let’s say we have two primes in this interval; that is,
b−2 b
2
p = 2b−1 + 2b−2 + ρ1
q = 2b−1 + 2b−2 + ρ2
This guarantees that the bit length of their product is 2b. The method nbits()
returns the bit length of a number.
sage: p.nbits ()
512
sage: q = random_prime (2 **b-1 , lbound =2 **(b-1)+2 **(b-2)); �
� q.nbits ()
512
sage: N = p*q; N.nbits ()
1024
It’s time to choose the public exponent e. A common choice of value for e is
216 + 1.
sage: e = 2**16 + 1; e
65537
SageMath has a built-in function euler_phi(). However, if we directly type
euler_phi(N), SageMath will try to factor N = pq. It’s better to manually calculate
the number of positive integers that are relatively prime to N and not greater than N
(this is easy as we know the factors of N and can use the formula—see Section 5.8.2):
i i
i i
i i
i i
i i
i i
i i
i i
i i
Suppose further that there exists an integer solution x0 for the modular equation
1
f (x ) ≡ 0 mod N , such that x0 < N r . D. Coppersmith showed how we can recover
this value in polynomial time by using Theorem 11.2 of Howgrave-Graham, which
we cite in the form of Alexander May’s survey (see [10, p. 6]).
Theorem 11.2 Let n, m ∈ N and g (x ) be a univariate polynomial with n monomials.
If we have some constraint X for |x| and the following equations hold:
N
v1 v2 vn X x i
g (x ) = v0 + x + 2 x2 + · · · + n xn = vi (11.9)
X X X X
i =0
g (x0 ) ≡ 0 mod N m
|x0 | ≤ X
i i
i i
i i
deg(g ) = n
Nm
||g (x X )|| < √
n+1
Following the results of Theorem 11.2, we can conclude that g (x0 ) = 0 over
the integers.
We can easily create polynomials that have the same root x0 over N m (we follow
[9, p. 69, p. 80]). Consider the family of polynomials gi, j (x ), such that
By construction, they all have the same root x0 over N m ; that is, gi, j (x0 ) ≡ 0
mod N m . The larger the value of m, the more polynomials we can construct. The
more polynomials we construct, the larger the lattice, and the longer it will take to
reduce the lattice.
Now imagine that Eve intercepted a series of plaintext messages between Alice
and Bob. The messages were:
The password for AES usage is: 4{8dXY!
The password for AES usage is: 31kTbwj
The password for AES usage is: 2rr#ETh
···
The password for AES usage is: &H,45zU
Then, Alice and Bob start exchanging AES-encrypted files using the communi-
cated password. When a new password is received, they immediately start using it.
However, they realize that this is completely insecure and increase their security by
using RSA.
They use the same encoding procedure that was demonstrated at the beginning
of this section. As we showed, the word asymmetric is encoded into the decimal
number 460199674176765747685731.
Let’s say Alice wants to send an RSA-encrypted string message S to Bob. She
first encodes it to the decimal integer D. To denote the message, we use the upper-
case D rather than the more common m, since m is the exponent of N in our context.
Also, an uppercase M is not a good choice because it will be used later in the code
examples for a matrix. Then she encrypts the number D using Bob’s public key
( N , e), that is c = ( D e ) mod N , and sends the encrypted message c over the inse-
cure channel. Bob recovers the original message D using his private exponent; that
is, cd = D mod N . Eve intercepts c.
Bob’s public key has parameters ( N , 3), where the bit length of N is 512. The
predictive nature of the message (popularly called “stereotyped messages”) can lead
to a devastating attack. Eve knows that the structure of the string message S is
for some characters Ci . Before encrypting, Alice must translate each character to
its ASCII binary string representation. Let’s denote the binary translation function
i i
i i
i i
as T1 ; that is, T1 ("xy") = T1 ("x")||T1 ("y"), where the symbol || denotes the
concatenation of strings.
With this in mind, we can write:
After this translation, Alice reads the final binary string as a decimal number.
Let’s call this function T2 ( S 0 ).
Each ASCII decimal representation of Ci is in the interval [0, 255]. Let’s call
the symbol with ASCII decimal representation 0 C00 , and the symbol with ASCII
decimal representation 255 C f f . So we choose indices in hexadecimal notation. For
simplicity, let’s denote
T2 (T1 ( B||C00 C00 · · · C00 )) < T2 (T1 ( B||C1 C2 · · · C7 )) < T2 (T1 ( B||C f f C f f · · · C f f ))
Since Eve knows c and a, she can reconstruct D if she is able to find a positive
integer x < X that satisfies the equation
(a + x )3 ≡ c mod N .
(a + x )3 − c ≡ 0 mod N
Let’s pause for a moment and implement the current polynomial using SageMath.
First, we introduce the encode() function—it is equivalent to T2 (T1 ( D )). Here is
an example of how to call this function and what it outputs:
encode("A"): 65, encode("AB"): 16706, encode("ABC"): 4276803
sage: def encode (D):
....: return Integer (''. join ([ bin(ord(x))[2 :].
....: zfill(8) for x in D]) ,2)
We introduce the expected starting characters of the encrypted message.
i i
i i
i i
i i
i i
i i
i i
i i
i i
After this first case, which we could solve with m = 1 (see (11.10) after
Theorem 11.2), we will now look at another example where we need a larger m.
i i
i i
i i
c = 74875898628081924295230958863232737993265641657662214847638
483603488006886812559351998510022388544254768721487918947883514
84389959862897996873514056282948
Can you recover the newly exchanged password? Here are a few things to
consider:
f 0 = (a 3 − c)2
f 1 = 6a 2 (a 3 − c)X
f 2 = a(15a 3 − 6c)X 2
f 3 = (20a 3 − 2c)X 3
i i
i i
i i
In general, if Alice uses an encryption exponent of e, then for this type of attack
to work, Eve must know e−e 1 of Bob’s message; see [9, p. 96].
Screenshots of CT1 (Figures 11.9 to 11.11) and CT2 (Figure 11.16) of
ready-to-run lattice-based implementations of attacks against RSA can be found
in Sections 11.12.1 and 11.12.2.
This chapter has thus far given a deeper, mathematical challenging outlook provid-
ing some algorithms for lattice basis reduction and their usage to break cryptosys-
tems. At the end, we will briefly discuss the lattice-based procedures of the NIST
standardization for PQC.
A given lattice has infinitely many different bases. The main goal of lattice basis
reduction is to find (by using some lattice basis as an input) a basis that consists
of short vectors, or, equivalently, a basis consisting of vectors that are pairwise
nearly orthogonal. Thus, the reduced basis may lead to a solution of an underly-
ing problem, like breaking a knapsack cryptosystem, as we have already shown
in Section 11.8.2.
Let’s first introduce the notion of Gram-Schmidt orthogonalization named after
the mathematicians Jørgen Pedersen Gram and Erhard Schmidt.
Definition 11.26 With an ordered lattice basis b1 , · · · , bm ∈ Rn we associate
the Gram-Schmidt orthogonalization b̂1 , . . . , b̂m ∈ Rn which can be computed
bi ·b̂ j
from b1 , · · · , bm together with the Gram-Schmidt coefficients µi, j = by the
b̂ j ·b̂ j
recursion
b̂1 = b1
P 1
b̂i = bi − i−
j =1 µi, j b̂ j i = 2, . . . , m
Let span(b1 , . . . , bi−1 )⊥ be the set of all vectors orthogonal to span(b1 , . . . , bi−1 );
that is,
i−1
X
span(b1 , . . . , bi−1 )⊥ = {v ∈ Rn v · x j b j = 0 ∀x j ∈ R}.
j =1
i i
i i
i i
For any real number x, dxc denotes the closest integer; that is, dxc = bx + 0.5c.
i i
i i
i i
6
= {(1, 7) − · (−1, 1), (−1, 1)}
2
= {(1, 7) − 3 · (−1, 1), (−1, 1)}
= {(4, 4), (−1, 1)}
√ √
Now ||a|| = 32 > 2 = ||b|| and we need another iteration:
a·b
{a, b} = {b − · a, a}
a·a
(4, 4) · (−1, 1)
= {(−1, 1) − · (4, 4), (4, 4)}
(4, 4) · (4, 4)
0
= {(−1, 1) − · (−1, 1), (4, 4)}
32
= {(−1, 1), (4, 4)}
√ √ √
Since ||a|| = 2< 32 = ||b|| < 34 = ||a − b||, the algorithm ends.
Output: {a, b} = {(−1, 1), (4, 4)}
The vector (−1, 1) is a shortest nonzero vector in L and (4, 4) is a shortest vector
of L that is linear independent of (−1, 1).
The two algorithms for calculating respectively the ordered lattice basis and
LLL-reduced δ basis, are summarized in the Crypto Procedures 11.2 and 11.3.
i i
i i
i i
i i
i i
i i
Remark: In the literature, the notion of BKZ-reduced bases is also used for block-
reduced bases.
Although there is no proven polynomial bound for the number of operations
of any algorithm to √ calculate a (β, δ )–block-reduced basis for β > 2 (except for
β = 3 and δ ∈ [ 12 , 12 3); see [16]), the following algorithm proved to be efficient
i i
i i
i i
in practice for small bock sizes (β ≤ 30). Its core component is the enumeration
algorithm verb!enum(j,k)! which finds an integer, nonzero minimum (u j , . . . , u k )
of the following term:
k
X
c j (ũ j , . . . , ũ k ) := ||π j ( ũ i bi )||22 , (ũ j , . . . , ũ k ) ∈ Zk− j +1
i= j
Before going into the details of enum(j,k) let’s have a look at the block-reduction
algorithm in the Crypto Procedure 11.5. It cyclically iterates over all positions j,
ensures that the basis is size-reduced, and that it is enforced for all j:
δ||b̂ j ||2 ≤ λ21 ( L (π j (b j ), . . . , π j (bmin ( j +β−1,m )))
i i
i i
i i
Step 2
g ← max{t : j ≤ t ≤ k, u t 6= 0}
Step 3
while |u g | > 1 do
i ← max{t : j ≤ t < g : u t 6= 0}
q ← u g /u i
ui ← u g − q · ui
u g ← u iold
bg ← q · bg + bi
bi ← bgold
Step 4
for i = g, . . . , j + 1 do
bi ← bi−1
Step 5
b j ← bnew
j
output b1 , . . . , bm
||b̂t ||2 = ||πt (bt )||2 , we get c̃t = c̃t +1 + (ũ t + ik=t +1 ũ i µi,t )2 ct . For fixed
P
(ũ t +1 , . . . , ũ k ) we can easily enumerate all integers ũ t , lsuch that correspond-
k
ing values of c̃t are nondecreasing, starting with ũ t = − ik=t +1 ũ i µi,t . The
P
(basic) variant of algorithm enum in Crypto Procedure 11.7 traverses the result-
ing search tree in depth-first search order. Other variants (e.g., traversing the tree
in breadth-first search order or incomplete—pruned—traversals) are given in [16].
i i
i i
i i
ũ t ← vt ← d−yt c , ∆t ← 0
if ũ t > −yt then
δt ← −1
δt ← 1
c j ← c̃ j , u i ← ũ i for i = j, . . . , k
t ←t +1
s ←max(s, t )
if t < s then
∆t ← − ∆t
if ∆t δt ≥ 0 then
∆t ← −∆t + δt
ũ t ← vt + ∆t
output (u j , . . . , u k ), c j
i i
i i
i i
Public Parameters:
Natural numbers r, n, s. (Messages consist of n blocks with s bit each, r is the
number of rounds to create the keys.)
Secret Key:
(0) (0)
(0) P 1 (0)
Integers ai = 1, ai > (2s − 1) i−
with a1 j =1 a j for i = 1, . . . , n and natural
numbers q2 , p , w for k = 1, . . . , r , where q1 := p (r ) /q2 is an integer.
(k ) (k )
(0)
The part {ai } of the secret key represents an easy knapsack. It is transformed
in a hard knapsack by the following transformations:
(k ) (k−1) (k )
ai := ai w(k ) mod p (k ) for i = 1, . . . , n + k − 1, an +k := − p (k ) ,
j k
(k ) (k )
fi := 2−prec(k ) ai 2prec(k ) / p(k ) for i = 1, . . . , n + k − 1, k = 1, . . . , r,
(r )
ai, j := ai mod q j for i = 1, . . . , n + r − 1, j = 1 , 2.
Public Key:
• Natural numbers q1 , prec(k ) for k = 1, . . . , r − 1;
• Nonnegative integers ai, j for i = 1, . . . , n + r − 1, j = 1 , 2;
(k )
• Rational numbers f i ∈ 2− prec(k ) [0, 2prec(k ) ) for k = 1, . . . , r − 1, i =
1, . . . , n + k − 1.
i i
i i
i i
n+
Xr −1
xi ai,1 = y1 mod q1 (11.11)
i =1
n+
Xr −1
xi ai,2 = y2 (11.12)
i =1
$n +k−1 %
(k )
X
x n +k = xi f i or k = 1, . . . , r − 1 (11.13)
i =1
Let’s transform these equations into a set of r + 1integer linear equations with
m 0-1-unknowns, where m := ns + (r − 1)(r /2 + s + log2 n − 1) + rk−
P 1
=1 prec (k ).
(k ) prec(k )
Since f i 2 ∈ [0, 2prec(k ) ) is integral we can write (11.13) as
n+ k−1
xn +k 2prec(k ) =
(k ) prec(k )
X
xi f i 2 − xn +r +k−1 for k = 1, . . . , r − 1, (11.14)
i =1
i i
i i
i i
With
(k )
f i 2prec(k ) for i = 1, . . . , n + k − 1
prec(k )
for i = n + k
−2
ai,k +2 := 0 for i = n + k + 1, . . . , n + r + k − 2
−1 for i = n + r + k − 1
for i = n + r + k, . . . , n + 2r − 2
0
n +2
X r −2
xi ai,k +2 = 0 for k = 1, . . . , r − 1 (11.15)
i =1
The unique solution of (11.11), (11.12), (11.15) directly transforms into the
unique solution of (11.11) - (11.13). To get 0 − 1-variables we use the binary
representation of the integer variables.
We set
s for 1 ≤ i ≤ n
s + i + log2 n − n − 1 for n + 1 ≤ i ≤ n + r − 1
di :=
prec(i − (n + r − 1)) for n + r ≤ i ≤ n + 2r − 2
P 1
and Di := i− j =1 d j .
Let t Di +1 , . . . , t Di +di ∈ {0, 1} be the binary representation of xi ; that is,
i −1
dX
xi = t Di +l +1 2l ,
l =0
and set
m
X
ti Ai,1 = y1 + zq1
i =1
m
X (11.16)
ti Ai, j = y j for j = 2, . . . , r + 1,
i =1
ti ∈ {0, 1}, z ∈ Z
i i
i i
i i
m
X
ci Ai,1 + cm +2 y1 = 0 mod q1
i =1
m
X
ci Ai, j + cm +2 y j = 0 for j = 1, . . . , r + 1.
i =1
s−1
X
xi := |vs (i−1)+ j +1 − v0 |2 j−1 for i = 1, . . . , n.
j =0
To find a vector with l∞ -norm 1 we modify algorithm enum in order to search for
short vectors in l∞ norm instead of the Euclidean norm ||.||2 . To do that we make
use of Hölder’s inequality [22, p. 347]:
The
Pn expression n||y||1 is defined to be the l1 -norm of y, given by ||y||1 :=
i =1 |yi |, y ∈ R .
For t = m, . . . , 1 we define the following functions wt , ct with integer
arguments ũ t , . . . , ũ m (using the notions of Definition 11.26):
m m
! !
X X
wt := wt (ũ t , . . . , ũ m ) := πt ũ i bi = wt +1 + ũ i µi,t b̂t
i =t i =t
m
!2
X
c̃t := c̃t (ũ t , . . . , ũ m ) := ||wt ||22 = c̃t +1 + ũ i µi,t ||b̂t ||22
i =t
i i
i i
i i
Let’s have a look into the algorithm enum described previously. It enumerates
in depth-first search order all nonzero integer vectors (ũ t , . . . , ũ m ) for t = m, . . . , 1
satisfying c̃t (ũ t , . . . , ũ m ) < c1 , where c1 is the current minimum for the function
c̃1 (ũ 1 , . . . , ũ m ). In order to find a shortest lattice vector with respect to the l∞ -norm
we modify this and recursively enumerate all nonzero integer vectors (ũ t , . . . , ũ m )
2
satisfying c̃t (ũ t , . . . , ũ m ) < n · B , where B is the current minimal l∞ -norm of all
lattice vectors w1 enumerated so far. The resulting enumeration area is illustrated
√
in Figure 11.7. We enumerate all vectors wt inside the sphere B with radius n ·
B centered at the origin. We can then stop the enumeration using the following
observations:
Since, for fixed ũ t , . . . , ũ m we can only reach lattice vectors in the hyperplane H
orthogonal to wt , we can prune the enumeration as soon as this hyperplane doesn’t
intersect with the set M of all points with l∞ -norm less or equal B. Using Hölder’s
inequality we get c̃t > B||wt ||1 whenever the intersection is empty. The inequality
can be tested in linear time and restricts the enumeration to the shaded area U ; that
√
is, the union of all balls with radius 12 n B centered in {±B /2}n .
The number of vectors wt to be enumerated and therefore the running time
of the enumeration can roughly be approximated by the volume of the area that
needs to be traversed. As a consequence the running time of the pruned enu-
meration algorithm enum∞ in the Crypto Procedure 11.11 is faster by the factor
volume(U )/ volume( B ). For dimension 2 this factor is exactly π2+2 π and in dimen-
sion n it is approximately ( π2+2 π )n−1 . This means that enum
∞ is faster by a factor
exponential in the dimension of the lattice. For more details see [16].
We are now able to formulate the attack algorithm:
i i
i i
i i
d−yt c
if ũ t > −yt then
δt ← −1
δt ← 1
i i
i i
i i
With the following modifications of enum∞ we can further improve the running
time of the attack:
Since ||v||22 = m + 1 and ||v||∞ = 1, we initialize c := m + 1.0001, B := 1.0001
and stop the algorithm as soon as we have found v. We also cut the enumeration for
ũ t as soon as there is an index j ∈ [0, m ] with bi, j = 0 for i = 1, . . . , t − 1 and bt, j 6=
0, |wt, j | 6= 1. We don’t miss the solution since w1, j = wt, j 6= ±1 for all choices of
ũ 1 , . . . , ũ t−1 . As the original basis vectors b1 , . . . , bm +1 only depend on the public
key, we can precompute the LLL-reduced basis b10 , . . . , bm 0
+1 of b1 , . . . , bm +1 once
for every public key we want to attack. For all messages which are encrypted with
the same public key we use the precomputed vectors b10 , . . . , bm 0
+1 together with
bm +2 instead of the original basis. More details on the attack including practical
results may be found in [23] and [16].
11.10.2 Factoring
Many public-key cryptosystems are based on the assumption that factoring large
natural numbers is hard. In 1993, C. P. Schnorr [24] proposed to use lattice basis
reduction to factorize natural numbers:
Crypto Procedure 11.13: Factoring
input N (a natural number with at least two prime factors),
α, c ∈ Q with α, c > 1
Step 1
calculate the list p1 , . . . , pt of the first t primes, pt = (ln N )α
i i
i i
i i
Step 2
Use lattice basis reduction in order to find m ≥ t + 2 pairs (u i , vi ) ∈ N2
with
Qt a ,j
ui = j =1 p ji with ai, j ∈ N
and
|u i − vi N | can be factorized over prime factors p1 , . . . , pt
Step 3
Factorize u i − vi N over primes p1 , . . . , pt and p0 = −1.
b
Let u i − vi N = tj =0 p j i, j , bi = (bi,0 , . . . , bi,t ) and ai = (ai,0 , . . . , ai,t ) with
Q
ai,0 = 0
Step 4
i i
i i
i i
message to a point m in the lattice, by using the public basis P, and then adds a
random error to m; such that the resulting point c is still closer to m than to any
other point in the lattice. Then, c is sent to the receiver who can use the well-formed
basis B in order to find m efficiently and obtain the original message.
The security of the scheme is based on the assumption that an attacker who
is not in the possession of the well-formed basis B needs to spend an infeasi-
ble amount of computational time in order to decipher the message, even with
an aid of quantum computers. However, the security of lattice-based schemes
against quantum-computer attacks is not yet well-understood. For example at Euro-
crypt 2019, several aspects of post-quantum cryptography based on lattices were
discussed:
i i
i i
i i
Figure 11.8 Restricted selection from the overview of all CrypTool functions.
i i
i i
i i
Figure 11.9 CT1 dialog: Factoring N with a hint (you know a fraction of p).
i i
i i
i i
Figure 11.10 CT1 dialog: Attack on stereotyped messages (you know a part of the plaintext message).
i i
i i
i i
Figure 11.11 CT1 dialog: Factoring N when the private exponent/key is too small (Bloemer/May, 2001).
i i
i i
i i
Figure 11.13 CT2 tutorial Lattice-based cryptography: SVP via LLL algorithm.
i i
i i
i i
Figure 11.14 CT2 tutorial Lattice-based cryptography: CVP, Find closest vector.
i i
i i
i i
Figure 11.15 CT2 tutorial Lattice-based cryptography, attack against the Merkle-Hellman knapsack crypto-
system.
i i
i i
i i
Figure 11.16 CT2 tutorial Lattice-based cryptography, attack against RSA (Coppersmith).
i i
i i
i i
i i
i i
i i
i i
i i
i i
References
i i
i i
i i
[11] Hermite, C., “26. Extraits de lettres de M. Ch. Hermite à M. Jacobi sur différentsobjets
de de la théoriedes nombres, deuxièmeletter,” in Journal für die reine und angewandte
Mathematik, Vol. 40, 1850, pp. 279–290.
[12] Korkine, A., and G. Zolotarev, “Sur les formesquadratiques positives quaternaires,” in
Mathematische Annalen, Vol. 5, 1872, pp. 581–583.
[13] Korkine, A., and G. Zolotarev, “Sur les formesquadratiques,” in Mathematische Annalen,
Vol. 6, 1873, pp. 366–389.
[14] Korkine, A., and G. Zolotarev, “Sur les formes quadratiques positives,” in Mathematische
Annalen, Vol. 11, 1877, pp. 242–292.
[15] Schnorr, C.-P., and M. Euchner, “Lattice Basis Reduction: Improved Practical Algorithms
and Solving Subset Sum Problems,” in Mathematical Programming, Vol. 66, No. 1–3,
1994, pp. 181–199.
[16] Ritter, H., “Aufzählung von kurzen Gittervektoren in allgemeiner Norm,” PhD thesis,
Johan Wolfgang Goethe-Universität Frankfurt, 1997.
[17] Chor, B., and R. L. Rivest, “A Knapsack Type Public-Key Cryptosystem Based on Arith-
meticin Finite Fields,” IEEE Transactions on Information Theory, Vol. 34, No. 5, 1988,
pp. 901–909.
[18] Orton, G., A., “A Multiple-Iterated Trapdoor for Dense Compact Knapsacks,” in
EUROCRYPT, Vol. 950, 1994, pp. 112–130.
[19] Schnorr, C.-P., and H. H. Hörner, “Attacking the Chor-Rivest Cryptosystem by Improved
Lattice Reduction,” in EUROCRYPT, Vol. 921, 1995, pp. 1–12.
[20] Brickell, E. F., “Breaking Iterated Knapsacks,” in Proc. CRYPTO 84, 1984, pp. 342–358.
[21] Shamir, A., “On the Cryptocomplexity of Knapsack Systems,” in Proc. 11th ACM Symp.
on Theory ofComputing, 1979, pp. 118–129.
[22] Heuser, H., Lehrbuch der Analysis, Teil 1, 11th ed., Stuttgart: Teubner, 1994.
[23] Ritter, H., “Breaking Knapsack Cryptosystems by l∞ -Norm Enumeration,” in Proceedings
of the 1st International Conference on the Theory and Applications of Cryptology, Prague,
Czech Republic: CTU Publishing House, 1996, pp. 480–492.
[24] Schnorr, C.-P., “Factoring Integers and Computing Discrete Logarithms via Diophantine
Approximations,” in Advances of Computational Complexity, DIMACS Series in Discrete
Mathematicsand Theoretical Science, Vol. 13, 1993, pp. 171–182.
[25] Ritter, H., and C. Rössner, Factoring via Strong Lattice Reduction Algorithms, Tech. rep.,
1997., https://www.researchgate.net/publication/2266562_Factoring_via_Strong_Lat-
tice_Reduction_Algorithms.
[26] Pellet-Mary, A., G. Hanrot, and D. Stehlé, Approx-SVP in Ideal Lattices with Preprocess-
ing, Cryptology ePrint Archive, Report 2019/2015, 2019, https://eprint.iacr.org/2019/215.
[27] Ba�etu, C., et al., Misuse Attacks on Post-Quantum Cryptosystems, Cryptology ePrint
Archive, Report 2019/525, 2019, https://ia.cr/2019/525.
[28] Albrecht, M. R., et al., The General Sieve Kernel and New Records in Lattice Reduction,
Cryptology ePrint Archive, Report 2019/089, 2019, https://ia.cr/2019/089.
[29] Report on the Third Round of the NIST Post-Quantum Cryptography Standardization
Process, National Institute of Standards and Technology (NIST), July 2022 (updated 2022-
09-26), https://nvlpubs.nist.gov/nistpubs/ir/2022/NIST.IR.8413.pdf.
[30] Wikipedia, NIST Post-Quantum Cryptography Standardization, https://en.wikipedia.org/
wiki/NIST_Post-Quantum_Cryptography_Standardization.
[31] NIST Computer Security Resource Center CSRC, Post-Quantum Cryptography PQC,
https://csrc.nist.gov/projects/post-quantum-cryptography/post-quantum-cryptography-
standardization.
[32] Stamp, M., Lattice Reduction Attack on the Knapsack, http://www.cs.sjsu.edu/faculty/s-
tamp/papers/topics/topic16/Knapsack.pdf.
i i
i i
i i
i i
i i
i i
C H A P T E R 12
C H A P T E R 12
Solving Discrete Logarithms and
Factoring
The hardiness of the discrete logarithm problem depends on the group over which
it is defined. In this chapter we review cryptanalytical algorithms that work for any
group. From a cryptographic point of view it is desirable to identify groups for
which one is unable to find better algorithms. One candidate for these groups are
elliptic curve groups.
In this chapter, we describe general cryptanalytical algorithms that apply for
any finite abelian group. That means, any group used in cryptography (e.g., multi-
plicative groups of finite fields or of elliptic curves) are susceptible to this kind of
algorithm. We will see that we can always compute a discrete logarithm in a group
√
of order n in O( n ) steps by Pollard’s rho method. This in turn means that for
achieving a security level of 2k one has to choose a group of order at least 22k . For
example, for achieving a security level of 80 bit, one has to choose a group of order
555
i i
i i
i i
at least 160 bit. This explains why in practice we usually take elliptic curve groups
with at least 160 bit order.
Moreover, let G be a group of order n and let n = p1e1 · . . . · p`e` be the prime
factorization of n. Then we will see that discrete logarithms in G can be computed
√ √
in time O(e1 p1 + . . . + e` p` ). Notice that this bound is equal to Pollard’s bound
√
O ( n ) if and only if n is a prime. Otherwise, the complexity of computing the
discrete logarithm is mainly determined by the size of the largest prime divisor of
its group order. This explains why, for example, Schnorr/DSA signatures are imple-
mented in groups which contain by construction a prime factor of size at least 160
bit. This also explains why usually elliptic curve groups have prime order or order
containing only a very small smooth cofactor.
This can be rewritten as g b j −bi = y. This in turn implies that we can recover our
a −a
discrete logarithm as x ≡ bij −bji mod n.
Hence, with Pollard’s rho method one can compute discrete logarithms in any
√
finite abelian group of order n in O( n ) steps. By using so-called cycle-finding
techniques, one can also show that Pollard’s rho method can be implemented within
constant space.
Moreover, it is also possible to improve the efficiency of square root algorithms
when multiple discrete logarithms in the same group are desired: When computing
√
√
L distinct logarithms, one can reduce the global cost from O( L n ) to O( Ln ) [2].
i i
i i
i i
12.1 Generic Algorithms for the Discrete Logarithm Problem in Any Group 557
method. Then it is quite easy to find a logarithm modulo the prime power
xi mod piei by a Hensel lifting process that performs ei calls to the discrete log-
arithm procedure modulo pi . In a Hensel lifting process, we start by a solution
xi mod pi , and then consecutively compute xi mod pi2 , xi mod pi3 , and so on until
xi mod piei (see [3] for Hensel’s formula).
Finally, one computes the desired discrete logarithm x mod n from the system
of (12.1) by Chinese remaindering. In total, the running time is mainly determined
by computing xi mod pi for the largest prime factor pi . That is, the running time
√
is roughly O(maxi { pi }).
i i
i i
i i
The same running time holds for computing the factorization of an integer n. This
running time is not only polynomial, but the attacks are even more efficient than
the cryptographic schemes themselves! This in turn means that the problem cannot
be fixed by just adjusting key sizes.
Thus, if we face the development of large-scale quantum computers in the
next decades, then all classical dlog- and factoring-based cryptography has to
be replaced. However, one should stress that the construction of large quantum
computers with many qubits appears to be way more difficult than its classical coun-
terpart, since most small quantum systems do not scale well and face decoherence
problems.
Recommendation: It seems hard to predict the developments in constructing
quantum computers. But experts in quantum physics currently do not see any major
obstacle that would hinder the development of large quantum computers in the long
term. It seems crucial to keep track of current progress in this area, and to have
some alternative quantum-resistant cryptosystems ready to enroll within the next
15 years.
References and further reading: We recommend reading the books of Menezes,
van Oorschot, and Vanstone [4], Joux [5], and Galbraith [6] for a survey of
cryptanalytic techniques. An introductory course in cryptanalysis is provided by
May’s lecture notes on cryptanalysis [7, 8] (German). An introduction to quantum
algorithms can be found in the books of Homeister [9] (German) and Mermin [10].
The algorithms of this section were originally presented in the superb works of
Pollard [11, 12] and Shor [13]. Generic algorithms for multiple dlogs have recently
been studied in [2].
Prime fields F p are (besides elliptic curves) the standard group for the discrete loga-
rithm problem. There has been no significant algorithmic progress for these groups
in the last 20 years. They are still a good choice for cryptography.
In Section 12.1, we learned that in any finite abelian group of order n, we
√
can determine discrete logarithms in O( n ) steps. Notice that both the Pollard
rho method and the Silver-Pohlig-Hellman algorithm from Section 12.1 used no
other property of representations of group elements than their uniqueness. In these
methods, one simply computes group elements by group operations and checks for
equality of elements. Algorithms of this type are called generic in the literature.
It is known that generic algorithms cannot compute discrete logarithms in
time better than the Silver-Pohlig-Hellman algorithm [14]. Thus, the algorithms of
Section 12.1 can be considered optimal if no further information about the group
elements is used.
However, when we specify our group G as the multiplicative group of the
finite field F p , where p is a prime, we can actually exploit the representation of
group elements. Natural representatives of F p are the integer 0, . . . , p − 1. Thus,
we can, for example, use the prime factorization of these integers. This is done in
the so-called Index Calculus type discrete logarithm algorithms. This type of algo-
rithm currently forms the class with the best running times for discrete logarithm
i i
i i
i i
over prime fields, prime extensions (Section 12.3) and for the factorization problem
(Section 12.4).
We will now illustrate an index calculus algorithm with a very easy example.
Relation finding: Find elements z i := g xi ∈ G for some integer xi that can be written
in the factor base; that is
k
Y e
g xi = f j ij .
j =1
k
X
xi ≡ ei j dlogg ( f j ) mod n,
j =1
dlogg ( f 1 ), . . . , dlogg ( f k ).
Once we have k linear independent relations of this type, we can compute these
unknowns by linear algebra. This means we actually first compute all discrete
logarithms of the factor base elements before we compute our desired individual
logarithm of y.
Qk e
Dlog computation: Express ygr = g x +r = j =1 f j j in the factor base for some
integer r . This gives us another relation
k
X
x +r ≡ e j dlogg ( f j ) mod n,
j =1
i i
i i
i i
Runtime: Choosing a large factor base makes it easier to find relations, since it
increases the likelihood that a certain number splits in the factor base. On the other
hand, for a large factor base we have to find more relations in order to compute
the dlogs of all factor base elements. An optimization of this tradeoff leads to a
running time of L p [ 12 ] for the relation finding step and also L p [ 12 ] for performing
the individual discrete logarithm computation in step 3.
Let us briefly discuss the advantages and disadvantages of the simple index
calculus algorithm from a cryptanalyst’s point of view.
Advantages:
e
For g xi = kj =1 f j i j it is trivial to compute the discrete logarithm on the
Q
•
left-hand size.
Disadvantages:
• We need to factor relatively large numbers g xi over the integers. One can
show that this intrinsically leads to a running time of L p [ 12 ], and there is no
hope to get below the constant 12 .
• We need to compute all discrete logarithms of the factor base elements. This
is inherent to all index calculus algorithms.
We will eliminate the first disadvantage by allowing factorizations over number
fields. The second disadvantage is eliminated by choosing a factor base with very
efficient discrete logarithm computations of its elements.
i i
i i
i i
Remark: When calculating the dlog there is only the term number field sieve and
no distinction between general versus special. This is in the opposite to the number
field sieve for factorization in Section 12.4.1.
The number field sieve is also an index calculus algorithm. Compared to the
previous approach it has the advantage to involve smaller numbers. This is done by
choosing a specific representation of the prime field F p , which is implicitly defined
as a finite field where two polynomials of small degree with small coefficients pos-
sess a common root. There are several methods that allow one to construct such
polynomials with a common root modulo p. In particular, for primes of a spe-
cial form (i.e., with a sparse representation), it is possible to construct polynomials
which are much better than in the general case. One typicalPconstruction that works
well is to choose a number m andP write p in basis m as it =0 ai m i . We then find
that f 1 ( X ) = X − m and f 2 ( X ) = it =0 ai m i have m as a common root modulo p.
Equipped with two polynomials f 1 and f 2 of this form, with m as their common
root modulo p, we obtain the commutative diagram in Figure 12.1:
Let r1 , r2 be roots of f 1 , f 2 , respectively. Then we are working with the number
fields Q[r1 ] ' Q[ X ]/( f 1 ( X )) and Q[r2 ] ' Q[ X ]/( f 2 ( X )).
Relation finding: The basic principle of the number field sieve consists of sending
elements of the form a + bX to both sides of the diagram and to write a relation
when both sides factor into the factor base. Technically, this is quite challenging,
because we need to introduce several tools to account for the fact that the left and
right sides are not necessarily unique factorization domains. As a consequence, we
need to factor elements into ideals and take care of the obstructions that arise from
the class groups and unit groups. This procedure gives us the discrete logarithms of
the factor base elements.
Runtime: The number field sieve is the most efficient currently known algorithm
for the large characteristic discrete logarithm problem. In the general case, which
means that p is not of a special form (e.g., close to a prime power), its complexity
1/3
is L p [ 13 , 64
9 ].
Figure 12.1 NFS in F p with two polynomials and common roots, shown as a commutative diagram.
i i
i i
i i
(in German) and the number theory book by Müller-Stach, Piontkowski [15]. For
gaining a deep understanding of the number field sieve, one has to study the book of
Lenstra and Lenstra [16] that contains all original works that led to the development
of the number field sieve algorithm in the late 1980s and early 1990s.
i i
i i
i i
12.3 Best Known Algorithms for Extension Fields F pn and Recent Advances 563
Relation finding: Göloglu, Granger, McGuire, and Zumbrägel show that one can
construct a special type of polynomials over Fq [x ] (the so-called Bluher polynomi-
als) that by construction split over Fq [x ]. So similar to our simple version of index
calculus for integers in Section 12.2.1, we obtain one side of the equation for free.
The cost for splitting the polynomials in Fq [ y ] is roughly O(q ) and the cost for find-
ing the discrete logarithms of the factor base elements is roughly O(n · q 2 ). We will
explain why this gives us the discrete logarithms of the factor base in polynomial
time for properly chosen parameters.
i i
i i
i i
The trick to work around this is to decrease the size of the base q to q 0 while
slightly increasing the extension degree n to n 0 . Our goal is that the new base field
size q 0 roughly equals the new extension degree n 0 ; that is q 0 ≈ n 0 . In this case, we
again obtain a running time which is polynomial in n 0 and q 0 , but now q 0 is also
polynomially bounded by n 0 . So, in total, for step 2 our running time is polynomially
bounded by n 0 .
Let us give a simple example of how this can be done for concrete parameters.
Assume that we wish to compute a discrete logarithm in F(2100 )100 . Then we would
lower the base field to q 0 = 210 and at the same time increase the extension degree
to n 0 = 1000; that is, compute in F(210 )1000 . Notice that this can always be done
by using the efficiently computable isomorphisms between finite fields of the same
cardinality.
Warning: One might be tempted to bypass the above with the selection of
exponents that do not split appropriately; that is, by choosing F2 p with prime
p. However, we can always embed our finite field in some larger field—as well
as the respective discrete logarithms. Hence, finite fields with small characteristic
have to be considered insecure, independently of the special form of the extension
degree n.
While the relation finding in step 2 of Göloglu, Granger, McGuire, and Zum-
brägel can be done in polynomial time, the individual log computation is still
time-consuming. If one does it naively, step 3 is even more time-consuming than
in Joux-Lercier because of the increased extension degree n 0 . If one balances out
the running times of step 2 and 3, one ends up with an improved overall running
1
time of L q n [ 13 , ( 49 ) 3 ].
i i
i i
i i
12.3 Best Known Algorithms for Extension Fields F pn and Recent Advances 565
that obviously factors in the factor base. Now, one applies linear and rational trans-
formations (called homographies) to h (x ), which preserve its property to split over
the factor base. One can show that there are sufficiently many independent homo-
graphies in order to construct sufficiently many relations. So out of one trivial
polynomial h (x ), we obtain for free all O(q ) relations. This enables us to compute
the discrete logarithms of the factor base elements in time O(q ).
Discrete log computation: Barbulescu et al. present an efficient degree decent algo-
rithm that on input of a polynomial p (x ) of degree n outputs a linear relation
between the discrete log of p (x ) and O(nq 2 ) polynomials of degree n2 in time poly-
nomial in q and D. This implies that we get a tree of polynomials, where the degree
drops in every level by a factor of two, which in turns implies a tree depth of log n.
This results in a running time of O(q O(log n ) ).
Runtime: As in Section 12.3.2 let us assume that the size q of the base field is of
the same size as the extension degree n; that is, q = O(n ). Then step 2 runs in
time O(q ) = O(n ), which is polynomial in n. Step 3 runs in time O(q O(log n ) ) =
2
O(n O(log n ) ) = L q n [o(1)]. Notice that n log n = 2log n grows faster than any poly-
c
nomial function in n but slower than any subexponential function 2n for some
c > 0.
i i
i i
i i
i i
i i
i i
References and further reading: Coppersmith’s algorithm [26] from the mid-1980s
was for a long time the reference method for computing discrete logarithms in small
characteristic fields. The Joux-Lercier function field sieve was introduced 2006
in [23].
The recent advances started at Eurocrypt 2013 with Joux’s pinpointing tech-
nique [24]. At Crypto 2013, Göloglu, Granger, McGuire, and Jens Zumbrägel [25]
already improved the constant c in the L [ 13 , c] running time. The improvement to
running time L [ 14 ] was then presented in the work of Joux [21]. Eventually, Bar-
bulescu, Gaudry, Joux, and Thomé [22] proposed an algorithm for the descent that
led to running time L [o(1)].
The best algorithm for factoring shows close similarity to the best algorithm for
computing discrete logarithms in prime order groups. It seems that the new attacks
do not help to improve any of the two algorithms.
The best algorithm for computing the prime factorization of integers, the so-
called number field sieve, is very similar to the best algorithm for computing discrete
logarithm in F p from Section 12.2.2, and much less similar to the algorithm for Fq n
from Section 12.3.
In a nutshell, all known, sophisticated algorithms that factor RSA moduli n =
pq for primes p, q of the same size rely on the same basic simple idea. Our goal is
to construct x, y ∈ Z/nZ such that
x 2 ≡ y 2 mod n and x 6≡ ±y mod n.
This immediately yields the factorization of n, since n divides the product x 2 − y 2 =
(x + y )(x − y ) by the first property, but n does neither divide x + y nor x − y by
the second property. Thus, one prime factor of n has to divide x + y, whereas the
other one has to divide x − y. This in turn means that gcd(x ± y, n ) = { p, q}.
The factorization algorithms only differ in the way in which these x, y are com-
puted. The intention is to compute x, y with x 2 ≡ y 2 mod n in an independent way.
If this independence is given, it is easy to show that x 6≡ ±y mod n holds with prob-
ability 12 , since every square in Z/nZ has 4 square roots by the chinese remainder
theorem—two different roots modulo p and two different roots modulo q.
i i
i i
i i
Linear Algebra: By linear algebra, we search for a product of the elements π f which
is a square and whose corresponding product of the πg is also a square. If we
send these elements via our homomorphism X 7→ m to Z/nZ, we obtain elements
x 2 , y 2 ∈ Z/nZ such that x 2 ≡ y 2 mod n. If we first compute the square roots of π f
and πg in their respective number fields before applying the homomorphism, we
obtain x, y ∈ Z/nZ with x 2 ≡ y 2 mod N , as desired. The independence of x, y here
stems from the different representations in both number fields.
Runtime: The above algorithm is up to some details (e.g., the square root compu-
tation in the number field) identical to the algorithm of Section 12.2.2 and shares
1/3
the same running time L [ 13 , 64
9 ].
Let us briefly give the idea of this relation. We compute the order k = ord(a ) for an
arbitrary a ∈ Z/nZ by our dlog algorithm; that is, we compute the smallest positive
k
integer k such that a k ≡ 1 mod n. If k is even, then a 2 6≡ 1 is a square root of 1. We
k
have a 2 6≡ −1 with probability at least 12 , since 1 has 4 square roots modulo n. Set
i i
i i
i i
k
x ≡ a 2 mod n and y = 1. Then we obtain x 2 ≡ 1 ≡ y 2 mod n and x 6≡ ±y mod n.
By the discussion at the beginning of the chapter, this allows us to factor n.
Secondly, we also know that both problems factoring and computing discrete
logarithms in F p are together at least as hard as computing discrete logarithms in
Z/nZ. In short
This fact can be easily seen by noticing that factoring and dlogs in F p together
immediately give an efficient version of the Silver-Pohlig-Hellman algorithm from
Section 12.1. We first factor the group order n in prime powers piei , and then com-
pute the discrete logarithms in F pi for each i. Just as in the Silver-Pohlig-Hellman
algorithm we lift the solution modulo piei and combine these lifted solutions via
Chinese remaindering.
We would like to stress that these two known relations do not tell much about
whether there is a reduction
12.4.4 Relation of Key Size versus Security for Dlog in F p and Factoring
The running time of the best algorithm for a problem defines the security level of
a cryptosystem. For example, for 80-bit security, we want that the best algorithm
requires at least 280 steps.
As we already noted, the best running time for discrete logs in F p and for
1/3
factoring is L [ 13 , 64
9 ]. The most accurate way to use this formula is to actually
measure the running time for a large real world factorization/dlog computation,
and then extrapolate to large values. Assume that we know that it took time T to
i i
i i
i i
factor a number n 1 , then we extrapolate the running time for some n 2 > n 1 by the
formula
1/3
L n 1 [ 13 , 64 ]
T· 9
1/3
.
L n 2 [ 13 , 64
9 ]
So, we use the L-formula to estimate the relative factor that we have to spend
in addition. Notice that this (slightly) overestimates the security, since the L-
formula is asymptotic and thus becomes more accurate in the numerator than in the
denominator—the denominator should include a larger error term. So, in practice,
one obtains (only slightly) less security than predicted by this formula.
We computed the formula for several choices of the bit-size of an RSA number
n, respectively a dlog prime p, in Table 12.2. Recall from Section 12.4.1 that the
running time of the number field sieve algorithm for factoring is indeed a function
of n and not of the prime factors of n.
We start with RSA-768 that has been successfully factored in 2009 [27]. In
order to count the number of instructions for factoring RSA-768, one has to define
what an instruction unit is. It is good practice in cryptography to define as a unit
measure the time to evaluate DES in order to obtain comparability of security levels
between secret and public key primitives. Then by definition of this unit measure,
DES offers 56-bit security against brute-force key attacks.
In terms of this unit measure, the factorization of RSA-768 required T = 267
instructions. From this starting point, we extrapolated the security level for larger
bit-sizes in Table 12.2.
We successively increase the bit-size by 128 up to 2048 bit. We see that in the
beginning, this leads to roughly an increase of security of 5 bit per 128-bit step,
whereas in the end we only have an increase of roughly 3 bit per 128-bit step.
By Moore’s law the speed of computers doubles every 1.5 years. Hence after
5 · 1.5 = 7.5 years we have an increase of 25 , which means that currently we
should roughly increase our bit-size by 128 bit every 7.5 years; and when we come
closer to 2000 bit our increase of 128-bit steps should be in intervals of no later
than 4.5 years. For more conservative choices that also anticipate some algorithmic
progress rather than just an increase in computers’ speed see the recommendations
in Section 12.7.
i i
i i
i i
Elliptic curves are the second standard group for the discrete logarithm problem.
The new attacks do not affect these groups; their security remains unchanged.
We would like to discuss elliptic curves E [ p n ] over finite extension fields F pn
and elliptic curves E [ p ] over prime fields F p . The latter are usually used for cryp-
tographic purposes. The reason to discuss the former too is to illustrate (similar to
the previous sections) the vulnerabilities of extension fields F pn as opposed to prime
field F p . However, we would like to point out that we assume in the following (in
contrast to the previous section) that n is fixed. This is because as opposed to the
algorithm of Joux et al., the algorithms for E [ p n ] have complexities that depend
exponentially on n.
We present two different approaches for elliptic curves over extension fields:
cover (or Weil descent) attacks introduced by Gaudry, Hess, and Smart (GHS), and
decomposition attacks proposed by Semaev and Gaudry. In some cases, it is possible
to combine the two approaches into an even more efficient algorithm as shown by
Joux and Vitse [30].
i i
i i
i i
Factor base: Consists of all points (x, y ) on the elliptic curve E [ p n ] such that x ∈ F p .
That is x lies in the ground field F p rather than in the extension.
Runtime: The factor base can be computed in time O( p ). Every R can be written
as a sum of n factor base elements; that is, yields a relation, with probability expo-
nentially small in n (but independent of p). If it yields a solution, the running time
of a Groebner basis computation is also exponential in n (but polynomial in log p).
In total, we need roughly p relations which can be computed in time linearly in p
and exponentially in n. Since we assumed n to be fixed, we do not care about the
bad behavior in n. The linear algebra step on a ( p × p )-matrix can then be per-
formed in O( p 2 ), since the matrix is sparse—every row contains exactly n nonzero
2
entries. With additional tricks one achieves a running time of O( p 2− n ) for Gaudry’s
algorithm.
n
This should be compared to the generic bound of O( p 2 ) that we achieve when
using Pollard’s rho algorithm from Section 12.1. Similar to Section 12.3, almost the
whole complexity of the problem seems to be concentrated in the size of the base
field p, and not in the extension degree n. Notice that as in Section 12.3, Gaudry’s
algorithm is exponential in log p.
12.5.3 Best Known Algorithms for Elliptic Curves E[ p] Over Prime Fields
Generic discrete log solving: In general, the best algorithm that we know for arbi-
√
trary elliptic curves E [ p ] is Pollard’s rho method with a running time of O( p ).
For the moment, it seems that nobody knows how to exploit the structure of an
elliptic curve group or its elements in order to improve over the generic bound.
We would also like to point out that random elliptic curves; that is, where the
elliptic curve parameters a, b in the defining Weierstrass equation y 2 ≡ x 3 + ax +
i i
i i
i i
b mod p are chosen in a uniformly random manner, are among the hard instances.
To further harden elliptic curves, one chooses for standardization only those curves
that have (almost) prime order. This means that the cofactor of the largest prime
in the group order is usually 1, which abandons the use of Silver-Pohlig-Hellman’s
algorithm.
The xedni calculus algorithm: In 2000, Silverman published his xedni calculus algo-
rithm (read xedni backwards) that uses the group structure of E [ p ] for discrete
logarithm computations, and thus is the only known non-generic algorithm that
works directly on E [ p ]. However, it was soon after his publication discovered that
the so-called lifting process in Silverman’s algorithm has a negligible probability of
succeeding in computing a discrete logarithm.
1 √ log p
L p [1, ] = p = 2 2 .
2
This means that for achieving a security level of k bit, we have to choose a prime
p with 2k bit. In other words, increasing the bit-size of our group by 2 bit leads
to increase of 1 bit in security. By Moore’s law we loose 1 bit of security every 1.5
years just from an increase of a computer’s speed. In order to guard against this
loss over 10 years, it thus suffices to increase the group-size by just 7 · 2 = 14 bit.
Notice that as opposed to the case of dlog in F p and factoring in Section 12.4.4
this increase is linear and independent of the starting point. That means to guard
against technological speedups over 20 years, an increase of 28 bit is sufficient.
Of course, this analysis only holds if we do not have to face any major break-
through in computer technology or algorithms. For a more conservative choice see
the advice in Section 12.7.
i i
i i
i i
• A small embedding degree for the embedding into a finite field: This would
allow for the use of more efficient finite field algorithms. Especially, the
requirement excludes supersingular curves of order p + 1.
• Trace one curves that have order |E [ p ]| = p: These curves are known to be
weak by the discrete logarithm algorithms of Satoh-Araki [34], Semaev [35],
and Smart [36].
• Large class number: This excludes that E [ p ] can be efficiently lifted to a
curve defined over some algebraic number field. This requirement is quite
conservative, since even for small class numbers there is currently no efficient
attack known.
In addition, Lochter and Merkle specify a variety of curves for p’s of bit-lengths in
the range 160 to 512. For TLS/SSL there is also a new set of proposed Brainpool
curves available [37].
The work of Bos, Costello, Longa, and Naehrig [38] gives a valuable introduc-
tion for practitioners on how to choose elliptic curve parameters that are secure and
also allow for efficient implementation in various coordinate settings (Weierstrass,
Edwards, Montgomery). Additionally, Bos et al. focus on side-channel resistance
against timing attacks by proposing constant-time scalar multiplications.
We highly recommend the SafeCurve project by Daniel Bernstein and Tanja
Lange [39] that provides an excellent overview for several selection methods, their
benefits and drawbacks. The goal of Bernstein and Lange is to provide security
of elliptic curve cryptography, rather than just strength of elliptic curves against
discrete logarithm attacks. Therefore, they take into account various types of side-
channels that may leak secrets in an implementation.
References and further reading: For an introduction to the mathematics of
elliptic curves and their cryptographic applications we refer to the textbooks of
Washington [40], Galbraith [6], and Silverman [41].
This section described the results of the original works of Gaudry, Hess,
Smart [42], Gaudry [43], Semaev [44], and the xedni algorithm of Silverman [41].
i i
i i
i i
i i
i i
i i
i i
i i
i i
Warning: One should keep in mind that the suggestions above only hold in a world
without large quantum computers. It seems crucial to keep track of current progress
in this area, and to have some alternative quantum-resistant cryptosystems ready
to enroll within the next 15 years.
References and further reading: For a good and conservative choice of key sizes we
highly recommend following the suggestions of the Bundesamt für Sicherheit in der
Informationstechnik (BSI) [49] and the Agence nationale de la sécurité des systèmes
d’information [50]. Both sources also provide various valuable recommendations
how to correctly implement and combine different cryptographic primitives.
In April 2022, Fabrice Boudot et al. published the very good article “The State
of the Art in Integer Factoring and Breaking Public-Key Cryptography” in IEEE
Security & Privacy. There they review the three number-theoretic problems of inte-
ger factorization, discrete logarithms in finite fields, and discrete logarithms over
elliptic curves, and come to very similar results [53].
References
[1] Ptacek, T., et al., “The Factoring Dead—Preparing for the Cryptopocalypse,” in Black Hat
Conference (2013).
[2] Fouque, P.-A., A. Joux, and C. Mavromati, “Multi-User Collisions: Applicationsto Discrete
Logarithm, Even-Mansour and Prince,” in Cryptology ePrint Archive, 2014, https://eprint
.iacr.org/2013/761.
i i
i i
i i
i i
i i
i i
[29] Bach, E., Discrete Logarithms and Factoring, UCB/CSD-84-186, June 1984, https://www2
.eecs.berkeley.edu/Pubs/TechRpts/1984/5973.html; https://www2.eecs.berkeley.edu/Pubs/
TechRpts/1984/CSD-84-186.pdf.
[30] Joux, A., and V. Vitse, “Cover and Decomposition Index Calculus on Elliptic Curves Made
Practical. Application to a Seemingly Secure Curve Over Fp6,” in IACR Cryptology ePrint
Archive, 2011, p. 20.
[31] Enge, A., P. Gaudry, and E. Thomé, “An L(1/3) Discrete Logarithm Algorithm for Low
Degree Curves,” in J. Cryptology, Vol. 24, No. 1, 2011, pp. 24–41.
[32] Lochter, M., and J. Merkle, Elliptic Curve Cryptography (ECC) Brainpool Stan-
dard Curves and Curve Generation, RFC 5639, 2010, https://datatracker.ietf.org/
doc/html/rfc5639.
[33] Lochter, M., and J. Merkle, ECCBrainpool Standard Curves and Curve Generation
v. 1.0, 2005, https://www.teletrust.de/fileadmin/files/oid/oid_ECC-Brainpool-Standard-
curves-V1.pdf.
[34] Satoh, T., and K. Araki,“Fermat Quotients and the Polynomial Time Discrete Log Algo-
rithm for Anomalous Elliptic Curves,” in Commentarii Mathematici Universitatis Sancti
Pauli 47, 1998.
[35] Semaev, I., “Evaluation of Discrete Logarithms on Some Elliptic Curves,” in Mathematics
of Computation 67, 1998.
[36] Smart, N., “The Discrete Logarithm Problem on Elliptic Curves of Trace One,” in Journal
of Cryptology 12, 1999.
[37] Lochter, M., and J. Merkle, Elliptic Curve Cryptography (ECC) Brainpool Curves for
Transport Layer Security (TLS), RFC 7027, 2013, https://datatracker.ietf.org/doc/html/
rfc7027.
[38] Bos, J. W., et al., Selecting Elliptic Curves for Cryptography: An Efficiency and Security
Analysis, 2014, https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/
selecting.pdf.
[39] Bernstein, D., and T. Lange, SafeCurves: Choosing Safe Curves for Elliptic-Curve Cryp-
tography, 2014, https://safecurves.cr.yp.to.
[40] Washington, L. C., Elliptic Curves: Number Theory and Cryptography, Discrete Mathe-
matics and its Applications, Chapman and Hall/CRC, 2008.
[41] Silverman, J. H., “The Xedni Calculus and The Elliptic Curve Discrete Logarithm
Problem,” in Designs, Codes and Cryptography, Vol. 20, 1999, pp. 5–40.
[42] Gaudry, P., F. Hess, and N. P. Smart, “Constructive and Destructive Facets of Weil
Descenton Elliptic Curves,” in J. Cryptology, Vol. 15, No. 1, 2002, pp. 19–46.
[43] Gaudry, P., “Index Calculus for Abelian Varieties of Small Dimension and the Ellip-
tic Curve Discrete Logarithm Problem,” in J. Symb. Comput., Vol. 44, No. 12, 2009,
pp. 1690–1702.
[44] Semaev, I., “Summation Polynomials and the Discrete Logarithm Problem on Elliptic
Curves,” in IACR Cryptology ePrint Archive, 2004, p. 31.
[45] Lenstra, A. K., et al., “Public Keys,” in CRYPTO, 2012, pp. 626–642, http://dx.doi.org/
10.1007/978-3-642-32009-5_37.
[46] Heninger, N., et al., “Mining Your Ps and Qs: Detection of Widespread Weak Keys in
NetworkDevices,” in Proceedings of the 21st USENIX Security Symposium, August 2012,
https://factorable.net/paper.html.
[47] Young, A. L., and M. Yung, “The Dark Side of Black-Box Cryptography, or: Should We
TrustCapstone?” in CRYPTO, 1996, pp. 89–103.
[48] Young, A. L., and M. Yung. “Kleptography: Using Cryptography Against Cryptography,”
in EUROCRYPT. 1997, pp. 62–74.
[49] BSI,Technical Guideline TR-02102-1, Cryptographic Mechanisms: Recommendations and
Key Lengths (Version 2022-01), Tech. rep., 2022, https://www.bsi.bund.de/SharedDocs/
Downloads/EN/BSI/Publications/TechGuidelines/TG02102/BSI-TR-02102-1.pdf.
i i
i i
i i
i i
i i
i i
C H A P T E R 13
C H A P T E R 13
Future Use of Cryptography
In 1978, Rivest, Shamir, and Adleman proposed the RSA public-key encryption
and signature schemes [1]. RSA is still the most widely used public-key scheme.
The security of RSA depends on the difficulty of factoring so-called RSA moduli
which are products of two large prime numbers. In their 1978 paper, the inventors
of RSA suggested using RSA moduli with 200 decimal places for long-term security.
Later, the company RSA Security published a list of RSA moduli of increasing size,
the RSA Challenge. RSA Security offered a total of $635,000 in prizes for factoring
these numbers; see Section 5.12.4.
In 2005, 27 years after the invention of RSA, Bahr, Boehm, Franke, and Klein-
jung of the University of Bonn succeeded in factoring a 200-decimal-digit RSA
challenge number (see Section 5.12.4). A key of this size, originally thought to
be secure for a very long time, was broken with a calculation that took them
only five months. This illustrates the tremendous progress factoring technology
has made in the 30 years since the invention of the RSA algorithm. This progress
is based on breakthrough mathematical ideas—such as the number field sieve pro-
posed by John Pollard as well as significant developments in computer hardware
and software implementation technology. Recent cryptanalytic results against RSA
and Dlog were discussed in Chapter 12 and Section 5.12.
In 2000, Lenstra and Verheul [2] developed an extrapolation formula to help
us predict the security that can be achieved with RSA and other important cryp-
tographic schemes in the long run. The formula suggests using 850-decimal-digit
RSA moduli if you want to protect data until 2038 (this corresponds to a 3072-bit
RSA key). RSA-2048 has an effective security of about 88 bit, making it secure
until about 2023 if you follow the Lenstra/Verheul equations from 2000; if you
follow the Lenstra equations from 2004, it has an effective security of about 95
581
i i
i i
i i
bit, making it secure until about the year 2040. So the experts have adjusted their
opinions over time.
These results and the recommendations of seven other authorities are dynami-
cally processed on the Bluekrypt website [3]. See Figures 13.1 and 13.2.
However, even a well thought-out extrapolation formula is no guarantee of
security. At any time, a brilliant mathematical idea can allow us to easily factor
large numbers, and destroy the security of RSA. In 1996, Peter Shor showed that
a quantum computer—a new type of computer that leverages the laws of quantum
mechanics to speed up certain types of computation—could in principle be used to
quickly factor large numbers [4]. If Shor’s algorithm could be practically applied,
Figure 13.1 A graph to determine secure key length until a given year (from BlueKrypt).
i i
i i
i i
Figure 13.2 Secure key sizes: result in BlueKrypt for the year 2022.
one would have to double the bit length of an RSA key to achieve the same level of
security. Despite intensive research in this area, it is still too early to say whether we
will ever be able to build quantum computers of sufficient capacity to apply Shor’s
algorithm to numbers of relevant size. See Section 5.12.3.
Early announcements by D-Wave about the performance of their quantum com-
puter were met with a lot of skepticism, even ridicule. As large companies have
invested heavily in QC, the skepticism has turned into hype.
The development of attacks on another widely used scheme called Digital Sig-
nature Algorithm and the elliptic curve cryptography class of schemes is analogous
to those on RSA. The security of these schemes depends on the difficulty of comput-
ing discrete logarithms. Even today, significant algorithmic progress is being made.
Quantum computers would render these schemes insecure.
And what’s the status of symmetric (so called secret-key) encryption schemes?
In 1977, DES was introduced as Data Encryption Standard [5]. Twenty-one years
later, the Electronic Frontier Foundation built Deep Crack, a specialized machine
that took only 56 hours to break a DES key. The problem with DES was that it
used keys that were too short. It seems that the inventors of DES did not anticipate
the speed of hardware development. The Advanced Encryption Standard [6], the
successor to DES, is currently considered secure, although there are interesting,
though still inefficient, methods to attack AES using algebraic methods.
AES is the gold standard for all symmetric ciphers—and because of more pow-
erful and cheaper chips, it is now even used in low-power, resource-constrained
devices such as sensors.
Is the security of today’s cryptography adequate for its growing importance? Expe-
rience shows: carefully designed and implemented cryptographic schemes have a
lifetime of five to twenty years. Those who use RSA, ECC, or AES for short-term
data protection can feel secure. It is also possible to achieve long-term authentic-
ity, integrity, and nonreputability of data, for example, by using multiple signature
schemes.
However, current schemes cannot guarantee long-term confidentiality. And
what about twenty years from now? What should we do if, virtually overnight,
i i
i i
i i
Let us take a closer look at these alternatives. The first encryption scheme based
on the decoding problem was proposed by McEliece [9].1 Background: Error-
correcting codes are used to transmit or store electronic data in such a way that
it remains undistorted even if a few bits are changed during transmission or on the
storage media. This property is used, for example, in compact discs (CDs). The
data on a CD can be reconstructed even if the disc is slightly scratched.
In a code-based encryption scheme, a message is encrypted by adding a fixed
number of errors to the encrypted message (i.e., flipping a fixed number of bits).
Decryption requires knowledge of an approriate decryption procedure that effi-
ciently eliminates these errors. This procedure is called the secret key. Code-based
encryption is generally very efficient. Research is currently underway to deter-
mine which codes lead to secure encryption methods with the smallest possible
keys.
Encryption based on lattice problems is similar to encryption based on error-
correcting codes. Lattices are regular structures of points in space. For instance,
the points where the lines cross on a square piece of paper form a 2-dimensional
lattice. For cryptographic use, the dimension of the lattice is chosen to be much
larger. Encryption works as follows: The plaintext is used to construct a lattice
point which is then slightly distorted so that it is no longer a lattice point, but close
to one. Whoever knows a secret about the lattice is able to find this lattice point in
the vicinity of the given point in space. The lattice point in turn yields the plaintext.
Chapter 11 gave a lightweight introduction to lattices.
1. McEliece can be found in JCT Algorithm Perspective and in JCT Default Perspective F Visuals
F McEliece Cryptosystem.
i i
i i
i i
From the point of view of the current state of cryptography, the problem of
long-term confidentiality remains unsolved: There is no practical way to keep an
encrypted message secret for a very long time.
Quantum cryptography can provide a way out here: These quantum technolo-
gies establish a secure channel to enable the exchange of keys (e.g., very long keys for
one-time pads). Their security is guaranteed by the laws of quantum mechanics; see
[13]. However, the known methods of quantum cryptography are currently rather
inefficient and allow only symmetric methods. Governments, for example, can use
them to exchange top-secret information. For many applications such as signatures,
symmetric cryptography alone is not sufficient. Note that quantum cryptography
should not be confused with post-quantum cryptography.
2. Under JCT Default Perspective F Visuals you can find several components and variants of this: the
one-time signature WOTS+, the normal Merkle signature (MSS), the extended Merkle signature scheme
(XMSS), and the multitree Merkle signature scheme (XMSS_MT).
In addition, the SPHINCS+ signature is extensively visualized. SPHINCS+ was one of the second track
candidates in the NIST post-quantum computing contest in round three (2020).
Many variants are offered in the JCT Algorithm Perspective, delivered by the BouncyCastle library.
3. In JCT Default Perspective F Visuals F Multivariate Cryptography, the rainbow signature vari-
ant by Jintai Ding and Dieter Schmidt [12] is used, which utilizes several layers of multivariate linear
equation systems.
i i
i i
i i
as long as they ensure that components can be quickly exchanged when they become
insecure.
To ensure IT security in the future, we need to build a portfolio of secure cryp-
tographic schemes. This portfolio must include schemes that are suitable for the
world of ubiquitous computing with many less powerful computers. It also needs to
include schemes that will remain secure in the event that powerful quantum comput-
ers are built. Several promising candidates have been discussed in this chapter. The
question of how to ensure long-term confidentiality still remains an open research
problem.
In 2016, NIST launched a competition to identify suitable alternatives to the
current generation of cryptographic methods (such as RSA or ECDSA). This next
generation of cryptographic algorithms is called “post-quantum cryptography.”
In July 2022, as a result of the third round, NIST announced which methods it
wants to standardize [14]:
13.7 Conclusion
• Attackers who just need to find one weak link in the chain. For example, one
server with weak password hashing, one computer on a network without
updates, one misconfigured router, one outdated component or library, and
so on;
• Users who mainly want speed and good usability, but don’t care about
security (awareness, backups, and common sense are needed even on the
computer);
• Monocultures and digital dependencies: This includes hardware with subsys-
tems such as “management engine” or “secure technology” and operating
i i
i i
i i
Figure 13.3 Embedding cryptology between corporate risk management and science.
systems or antivirus software that are always online and may send back
sensitive data or have backdoors;
• Last but not least, law enforcement and surveillance: Despite all the legit-
imate reasons, government agencies have never been able to keep the data
they collect to themselves. According to an unnamed intelligence source, all
the zero-day exploits they collected end up in the hands of organized crime
after an average of two years.
References
[1] Rivest, R. L., A. Shamir, and L. Adleman, “A Method for Obtaining Digital Signatures and
Public-Key Cryptosystems,” in Communications of the ACM, Vol. 21, No. 2, April 1978,
pp. 120–126.
[2] Lenstra, A. K., and E. R. Verheul, Selecting Cryptographic Key Sizes (1999 + 2001), in
Journal of Cryptology, Vol. 14, 2001, pp. 255–293, https://www.cs.ru.nl/E.Verheul/paper-
s/Joc2001/joc2001.pdf.
[3] Giry, D., BlueKrypt: Cryptographic Key Length Recommendation, Version 32.3, May
2020, https://www.keylength.com/.
[4] Shor, P. W., “Polynomial Time Algorithms for Prime Factorization and Discrete Loga-
rithms on a Quantum Computer,” in SIAM Journal on Computing, Vol. 26, No. 5, 1997,
pp. 1484–1509.
i i
i i
i i
[5] Data Encryption Standard (DES), Federal Information Processing Standards (FIPS) 46.
National Bureau of Standards, National Technical Information Service, Springfield, Vir-
ginia: U.S. Department of Commerce, 1977.
[6] Dworkin, M. J., et al., Advanced Encyption Standard (AES), Federal Information Process-
ing Standards(FIPS) 197, National Institute of Standards and Technology (NIST). Gaithers-
burg: U.S. Departmentof Commerce, November 26, 2001, https://nvlpubs.nist.gov/nist-
pubs/FIPS/NIST.FIPS.197.pdf.
[7] Bernstein, D., and T. Lange, Post-Quantum Cryptography—Dealing with the Fall-
out of Physics Success, in Nature, 2017, http://www.readcube.com/articles/10.1038/na-
ture23461; https://eprint.iacr.org/2017/314.pdf.
[8] Beullens, W., et al., Post-Quantum Cryptography: Current State and Quantum Mitigation,
Tech. rep., 2021, https://www.enisa.europa.eu/publications/post-quantum-cryptography-
current-state-and-quantum-mitigation/@@download/fullReport.
[9] McEliece, R. J., “A Public Key Cryptosystem Based on Algebraic Coding Theory,” in DSN
Progress Report 42–44, 1978, pp. 114–116.
[10] Merkle, R. C., “Secrecy, Authentication, and Public Key Systems,” PhD thesis, Department
of Electrical Engineering, Stanford University, 1979.
[11] Buchmann, J., et al., “CMSS—An Improved Merkle Signature Scheme,” in 7th Interna-
tional Conference on Cryptology in India—Indocrypt’06, R. Barua and T. Lange (eds.),
lecture notes incomputer science 4392, Springer-Verlag, 2006, pp. 349–363.
[12] Ding, J., and D. Schmidt, “Rainbow, a New Multivariable Polynomial Signature Scheme,”
in Applied Cryptography and Network Security, J. Ioannidis, A. Keromytis, and M. Yung
(eds.), Springer, 2005, pp. 164–175.
[13] C. H. Bennett and G. Brassard. “An Update on Quantum Cryptography,” in Advances in
Cryptology—CRYPTO ’84, G. R. Blakley, and D. Chaum (eds.), Vol. 196, lecture notes in
computer science, Springer-Verlag, 1985, pp. 475–480.
[14] Report on the Third Round of the NIST Post-Quantum Cryptography Standardization
Process, National Institute of Standards and Technology (NIST), July 2022 (updated Sept.
2022), https://nvlpubs.nist.gov/nistpubs/ir/2022/NIST.IR.8413.pdf.
[15] IETF, The Messaging Layer Security (MLS) Protocol RFC 9420, https://data-
tracker.ietf.org/doc/rfc9420/ (visited on 08/02/2023).
i i
i i
i i
APPENDIX A
APPENDIX A
Software
Sections A.1 to A.4 briefly describe the four CT variants CT1, CT2, JCT, and CTO.1
For each, the functions offered (via menus, templates, or plugins) are shown.
On the internet, a list with all functions offered by CrypTool 1 (CT1) can be created
with: https://www.cryptool.org/en/documentation/functionvolume?ctver
sion=ct1.
The main menu of CT1 contains both generic service functions in the six main
menu items
• File; • Options;
• Edit; • Window;
• View; • Help.
and the actual crypto functions in the following four main menus:
589
i i
i i
i i
590 Software
When you start CT2 it first shows the Startcenter (see Figure A.1).2
Figure A.2 shows the beginning of a list with all functions offered by Cryp-
Tool 2. This list was created with https://www.cryptool.org/en/documentation
/functionvolume?ctversion=ct2.
Besides the information on how you can get in the web a list of all functions in
CT2, this appendix contains information about the templates (graphical programs
included in CT2) and about the graphical editor (“WorkspaceManager”) of CT2.
When CT2 is started, the Startcenter opens first.
In the Startcenter, you have the choice to open CT2 templates in two different
ways:
• Via the Wizard (second icon with magic wand, below “Main functions”),
which guides you to the provided templates.
• Via the template tree (window in the center of the Startcenter), from which
you can select ready-made cryptographic workflows.
2. The current CT2 release is CT 2.1 (release 2023.1 from June 2023). Each day a new “nightly build” is
generated.
i i
i i
i i
i i
i i
i i
592 Software
The Wizard offers thematically nested choices for the desired cryptographic sce-
nario, for example, “Encryption/Decryption F Classical Encryption/Decryption F
Caesar,” and then finally leads the user to the corresponding template. The selected
scenario with the own inputs can be opened afterwards also as a graphical program
in the WorkspaceManager (small WorkspaceManager symbol with plus sign on the
top right of the respective last Wizard page) and can be stored in an own cwm file
(own template).
Alternatively to the provided templates, you can create your own graphical pro-
grams. The WorkspaceManager is there for this purpose: It provides a workspace
where you can assemble the components (e.g., an encryption function, a text input
function) yourself using the visual programming language. The WorkspaceManager
can be called in the Startcenter by means of the first icon under main functions. On
the empty workspace you can drag and drop all components from the left naviga-
tion bar and then connect them as desired. The implemented crypto functionality
is contained in these components (e.g. Enigma, AES).
In the template tree in the Startcenter there is at least one template for almost
every component. The offered templates contain immediately executable crypto-
graphic workflows. For example, if you change your input in the template for AES,
you can see dynamically and immediately how outputs change accordingly (e.g.,
how padding adds a block or what the effect of chaining is).
Figure A.3 shows an extract from the template tree of the Startcenter of CT2.
Screenshots from CT2 can be found at https://www.cryptool.org/en/ct2/
screenshots.
Resources and developer information about CT2 can be found at https://www
.cryptool.org/en/ct2/resources.
When you start JCT3 the first time it comes up with the welcome window
(see Figure A.4).
Figure A.5 shows the beginning of a list with all functions in JCrypTool. This
list was created with https://www.cryptool.org/en/documentation/function
volume?ctversion=jct.
After pressing “Start JCT” you can directly use the different functions. The
functions implemented in JCT are presented in two different perspectives:
• Default perspective;
• Algorithm perspective.
All functions of the default perspective can be found both in the menus and in
the navigation bar called “Crypto Explorer” (at the right side). The default perspec-
tive contains all important methods like classic transposition or modern AES, and
many visualizations (e.g., Diffie-Hellman key exchange or calculations on elliptic
curves).
3. The current JCT release is JCT 1.0.9 (July 2023). Occasionally a new weekly build is generated. You can
find further information about JCT at: https://www.cryptool.org/en/jct/volunteer.
i i
i i
i i
i i
i i
i i
594 Software
All functions of the algorithm perspective can be found in the navigation bar
called “Algorithms.” This perspective contains all detail settings of the various
algorithms; it especially offers post-quantum computing algorithms.
On the starting page of CTO (Figure A.6) you can choose via text search or icon
click which plugin to start.
CrypTool-Online (https://www.cryptool-online.org) is a website with
applications (so-called plug-ins) for testing, learning, and discovering ancient and
modern cryptography. Current web technologies such as React, Chakra UI, Boot-
strap, and WebAssembly are used. The technological aim is a responsive design
for all device sizes, and simultaneously a common full-screen like appearance for
desktop monitors.
Figure A.7 shows the beginning of a list with all functions offered by CTO. This
list was created with https://www.cryptool.org/en/documentation/function
volume?ctversion=cto.
As the overall function list at the CTP (CrypTool portal) is only updated twice
a year, the most current list of CTO plugins can be found on the CTO starting page
(see Figure A.8).
Parts of CTO are:
i i
i i
i i
Figure A.5 Display of functions volume in CTP: the first functions offered by JCT.
i i
i i
i i
596 Software
i i
i i
i i
i i
i i
i i
598 Software
Figure A.8 Display of the first functions in CTO on the CTO starting page (February 2022).
i i
i i
i i
i i
i i
i i
i i
i i
i i
APPENDIX B
APPENDIX B
Miscellaneous
601
i i
i i
i i
602 Miscellaneous
And Jimmy Went to the Rainbow (original title: Und Jimmy ging zum Regenbo-
gen), Johannes Mario Simmel, Knaur Verlag, 1970.
The novel plays between 1938 and 1967 in Vienna. The main character Manual
Aranda uncovers step by step the past of his murdered father. Important for the
plot is an encrypted manuscript, which is decrypted in Chapter 33. In the novel
the cipher is called “25-fold Caesar cipher.” It is actually a Vigenère cipher with a
25-character key. A movie of the novel appeared in 1971.
i i
i i
i i
i i
i i
i i
604 Miscellaneous
i i
i i
i i
The Museum of the Stolen Memories (original title: Das Museum der gestohlenen
Erinnerungen), Ralf Isau, Thienemann-Verlag, 1997/2003.
In this exciting novel the last part of the oracle can only be solved with the joined
help of the computer community. The book got several awards and exists in eight
different languages, but not in English yet.
Final Solution, Scott McBain, manuscript not published by Harper Collins, 2004
(German version was published in 2005).
In a near future, politicians, chiefs of military, and secret services of many dif-
ferent countries take over all the power. With a giant computer network called
“Mother” and complete surveillance, they want to cement their power and com-
mercialization of life forever. Humans are only assessed according to their credit
rating, and globally acting companies elude of any democratic control. Within the
thriller, the obvious injustice, but also the realistic likelihood of this development,
are considered again and again.
With the help of a cryptographer, a code to destroy was built into the super
computer “Mother”: In a race several people try to start the deactivation (Lars
Pedersen, Oswald Plevy, the female American president, the British prime minister,
and an unknown Finnish person named Pia, who wants to take revenge for the
death of her brother). On the opposite side a killing group acts under the special
guidance of the British foreign minister and the boss of the CIA.
i i
i i
i i
606 Miscellaneous
Heidelberg Lies (original title: Heidelberger Lügen), Wolfgang Burger, Piper, 2006.
This detective story playing in the Rhein-Neckar area in Germany has several inde-
pendent strands and local stories, but mainly it is about police officer Gerlach from
Heidelberg. On page 207, the cryptographic reference for one strand is shortly
explained: The soldier Hörrle had copied circuit diagrams of a new digital NATO
decryption device and the murdered man had tried to sell his perceptions to China.
i i
i i
i i
The only cryptographic parts are a “Sprungcode” (the criminals use this method
to communicate via newsletter adverts), steganography (used to hide the Enigma
key), and an Enigma message (containing the encrypted coordinates of the treasure).
At the beginning of the plot an Enigma device is stolen with high efforts which
is necessary to let the story play in the constructed way. But in the reality today such
a theft is completely needless, as there are great software emulators for the Enigma.
Perdition (original title: Flickan som lekte med elden), Stieg Larsson, 2006.
The author was posthumously awarded in 2006 with the Scandinavian thriller
award. The superhero Lisbeth Salander uses PGP and occupies herself with
mathematical riddles like the Fermat theorem.
A King for Germany (original title: Ein König für Deutschland), Andreas
Eschbach, Lübbe, 2009.
The novel deals with manipulations of electronic voting machines.
Vincent Merrit, a young American programmer, is blackmailed to write such
a program. Besides commercially oriented blackmailers, massively multiplayer
online role-playing games (MMORPGs) and live action role playing (LARP), have
a role. Because Merrit assumed that his program will be misused, he installed a
trapdoor: If a party with the name VWM participates at the election, it auto-
matically gets 95% of the votes. The fictional story line is based on many veri-
fiable and well researched facts, which are referenced in footnotes. While the
i i
i i
i i
608 Miscellaneous
i i
i i
i i
modern technology integrated into our modern lives as a virtual world overlaying
our real world.
The Fifth Murderer (original title: Der fünfte Mörder), Wolfgang Burger, Piper,
2011.
Location and time of the story: Germany / Heidelberg, 1990 to 2009. Episode
7 of the Alexander-Gerlach series. Inspector Alexander Gerlach almost became a
victim of a bomb blast when the sport utility vehicle (SUV) of a Bulgarian panderer
exploded. Gerlach starts investigating because he wants to prevent a gang warfare,
but then his bosses call him off. When the journalist Machatschek supports Gerlach,
he communicates with him only via Skype using an add-on encryption program
which he believes is the most secure in the world.
Master of the Universe: Master of all Staff (original title: Herr aller Dinge),
Andreas Eschbach, Lübbe, 2011.
This novel deserved a much broader audience: The idea in it of the “most terrific of
all crimes,” which is the origin of the whole story, is new and almost revolutionary,
but also infinitely sad. Along the failing partnership of Hiroshi (inventor genius)
and Charlotte, important topics like justice, human wealth, and power are dealt
with.
From a crypto perspective, Hiroshi uses distributed calculations and deve-
loped an encryption and backup system which misleads the government which
bugged him.
Blackout – Tomorrow is too Late (original title: Blackout – Morgen ist es zu spät),
Marc Elsberg, Blanvalet, 2012.
During a cold day in winter, all power supply networks in Europe break down.
Agencies, energy suppliers, and security companies are in the dark and unable to
i i
i i
i i
610 Miscellaneous
solve the problem. The Italian computer scientist Piero Manzano believes that this is
caused by terrorists using hackers: All customers use smart meters, electricity meters
controlled by software that was manipulated. Despite the integrated security and
encryption components, they have been hacked, and are out of order by wrong
control sequences. The terrifying consequences happening at various locations are
described realistically and excitingly, as are the reactions of the human beings.
The Eigths Revelation (original title: Die achte Offenbarung), Karl Olsberg, Auf-
bau Taschenbuch, 2013.
Can a message from the past change our future? An ancient, encrypted manuscript
fell into the hands of historian Paul Brenner. The more he decodes the text, the more
puzzling the content is: Because the book tells with remarkable precision events
years ahead of the time of its presumed creation. While highly dangerous genetic
material disappears from a U.S. laboratory, someone tries to prevent, at any price,
Paul from deciphering the last (the eighth) revelation. A gripping thriller about a
shockingly realistic apocalypse with many human aspects.
As a reader, you can participate in the deciphering of the manuscript.
The experiments of Paul to make the right persons aware of his discovery and
to correct it later, are described very excitingly—even chief editors have a dilemma
with conspiracy.
The cipher on the last book page is offered as a challenge in the crypto
competition MTC3: https://mysterytwister.org/challenges/level-1/the-
last-note.
ZERO – They Know What You Are Doing (original title: ZERO – Sie wissen, was
du tust), Marc Elsberg, Blanvalet Verlag, 2014.
London. In a pursuit a boy is shot. His death takes the journalist Cynthia Bonsant
to the acclaimed internet platform Freemee. Freemee collects and analyzes data, and
thus promises its millions of users (rightly) a better life and more success. There is
only one who warns about Freemee and about the power that the online newcomer
could give just a few: ZERO, the most searched online activist in the world. As
Cynthia begins precisely to research, she’s becoming the quarry. And in a world of
cameras, headsets, and smartphones there is no escape.
Highly topical and menacing: the transparent person under control. The novel
takes place in the near future (fiction) and contains many contemporary references
such as PRISM, predictive analytics, and gamification. By the way, references to
well-known science fiction media like The Running Man, Monkey Wrench Gang,
V as Vendetta (V wears a Guy Fawkes mask, now the hallmark of Anonymous),
Network, and Body Snatchers are processed.
Technologically / cryptologically the protagonists move on the highest level,
which is not further explained: Alice Kinkaid communicates with a Raspberry Pi.
Cynthia’s daughter Vi uses mesh networks.
i i
i i
i i
Remark 1:
A long list of (partly commented) samples of cryptology in fictional literature can be
found on the following German web page: https://www.staff.uni-mainz.de/
pommeren/Kryptologie/Klassisch/0_Unterhaltung/. For some older authors
(e.g., Jules Verne, Karl May, Arthur Conan Doyle, and Edgar Allen Poe) there are
even links to the original and relevant text pieces.
Remark 2:
You can find title pages of some of these books on the website of Tobias Schrödel,
who collects classic books about cryptography: https://cryptobooks.org/.
Remark 3:
If you know of further books and movies, where cryptography has a major role then
we would be very glad if you could send us the exact title and a short explanation
about the movie/book’s content. We will insinuate your possible enthusiasm for a
title. Thanks a lot.
i i
i i
i i
612 Miscellaneous
Top Secret – The Book for Detectives and Spies (original title: Streng geheim – Das
Buch für Detektive und Agenten), author unknown, Edition moses, year unknown.
This is a thin book for small kids with Inspector Fox and Dr. Chicken.
The Three Investigators: The Secret Key (Original German title: Die 3 ???: Der
geheime Schlüssel nach Alfred Hitchcock (volume 119), Robert Arthur, Kosmos-
Verlag (from 1960).
The three detectives Justus, Peter, and Bob have to decrypt covered and encrypted
messages within this story to find out what is behind the toys of the Copperfield
company.
The Manual for Detectives. Everything You Need to Know About Ciphers, Codes,
Reading Tracks and the Biggest Detectives of the World (original title: Das Hand-
buch für Detektive. Alles über Geheimsprachen, Codes, Spurenlesen und die
großen Detektive dieser Welt), Matthias Müller-Michaelis, Südwest, 2002.
A small collection on 62 pages.
Top Secret! – How to Encrypt Messages and to Hack Codes (original title: Streng
geheim! – Wie man Botschaften verschlüsselt und Zahlencodes knackt), Rudolf
Kippenhahn, rororo, 2002.
In this novel, a grandpa, an expert for secret writings, teaches his four grandchildren
and their friends how to encrypt messages that nobody should read. Because there
i i
i i
i i
is someone who hacks their secrets, the grandpa has to teach them more and more
complicated methods.
Within the framework of this story, the most important classic encryption
methods and their analyses are explained in a manner exciting and appropriate
for children.
Top Secret. The Big Book for Detectives (original title: Streng geheim. Das große
Buch der Detektive), Corinna Harder and Jens Schumacher, Moses, 2003.
A collection on 118 pages.
Your Mission in the Weird Villa. Riddle Thriller (original title: Dein Auftrag in
der unheimlichen Villa. Kennwort Rätselkrimi), Helga Talke and Milena Baisch,
Loewe, 2003.
From 4th form. http://www.antolin.de.
Young detectives solve simple ciphers and codes during their missions.
The Three Investigators: Manual for Secret Messages (original title: Die 3 ???:
Handbuch Geheimbotschaften), Bernd Flessner, Kosmos, 2004.
On 127 pages you learn in an easy and exciting manner, structured by the method
types, which secret languages (like the one of the Navajo Indians or dialects)
and which secret writings (real encryption or hiding via technical or linguistic
steganography) existed and how simple methods can be decrypted.
The author tells where in history the methods were used and in which novels
authors used encryption methods [like in Edgar Allan Poe’s The Gold Bug, like with
Jules Verne’s hero Mathias Sandorf, or like with Astrid Lindgren’s master detective
Blomquist who used the ROR language (similar inserting ciphers are the spoon or
the B language)].
This is a didactically excellent introduction for younger teens.
The Treasure of the White Hawks (original title: Der Schatz der weißen Falken),
directed by Christian Zübert, 2005.
This exciting adventure movie for kids ties in with the tradition of classics like Mark
Twain’s The Adventures of Tom Sawyer and Huckleberry Finn or Enid Blytons “The
Famous Five.” The plot happens in summer 1981. In an old half tumbledown villa
three young kids find the treasure map of the “White Hawks,” which they decrypt
with the help of a computer. Traced by another gang they aim to go to an old castle.
i i
i i
i i
614 Miscellaneous
Remark 1:
You can find title pages of many of these kid books on the website of Tobias
Schrödel, who collects classic books about cryptography: https://cryptobooks
.org/.
Remark 2:
If you know of further books that address cryptography in a didactic and, for chil-
dren, adequate way, then we would be very glad if you could send us the exact book
title and a short explanation about the book’s content. Thanks a lot.
Python Example B.1: Decryption of the Gold-Bug Ciphertext from the Novel
of E.A. Poe (with Python)
print ("\n# Appendix_B --SAMPLE 010: =========")
PA = 'ETHSONAIRDGLBVPFYMUC '
print('Plaintext alphabet PA: ', PA , ' Length of PA ', len(PA))
CA = "8;4)+*56(!302 '.1:9?-"
print('Ciphertext alphabet CA:', CA , ' Length of CA ', len(CA))
C = '''53++!305))6*;4826)4+.)4+);806*;48!8'60))85;1 +(;:+*8!83(88)5*!;46
(;88*96*?;8)*+(;485);5*!2 :*+(;4956*2(5*-4)8'8*;4069285);)6!8)4++;1(+9;4
8081;8:8+1;48!85;4)485!528806*81(+9;48;(88;4(+?34;48)4+;161;:188;+?;'''
P = C.translate(codetableC2P);
print('\nKidd decrypted :')
print(P)
i i
i i
i i
outtab = "12345"
trantab = str.maketrans(intab , outtab)
stri = "this is string example ..AE..wow !!!"
print ("\ nTest substituting only lower -case vocals :", stri.translate( �
� trantab))
#------------------------------------
# Appendix_B --SAMPLE 010: =========
# Plaintext alphabet PA: ETHSONAIRDGLBVPFYMUC Length of PA 20
# Ciphertext alphabet CA: 8;4)+*56(!302 '.1:9?- Length of CA 20
#
# Kidd decrypted:
# AGOODGLASSINTHEBISHOPSHOSTELINTHEDEVILSSEATFORTYONEDEGREESANDTHI
# �
� RTEENMINUTESNORTHEASTANDBYNORTHMAINBRANCHSEVENTHLIMBEASTSIDESHOOTFROMTH �
�
# ELEFTEYEOFTHEDEATHSHEADABEELINEFROMTHETREETHROUGHTHESHOTFIFTYFEETOUT
#
# Test substituting only lower -case vocals: th3s 3s str3ng 2x1mpl2..AE �
� ..w4w!!!
Remark 1:
When printing the ciphertext, Poe or his publisher “cheated,” similarly to the
author of the Python code who used only ASCII characters.
In the archive of an original publication (e.g., at https://archive.org/
details/goldbug00poegoog at page 95) you can see that Poe used characters that
were common in the letterpress printing (and most of them are also part of the
ASCII set). It is very unlikely that an untaught pirate would use just such characters
for his ciphertext.
Remark 2:
The sample code uses the Python string functions “maketrans” and “translate.”
So both alphabets (for the plaintext and the ciphertext) are inserted as a simple
string, and “maketrans” creates a mapping table. The actual encryption is done by
“translate.” For the decryption you just have to switch the arguments of “make-
trans” for the two alphabets. The otherwise necessary transformations between
characters and their ASCII numbers (using “str” and “ord”) can be avoided. This
is ideal for monoalphabetic ciphers—especially for lessons at the junior high school.
It’s evident how less code is needed with Python 3 or SageMathfor such tasks.
In the sample there were only 7 lines of code really necessary.
As a guide for the authors and because the internet and marketing ads often deviate
from the official spelling, we list the recommendations from IEC (International
Electrotechnical Commission), and so on.
i i
i i
i i
616 Miscellaneous
The LaTeX package siunitx [5] allows you to conveniently enter numbers
and units and display them consistently throughout the document. The package
documentation is very good and easy to understand.
1000B = 1 kB = 1 kilobyte
1024B = 1 KiB = 1 kibibyte = 1 KB [sometimes wrongly as 1 kilobyte]
Hyphens
Public-key cryptography: Hyphen if the two words are used like one adjective.
Brute-force attack: Hyphen if the two words are used like one adjective.
https://www.scribendi.com/academy/articles/hyphenation.en.html.
https://dictionary.cambridge.org/grammar/british-grammar/hyphens.
References
[1] Kippenhahn, R., VerschlüsselteBotschaften: Geheimschrift, Enigma und Chipkarte, 1st ed,
Rowohlt, 1997.
[2] Slade, R., REVIEW: “Kim,” Rudyard Kipling, 2006, http://catless.ncl.ac.uk/Risks/24.49
.html%5C#subj12.
[3] Kipling, R., Kim, https://kipling.thefreelibrary.com/Kim.
[4] Witten, H., I. Letzner, and R.-H. Schulz. “RSA & Co. in der Schule: ModerneKryptologie,
alteMathematik, raffinierteProtokolle, Teil 1: Sprache und Statistik”. In: LOG IN 3/4,
1998, pp. 57–65, https://informatik.schule.de/krypto/.
[5] Wright, J., Siunitx—A comprehensive (SI) Units Package, 2023, https://ctan.org/pkg/
siunitx.
i i
i i
i i
CHAPTER 0
CHAPTER 0
Bernhard Esslinger
Initiator of the CrypTool project, editor, and main author of this book. Professor
for IT security and cryptography at the University of Siegen. He is the former CISO
of SAP AG, and former head IT security at Deutsche Bank.
Email: [email protected].
Contributors
Doris Behrendt
Author of Section 6.5 (“The RSA Plane”). Mathematician, member of CT Team
since 2018. Took over the project lead of the CT project in 2023 at Bundeswehr
University, Munich. Email: [email protected].
Matthias Büger
Contributor to Chapter 8 (“Elliptic-Curve Cryptography”). Research analyst at
Deutsche Bank.
Miroslav Dimitrov
First author of Chapter 11 (“Lightweight Introduction to Lattices”). Bulgarian
Academy of Sciences. Email: [email protected].
Bartol Filipovic
Original author of the CT1 elliptic curve implementation and of Chapter 8
(“Elliptic-Curve Cryptography”).
Martin Franz
Original author of Chapter 10 (“Homomorphic Ciphers”). Works and carries out
research in the area of applied cryptography.
Henrik Koy
Main developer and coordinator of CT1 development version 1.3 and 1.4. Book
reviewer and TEX guru. Cryptographer and project leader IT at Deutsche Bank.
617
i i
i i
i i
Vasily Mikhalev
Author of Section 2.5 (“Hagelin Machines as a Models for Precomputer Ciphers”),
coauthor of Section 1.7 (“Best Known Attacks on Given Ciphers”), and coauthor
of Chapter 3 (“Historical Cryptology”). Postdoctoral researcher at the University
of Siegen.
Roger Oyono
First implementer of the CT1 factorization dialog and original author of Chapter 6
(“The Mathematical Ideas Behind Modern Asymmetric Cryptography”).
Klaus Pommerening
Original author of Chapter 9 (“Foundations of Modern Symmetric Encryption”).
Former professor of mathematics and computer science at Johannes-Gutenberg-
Universität Mainz.
Harald Ritter
Contributor to Chapter 11 (“Lightweight Introduction to Lattices”). Member of
IACR; PhD thesis on lattice basis reduction at the University of Frankfurt. Senior
Consultant at NOVOSEC AG, Frankfurt/Main.
Email: [email protected].
Christine Stötzel
Contributor to Chapter 2 (“Paper-and-Pencil and Precomputer Ciphers”).
Johannes Buchmann
Coauthor of Chapter 13 (“Future Use of Cryptography”). Prof. Johannes Buch-
mann held the Chair for Theoretical Computer Science (Cryptography and Com-
puter Algebra) at the department of Computer Science of the Technische Universität
Darmstadt TUD). Retired.
Alexander May
Coauthor of Chapter 12 (“Solving Discrete Logarithms and Factoring”) and of
Chapter 13 (“Future Use of Cryptography”). Full professor at the department
of mathematics (chair for cryptology and IT Security) of the Ruhr-Universität
Bochum, and member of the Horst-Görtz Institute for IT Security. His research
focuses on algorithms for cryptanalysis, especially on methods for attacking the
RSA cryptosystem.
i i
i i
i i
Erik Dahmen
Coauthor of Chapter 13 (“Future Use of Cryptography”). Researcher at the
Chair for Theoretical Computer Science (Cryptography and Computer Algebra),
Department of Computer Science, Technische Universität Darmstadt, Germany.
Ulrich Vollmer
Coauthor of Chapter 13 (“Future Use of Cryptography”). Researcher at the
Chair for Theoretical Computer Science (Cryptography and Computer Algebra),
Department of Computer Science, Technische Universität Darmstadt, Germany.
Antoine Joux
Coauthor of Chapter 12 (“Solving Discrete Logarithms and Factoring”). Antoine
Joux is the holder of the Cryptology chair of the Foundation of the University
Pierre et Marie Curie (Paris 6) and a senior security expert at CryptoExperts, Paris.
He worked in various fields of cryptanalysis, and he is a key player in the recent
advances in computing discrete logarithms in fields of small characteristic.
Arjen Lenstra
Coauthor of Chapter 12 (“Solving Discrete Logarithms and Factoring”). Arjen
Lenstra is a full professor at École Polytechnique Fédérale de Lausanne (EPFL) and
head of the laboratory for cryptological algorithms. He is one of the inventors of
the best algorithm currently available for factoring integers (the number field sieve).
He was involved in many practical factoring records.
Beáta Megyesi
Coauthor of Chapter 3 (“Historical Cryptology”). Professor of computational
linguistics, Uppsala University, Sweden. PI of the DECRYPT project. Email:
[email protected].
Alicia Fornés
Coauthor of Chapter 3 (“Historical Cryptology”). Computer Vision Center, Uni-
versitat Autònoma de Barcelona, Spain.
Benedek Láng
Coauthor of Chapter 3 (“Historical Cryptology”). Historian of science, Eötvös
Loránd University, Budapest, Hungary.
Michelle Waldispühl
Coauthor of Chapter 3 (“Historical Cryptology”). Associate professor of German
linguistics and language acquisition at the University of Gothenburg, Sweden.
i i
i i
i i
Nils Kopal
Coauthor of Chapter 3 (“Historical Cryptology”) and Section 1.7 (“Best Known
Attacks on Given Ciphers”). Leader of the development of the software CrypTool 2.
Computer scientist and cryptanalyst working as a postdoctoral researcher at the
University of Siegen. Email: [email protected].
Ralph Simpson
Coauthor of Section 1.6 (“Key Spaces: A Theoretical and Practical View”). See
www.CipherHistory.com.
i i
i i
Index
A for factoring integers, 567–71
Addition new, 24
associativity of, 498 for prime fields, 558–62
closure under, 498 random-based, 24
commutativity of, 498 types of, 24
in groups, 215–16 See also specific algorithms
neutral element under, 498 Alphabetic-code elements, 113
tables, 208, 272 Alphabetic elements, 113
Additive inverses, 208–11, 498 American Cryptogram Association (ACA),
ADFG(V)X cipher, 57, 102 73–74
Advanced Encryption Standard (AES) AMSCO cipher, 42
about, 3–4 AND, 394, 395, 398–99
animation in CTO, 26 Arithmetic prime sequences, 167–70
block ciphers and, 424–26 Arithmetic progression, 167, 169–70
in CT2, 26–28 Artificial intelligence (AI), 109, 119, 134
design principles, 425 Associativity, 498, 499
Mini-AES, 30–32 Asymmetric cryptography
with OpenSSL at command line, 28–29 about, 301
with OpenSSL within CTO, 29–30 applications using numerical examples,
round function, 426 252–57
S-AES, 32 Diffie-Hellman key-exchange protocol and,
structure of, 425 253–57
for symmetric ciphers, 583 one-way functions and, 301–3
visualizations/implementations, 25–30 Asymmetric encryption
Affine cipher, 46, 83–85 advantage of, 6
Algebraic attacks defined, 5
about, 416 illustrated, 6
with known plaintext, 416–17 keys, 5–6
on LFSRs, 444–47 procedure, 5–6
Algebraic cryptanalysis See also RSA algorithm
about, 415–16 Atbash cipher, 46, 81
attacks with known plaintext, 416–17 Attacks
complexity of attack and, 417–18 best known, 14–16
Algebraic normal form (ANF), 401–2, 412–14 brute-force, 4–5
Algorithms chosen-ciphertext (CCA), 20
constant-based, 24 chosen-plaintext (CPA), 20
for extension fields, 562–67 ciphertext-only (COA), 20
621
V Z
Variable-key attacks, 19 Zhang, Yitang, 174–75
Vectors
about, 316, 487
For further information on these and other Artech House titles, including previously considered out-of-print
books now available through our In-Print-Forever® (IPF®) program, contact: