Lecture.3
Lecture.3
CRYPTOGRAPHY
“All communication involves some sort of encoding of messages”—John Pierce, An
Introduction to Information Theory: Symbols, Signals, Noise
“It may be roundly asserted that human ingenuity cannot concoct a cipher which
human ingenuity cannot resolve.”—Edgar Allen Poe, “A Few Words on Secret
Writing,” Graham’s Magazine, July 1841, 19:33-38
Five Minute Binary Refresher
• Binary and Decimal systems
• Decimal number line (Base 10): 0,1,2,3,4,5,6,7,8,9,?
• Binary number line (Base 2): 0,1,?
• How to count to 10 in binary?
• The math is actually fun (it’s like playing blackjack):
• The powers of 2 are 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, etc.
• To manually convert any number to binary, we simply count the additive powers:
• 53 = (32 + 16 + 4 + 1) = (1 x 32) + (1 x 16) + (0 x 8) + (1 x 4) + (0 x 2) + (1 x 1) = 110101
• To verify: python3 -c "print(bin(53))" | cut -c 3-
• 86 = (64 + 16 + 4 + 2) = (1 x 64) + (0 x 32) + (1 x 16) + (0 x 8) + (1 x 4) + (1 x 2) + (0 x 1) = 1010110
• To verify: python3 -c "print(bin(86))" | cut -c 3-
• To reverse: 0 + 2 + 4 + 0 + 16 + 0 + 64 = 86
1010110 = (0 x 20) + (1 x 21) + (1 x 22) + (0 x 23) + (1 x 24) + (0 x 25) + (1 x 26) =
Exclusive Or Refresher
• The Exclusive Or (XOR) operation states:
• 0⨁0=0
• 1⨁1=0
• 1⨁0=1
• 0⨁1=1
• Thus:
• α⨁α=0
• (α ⨁ β) ⨁ β = α
• Thus, the binary equivalent of hex 5 (0x05, 5d) is 0101, which, when XORd with 1111 (hex
0x0F, 15d) yields: 1010, or hex A (decimal 10), or (1010)2 = 0x0A
• The binary equivalent of hex E (0x0E, 14d) is 1110, when XORd with 1111 yields 0001, or hex 1
(decimal 1), i.e. (0001)2 = 0x01
• (10101010)2 = (AA)16 = 0xAA; (01010101)2 = (55)16
• 10101010 ⨁ 01010101 = 11111111 (0xFF) [0xAA ⨁ 0x55 = 0xFF]
echo –n ‘CAESAR’ | xxd –b
• Example: view and execute: src.lecture/lecture.3/xor/xor.py echo –n ‘ATTACK’ | xxd –b
Modular Arithmetic
• Modular arithmetic is a way we can make a finite field closed under defined operations,
including addition, subtraction, multiplication and division
• Modular arithmetic is concerned with integers, aka whole numbers
• Take 17 / 5 = 3 with a remainder of 2
• It is sometimes useful to focus on the remainder of division, so, we say that 17 mod 5 ≡ 2,
that is to say, 17 modulo 5 is congruent to 2
• In 17 mod 5 ≡ 2, 5 is known as the modulus
• The modulus allows us to keep the remainder within a certain range (N – 1) [viz. 0 – 4]:
range: {0...4} range: {0...4} range: {0...4} range: {0...4}
0 mod 5 ≡ 0 5 mod 5 ≡ 0 10 mod 5 ≡ 0 15 mod 5 ≡ 0
1 mod 5 ≡ 1 6 mod 5 ≡ 1 11 mod 5 ≡ 1 16 mod 5 ≡ 1
2 mod 5 ≡ 2 7 mod 5 ≡ 2 12 mod 5 ≡ 2 17 mod 5 ≡ 2 R<5
3 mod 5 ≡ 3 8 mod 5 ≡ 3 13 mod 5 ≡ 3 18 mod 5 ≡ 3
4 mod 5 ≡ 4 9 mod 5 ≡ 4 14 mod 5 ≡ 4 19 mod 5 ≡ 4
Modular Arithmetic
• If two numbers have the same remainder on division by N, we regard them as equivalent
modulo N: x = y (mod N) (e.g., 6/5, 11/5, 16/5, where the remainder is 1, thus 6, 11 and 16
are all equivalent modulo 5)
• If N is a positive integer, arithmetic modulo N uses only the integers in the series 0, 1, 2, 3, ...
N-1, that is to say, integers from 0 to N-1
• In the US, we use modular arithmetic every day, with a 12-hour clock wherein we use
addition modulo 12 (10 PM + 6 hours = (10+6) - 12 = 4 AM, or by counting six hours
around the 12-hour clock: 11, 12, 1, 2, 3, 4)
• We also use modular arithmetic every day in calculating the days of the week (N = 7) and
for determining even vs odd (we don’t even need Euclid) (N=2)
Modular Arithmetic
• Modulo Definition (per Gauss):
Let a, r, m ∈ ℤ (where ℤ is a set of all integers) and m > 0. We write
a ≡ r mod m
(a is congruent to r modulo m)
• For example, 42 = (4 x 9) + 6 (there are four 9’s in 36, to which 6 is added yielding 42).
• a = 42
• r=6
• m=9
• We say 42 ≡ 6 mod 9; where 9 | 42 – 6 (36) : 36 / 9 = 4 (‘|’ means “evenly divides”)
Equivalence Classes
• For every given modulus m and number a, there are infinitely many valid remainders.
• For example [a ≡ r mod m iff m | (a-r): (42 – 6) / 9 = 4]:
• 12 ≡ 3 mod 9, 3 is a valid remainder since 9 | (12 – 3) (read: 9 divides (12 – 3), 9 divides 9)
• 12 ≡ 21 mod 9, 21 is a valid remainder since 9 | (21 – 3) (9 divides 18)
• 12 ≡ –6 mod 9, –6 is a valid remainder since 9 | (–6 – 3) (9 divides –9)
• The set of numbers:
{...,-24, -15, -6, 3, 12, 21, 30,...}
form what is known as an equivalence class. There are eight other such classes just for the
modulus 9:
{...,-27,-18,-9,0,9,18,27,...},{...,-26,-17,-8,1,10,19,28,...}, ...,{...,-19,-10,-1,8,17,26,35,...}
• For a given modulus m, it does not matter which element from a class we choose for a
given computation, as they are all equivalent.
• This property of equivalence classes has major positive implications in modern
cryptography, especially concerning modular exponentiation...
INTRODUCTION TO
CRYPTOGRAPHY
“Human ingenuity cannot concoct a cipher which human ingenuity cannot
resolve.”—Edgar Allen Poe, “A Few Words on Secret Writing,” Graham’s Magazine,
July 1841, 19:33-38
Fundamental Types
• Steganography (στεγανός means covered and γράφειν means to write)
• Message is not visible, but remains plaintext if anyone can uncover it...
• Demaratus, a Greek exile, sent a warning back to Greece about a forthcoming attack by Xerxes King of
the Persians by writing it directly on the wooden backing of a wax tablet before applying beeswax, thus
the beeswax covered the writing.
• Herodotus tells the story of Histaiaeus who sent a message to Aristagoras of Miletus to revolt against
the Persian King, by shaving the head of his most trusted servant, "marking" the message onto his scalp,
then sending him on his way once his hair had regrown
• Other classical (and modern) uses involve invisible ink, ancient uses of the thithymallus plant as
reported by Pliny the Elder (d. AD 79, Vesuvius) and modern uses include invisible ink kits for kids
• 20th century uses include German Abwehr agents using 1 millimeter diameter “microdots”, which used
subminiature photography to embed of a page of documents into a ‘dot’ that looked to the naked eye
as a period.
• Modern uses of steganography including hiding messages in graphical images, and including Hewlett-
Packard color laser printers add tiny yellow dots to each page, which contain encoded printer serial
numbers and date and time stamps
Fundamental Types
• Cryptography (κρυπτός means hidden and γράφειν means to write)
• Message is modified into some form of meaningless characters but may be quite
visible (as in the Scytale leather belt worn by Spartan spies)
ABCDEFGHIKLMNOPQRSTVXYZ
• So in the shift-3 cipher, “CAESAR” would encrypt as: “FDHXDV”
Caesar Cipher
• Suetonius in his Lives of the Caesars (2nd century A.D.), describes the Caesar Cipher with a
rotation of 3 characters
• The end letters X, Y and Z could not be shifted down, so they would “roll back” to the top of
the alphabet, X becoming A and Y becoming B and Z becoming C.
• To decrypt the ciphertext, simply reverse the direction of the algorithm (“F” becomes “C”)
So:
xi , yi , k ∈ { 0...22 }, in alphabet ℤ23
Encryption: yi = (xi + k) mod 23
Decryption: xi = (yi - k) mod 23
ABCDEFGHIKLMNOPQRSTVXYZ
Transposition Cipher
• In a transposition cipher the plaintext remains the same, but the order of the characters
is shuffled around at a “random” line length
• This line length serves as the “key” to solving the cipher
• Words are written without spacing with a fixed line length (right margin) and then
wrapped onto the next line without respect to words, such as the following with a “key”
of 9:
THISISTHE
TEXTTHATI
AMSHOWING
• Once written thus, the text is transposed as columns, reading down from left to right,
yielding the ciphertext: TTAHEMIXSSTHITOSHWTAIHTNEIG
• Cryptanalysis involves letter frequency analysis
• Running the ciphertext through a second transposition can improve the safety of the
encryption
In-Class Exercise
• Let’s use a brute force method on the ciphertext “zayeldan”...which would brute force
as:
Shift Result (mod 26)
1. abzfmebo
2. bcagnfcp
3. cdbhogdq
4. decipher
5. …
Cryptanalysis Using Letter-Frequency
• Statistical letter frequency analysis uses a standard English letter frequency tabulation to
render the ordering of English characters from most to least common, yielding (in order):
etaoinshrdlcumwfgypbvkjxqz
• Knowing the properties of a rotation cipher (i.e., a consistent shift), we can conclude that
probably the most common letter of the ciphertext corresponds to the letter ‘e’:
Cryptanalysis Using Letter-Frequency
• Assume ciphertext:
"qzfc dnzcp lyo dpgpy jplcd lrz zfc qlespcd mczfrse qzces zy estd nzyetypye, l
yph yletzy, nzynptgpo ty wtmpcej, lyo opotnlepo ez esp aczazdtetzy esle lww xpy
lcp ncplepo pbflw. yzh hp lcp pyrlrpo ty l rcple ntgtw hlc, epdetyr hspespc esle
yletzy, zc lyj yletzy dz nzynptgpo lyo dz opotnlepo, nly wzyr pyofcp. hp lcp xpe
zy l rcple mleewp-qtpwo zq esle hlc. hp slgp nzxp ez opotnlep l azcetzy zq esle
qtpwo, ld l qtylw cpdetyr awlnp qzc eszdp hsz spcp rlgp esptc wtgpd esle esle
yletzy xtrse wtgp. te td lwezrpespc qteetyr lyo aczapc esle hp dszfwo oz
estd. mfe, ty l wlcrpc dpydp, hp nly yze opotnlep hp nly yze nzydpnclep hp nly
yze slwwzh estd rczfyo. esp mclgp xpy, wtgtyr lyo oplo, hsz decfrrwpo spcp, slgp
nzydpnclepo te, qlc lmzgp zfc azzc azhpc ez loo zc opeclne. esp hzcwo htww wteewp
yzep, yzc wzyr cpxpxmpc hsle hp dlj spcp, mfe te nly ypgpc qzcrpe hsle espj oto
spcp. te td qzc fd esp wtgtyr, clespc, ez mp opotnlepo spcp ez esp fyqtytdspo
hzcv hstns espj hsz qzfrse spcp slgp esfd qlc dz yzmwj loglynpo. te td clespc qzc
fd ez mp spcp opotnlepo ez esp rcple eldv cpxltytyr mpqzcp fd esle qczx espdp
szyzcpo oplo hp elvp tyncpldpo opgzetzy ez esle nlfdp qzc hstns espj rlgp esp
wlde qfww xpldfcp zq opgzetzy esle hp spcp strswj cpdzwgp esle espdp oplo dslww
yze slgp otpo ty glty esle estd yletzy, fyopc Rzo, dslww slgp l yph mtces zq
qcppozx lyo esle rzgpcyxpye zq esp apzawp, mj esp apzawp, qzc esp apzawp, dslww
yze apctds qczx esp plces"
• Frequencies obtained from the above ciphertext: {'p': 165, 'e': 126, 'l': 102, 'z': 93, 's': 80, 'c': 79, 'y': 77, 't': 68, 'o':
58, 'd': 44, 'w': 42, 'n': 31, 'h': 28, 'q': 27, 'r': 27, 'g': 24, 'f': 21, 'a': 15, 'm': 14, 'x': 13, 'j': 10, 'v': 3, 'b': 1, 'R': 1}
• Shift ‘p’ to ‘e’ mod 26 is: 15 => shift ‘q’ to ‘f’; shift ‘z’ to ‘o’; shift ‘f’ to ‘u’; shift ‘c’ to ‘r’, etc.
• cat letter.frequency.py |tail -4
Cryptanalysis Using Letter-Frequency
“qzfc dnzce lyo degey jelcd lrz zfc qltsecd mczfrst qzcts zy tstd
nzyttyeyt, l yeh ylttzy, nzynetgeo ty wtmectj, lyo oeotnlteo tz tse
aczazdtttzy tslt lww xey lce ncelteo ebflw. yzh he lce eyrlreo ty l
rcelt ntgtw hlc, tedttyr hsetsec tslt ylttzy, zc lyj ylttzy dz nzynetgeo
lyo dz oeotnlteo, nly wzyr eyofce. he lce xet zy l rcelt mlttwe-qtewo zq
tslt hlc. he slge nzxe tz oeotnlte l azcttzy zq tslt qtewo, ld l qtylw
cedttyr awlne qzc tszde hsz sece rlge tsetc wtged tslt tslt ylttzy xtrst
wtge. tt td lwtzretsec qttttyr lyo aczaec tslt he dszfwo oz tstd. mft,
ty l wlcrec deyde, he nly yzt oeotnlte he nly yzt nzydenclte he nly yzt
slwwzh tstd rczfyo. tse mclge xey, wtgtyr lyo oelo, hsz dtcfrrweo sece,
slge nzydenclteo tt, qlc lmzge zfc azzc azhec tz loo zc oetclnt. tse
hzcwo htww wtttwe yzte, yzc wzyr cexexmec hslt he dlj sece, mft tt nly
yegec qzcret hslt tsej oto sece. tt td qzc fd tse wtgtyr, cltsec, tz me
oeotnlteo sece tz tse fyqtytdseo hzcv hstns tsej hsz qzfrst sece slge
tsfd qlc dz yzmwj loglyneo. tt td cltsec qzc fd tz me sece oeotnlteo tz
tse rcelt tldv cexltytyr meqzce fd tslt qczx tsede szyzceo oelo he tlve
tynceldeo oegzttzy tz tslt nlfde qzc hstns tsej rlge tse wldt qfww
xeldfce zq oegzttzy tslt he sece strswj cedzwge tslt tsede oelo dslww
yzt slge oteo ty glty tslt tstd ylttzy, fyoec Rzo, dslww slge l yeh mtcts
zq qceeozx lyo tslt rzgecyxeyt zq tse aezawe, mj tse aezawe, qzc tse
aezawe, dslww yzt aectds qczx tse elcts”
• Frequencies obtained from the above ciphertext: {'p': 165, 'e': 126, 'l': 102, 'z': 93, 's': 80, 'c': 79, 'y': 77, 't': 68, 'o': 58,
'd': 44, 'w': 42, 'n': 31, 'h': 28, 'q': 27, 'r': 27, 'g': 24, 'f': 21, 'a': 15, 'm': 14, 'x': 13, 'j': 10, 'v': 3, 'b': 1, 'R': 1}
• Shift ‘p’ to ‘e’ mod 26 is: 15 => shift ‘q’ to ‘f’; shift ‘z’ to ‘o’; shift ‘f’ to ‘u’; shift ‘c’ to ‘r’, etc.
• python3 src.lecture/lecture.3/caesar/letter.frequency.py
Cryptanalysis Using Letter-Frequency
• Assume plaintext:
"Stately, plump Buck Mulligan came from the stairhead, bearing
a bowl of lather on which a mirror and a razor lay crossed. A
yellow dressinggown, ungirdled, was sustained gently behind him
on the mild morning air. He held the bowl aloft and intoned:
Introibo ad altare Dei. Halted, he peered down the dark
winding stairs and called out coarsely: —Come up, Kinch! Come
up, you fearful jesuit!"
• Visit http://rumkin.com/tools/cipher/caesar.php and paste text above and choose a
shift factor
• Paste ciphertext into src.lecture/lecture.3/caesar/tmp.py
• Note you need enough text (i.e., characters) to provide statistical significance
RANDOMNESS
“Anyone who considers arithmetical methods of producing random digits is, of
course, in a state of sin.”—John von Neumann
Bitmap generated with a language-
• Properties of randomness
• Which number is more random, A or B?
• A) 10010110
• B) 99999999
• E.g. src.lecture/lecture.3/random/ntr.py
• Why does randomness matter?
A State of Sin:
100
≈10 10
2256
Possible Outputs
Possible Inputs
• Example:
src.lecture/lecture.3/hashing$ python3 hash-256.py ‘a’
python3 -c
'print(bin(int("CA978112CA1BBDCAFAC231B39A23DC4DA786EFF8147C4E72B9807785AFEE48BB",16)))'
echo -n [copied binary output from above...ignoring ‘0b’ prefix] |wc -c
The Pigeonhole Principle
• Also known as Dirichlet’s drawer principle
• If we have 9 pigeonholes for pigeons and 10 pigeons, we will
necessarily have two pigeons in a single compartment
• Since the output of every hash function has a fixed-bit length,
say n bits, there are only 2n possible output values, while at the
same time the number of inputs to the hash function is infinite
• Since the possibility of collisions is ineluctable, the best we can do
is ensure that they cannot be found in practice, that is, easily...
• Thus, a strong hash function should be designed such that given x1 and h(x1), it is
impossible to discover some x2 (from the given) such that h(x1) = h(x2)
• Note that it is always possible that Mallory (a malicious active attacker) could “luck out”
and pick x2 out of “thin air” and yield h(x1) = h(x2), but we can make this
computationally infeasible by ensuring that our output length is at least 80 bits (flip our
coin 80+ times).
It gets worse...The Birthday Paradox
• How many people are needed at your birthday party such that there is about a 50%
chance that no one there has the same birthday as yours (Month and Day only)?
• Naïve answer is that it would take about 365/2 or 183 people before you hit a 50%
probability that someone shares your birthday...let’s see...
• The probability, given just me, that no one else shares my birthday is 100%,
since there is no one else to collide with my birthday
• If there’s just me and one other person, the probability of no collisions is:
P(no collisions) = (1 – 1/365) = .997
• If there’s just me and two other people, the probability of no collisions is:
P(no collisions) = (1 – 1/365) * (1 – 2/365) = .992
• So, given N people, how long does it take to get to a probability of < 50% that
no one else shares my birthday?
P(no collisions) = (1 – 1/365) * (1 – 2/365) * (1 – 3/365) * (1 – N/365)
It gets worse...The Birthday Paradox
• How many people are needed at your birthday party such that there is about a 50%
chance that no one there has the same birthday as yours (Month and Day only)?
• Naïve answer is that it would take about 365/2 or 183 people to hit a 50% Probabilty # People:
100.0% 1
probability...let’s see... 99.7%
99.2%
2
3
• The probability, given just me, that no one else shares my birthday is 100%, 98.4%
97.3%
4
5
since there is no one else to collide with my birthday 96.0%
94.4%
6
7
• If there’s just me and one other person, the probability of no collisions is: 92.6%
90.5%
8
9
P(no collisions) = (1 – 1/365) = .997 88.3%
85.9%
10
11
• If there’s just me and two other people, the probability of no collisions is: 83.3%
80.6%
12
13
1 2
P(no collisions) = (1 – /365) * (1 – /365) = .992 77.7% 14
76.0% 15
• So, given N people, how long does it take to get to a probability of < 50% that 71.6%
68.5%
16
17
no one else shares my birthday? 65.3%
62.1%
18
19
P(no collisions) = (1 – 1/365) * (1 – 2/365) * (1 – 3/365) * (1 – N/365) 58.9% 20
55.6% 21
52.4% 22
49.3% 23
Finding Collisions
• Turns out that the unfortunate consequence of the birthday paradox is that the number
of messages we need to hash in order to find a collision is roughly equal to the square
root of the number of possible output values, or about 2! = 2!/# instead of 2! as one
might expect
• After a little Taylor Series hocus pocus, we can compute that we would have to hash 𝑡
n-bit hash input values to find a collision, where lambda is the probability of a collision:
"#$ ⁄%
1
𝑡 ≈2 ln
1−𝜆
• For example, assume we want to find a collision for a hypothetical hash function H()
which produces 80 bits of output. For a collision probability (𝜆) of approximately 50%,
&'#$ ⁄% $
we would expect to have to hash about 𝑡 ≈ 2 ln ≈ 2+'., ≈
$('.*
{Given P1} P1
P
X X
{Find P2}
H P2
H
on
e-
w
ay
Padding
Block Block Block
(512 bits) (512 bits) (N bits)
M1, M2, M3, etc. are advancing pieces of the original message being hashed
H0 is the Initialization Vector (IV) of the internal state; Hn etc. are chaining values representing the advancing state of the hash
The Workhorse: SHA-256
• SHA-256 uses the M-D compression function and repeatedly takes 768-bit input and
produces 256-bit output.
• echo -n "0012ab8dc588ca9d5787dde7eb29569da63c3a238c" | openssl sha256
Effectively,
a digital
fingerprint
0a96742670166ddf3a9cd6
c88c11ea24ea2c0f6920d3
f99049f53c89c67c9eea
256 bits
32 bytes,
Every time
1,553,444 bytes
Message Digests
• A cryptographic hash function is one type of hash function that uses
an algorithm that maps data of varying size to a bit-string of a fixed size (the hash)
• Given our properties of collision resistance hash functions:
• If H(x) = H(y), we may assume x = y, and this allows us to use hash functions as a
message digest
• Remember hash functions do not encrypt the data (i.e., you cannot “decrypt” the hashed
message digest back to the original)
• The input data is commonly called the message, and the output (the hash value or simply
the “hash”) is often called the message digest or simply the digest
• If two messages have the same resulting digest, depending on our properties of hash
functions, we can be confident that the two original messages are identical.
Message Digests
• Message digests have proven effective in a variety of contexts:
• Password storage (cf. crypt in UNIX systems which leverage MD5, Blowfish, SHA-256,
etc. and Microsoft’s pathetic LANMAN)
• Proof of file integrity (MD5) for network data transfers
• Data Integrity: Revision control systems such as Git, Mercurial, etc. use message
digests not for security but to identify revisions and to ensure that the data has not
changed due to accidental corruption
• Bitcoin
The Workhorse: SHA-256
• Use the live dynamic sha256 at: https://passwordsgenerator.net/sha256-hash-
generator/
• Enter the text: Hello MPCS 56600 Peeps!
• See the hashed result:
1DD635FF84BDED73C744DC9CF1915D9C013E32302598FF75A7BA0B9CF00C0674
• $ echo -n 'Hello MPCS 56600 Peeps!' | openssl dgst -sha256
(stdin)= 1dd635ff84bded73c744dc9cf1915d9c013e32302598ff75a7ba0b9cf00c0674
• You can find examples of SHA-256 functions in multiple languages in my pub directory
located here: ~mark/pub/56600/src.lecture/lecture.3/sha256/examples/*
CLASSIFICATION OF CIPHERS
Encryption and Decryption using Stream and Block ciphers
Basic (Relevant) Cryptographic Vocabulary
• Types of Ciphers:
• Stream Ciphers (work on individual bits discretely and individually)
• Classical ciphers
xi , yi , si ∈ { 0, 1 }
Encryption: yi = esi(si ) ≡ xi + si mod 2
Decryption: xi = dsi(yi ) ≡ yi + si mod 2
• Block Ciphers (we’ll get to these...)
• Modern Ciphers
• Symmetric Encryption
• Asymmetric Encryption
Symmetric Ciphers
• In symmetric ciphers, there is a single key that is used to both encrypt and decrypt
• The plaintext is encrypted using a key, and the ciphertext is decrypted using the very
same key
• Needless to say, the key needs to be kept hidden, which is why symmetric ciphers are
sometimes called secret key ciphers
• Examples of modern symmetric ciphers include DES, 3DES, International Data
Encryption Algorithm (IDEA), and the Advanced Encryption Standard (AES)
STREAM CIPHERS
Stream Ciphers
• Most stream ciphers are word-based or character-based, and the
encryption occurs “word by word” or “character by character”
• Both the One-Time Pad and the Vigenère cipher are examples of
stream ciphers
• The most (in)famous example of a stream cipher was the electro-
mechanical stream cipher Enigma Machine
Turing’s Hut 8
The Enigma Machine
• Rotor orientation: Each of the three rotors could be set in one of 26
orientations, therefore 263 (17,576) settings...
• Rotor arrangements: Each of the three scramblers could be positioned in
any of size orders: 3! = 6
• Plugboard: The number of ways of connecting (swapping) any six pairs of
letters out of 26: 100,391,791,500 different combinations (26! / 14! / 6! /
26!)
• The total number of possible keys is the product of these three numbers:
• 17,576 x 6 x 100,391,791,500 = 10,586,916,764,424,000....over ten
quadrillion...a lot.
Alan Turing’s
Alan Turing
17th cousin
Turing’s Bombe Machine
• Alan Turing designed a machine that would decrypt an Enigma-
encrypted message, with one caveat...
• A crib (hint) was needed to reduce the combinations to something
manageable
Modern Stream Ciphers
• Modern stream ciphers are bit-based in that they encipher bit-by-bit
• Stream ciphers take plaintext and apply a keystream sequence to it
• As a simplistic example, let’s imagine a rule statement such that “if there is a 1 in
keystream[x], then change the bit in plaintext[x]. If there is a 0 in the keystream[x], then leave
plaintext[x] unchanged.”
• Let plaintext = 1100101 and keystream = 1000110
• Plaintext[0] is a 1 and keystream[0] is a 1. 1 means change it. Plaintext[0] becomes a 0.
• Plaintext[1] is a 1 and keystream[1] is a 0. 0 means no change. Plaintext[1] remains a 1, etc.
• The resulting ciphertext becomes: 0100011
• Note our rule statement above is essentially the XOR operation, thus we have:
• Where, C = Ciphertext, P = Plaintext, and K = Key:
• Ci = Pi ⨁ Ki
• Pi = Ci ⨁ Ki
251959084756578934940271832400483985714292821262040320277771378360436
620207759555626401852588078440691829064124951508218929855914917618450
280848912007284499268739280728777673597141834727026189637501497182469
116507761337985909570009733045974880842840179742910064245869181719511
874612151517265463228221686998754918242243363725908514186546204357679
842338718477444792073993423658482382428119816381501067481045166037730
605620161967625613384414360383390441495263443219011465754445417842402
092461651572335077870774981712577246796292638635637328991215483143816
7899885040445364023527381951378636564391212010397122822120720357