Is the Caesar Cipher

advertisement
An Introduction to Cryptology
Cryptology
• Is defined as the science of making
communication incomprehensible to all
people except those who have a right to read
it and understand it.
Two parts of Cryptology
1. Cryptography – which concerns itself with
the secrecy system itself and its design.
2. Cryptanalysis – which concerns itself with the
breaking of the secrecy system above.
History
• Cryptography mainly started out for military,
secret agents, and war.
• Computer communications via Internet,
wireless and mobile devices.
Terms
• Code- a set of information that will allow
words to be changed to other s or symbols
• Plaintext – the message that you wish to put
into secret form. Plaintext is usually written in
all lowercase letters without spaces.
Example: “I will meet you at 5 PM in the mall”
Plaintext: “iwillmeetyouatfivepminthemall”
• Cipher – the method for altering the plaintext
Terms
• Ciphertext – the secret version of the
plaintext.
• Encipher – changing from plaintext to
ciphertext.
• Decipher – changing from ciphertext to
plaintext
• Key – information that will allow someone to
encipher the plaintext and also decipher the
ciphertext.
Monoalphabetic Substitution Ciphers
• Every character in the plaintext message is
replaced with a unique alternative character
in the ciphertext message. Aka cryptogram
The Additive (Shift) Cipher System
• Where each letter in the plaintext is replaced
by a certain letter whose position is the same
value away from each letter. Also known as a
shift
Caesar Ciphers
Cryptography
• Cryptography is the study and practice of
hiding information. Caesar’s cipher is just one
way to encrypt and decrypt information. It is
too weak for real-world applications.
• There are many methods of cryptography that
are much more foolproof than Caesar’s
Cipher!
• Caesar is a Monoalphabetic Substitution
Cipher also known as an Additive Cipher or
Shift Cipher
Cryptography
“art or science concerning the principles, means and methods for rendering
plain information unintelligible and for restoring encrypted information to
intelligible form.” -- National Information System Security Glossary (NSTISSC)
plaintext
plaintext
ciphertext
ZXYCTHI
MESSAGE
MESSAGE
encode/encipher
algorithm
decode/decipher
algorithm
Basic Terminology
•
•
•
•
•
•
•
•
plaintext - the original message
ciphertext - the coded message
cipher - algorithm for transforming plaintext to ciphertext
key - info used in cipher known only to sender/receiver
encipher (encrypt) - converting plaintext to ciphertext
decipher (decrypt) - recovering ciphertext from plaintext
cryptography - study of encryption principles/methods
cryptanalysis (codebreaking) - the study of principles/
methods of deciphering ciphertext without knowing key
• cryptology - the field of both cryptography and cryptanalysis
Caesar Cipher
•
•
•
•
•
earliest known substitution cipher
by Julius Caesar
first attested use in military affairs
replaces each letter by 3rd letter later
example:
meet me after the toga party
PHHW PH DIWHU WKH WRJD SDUWB
Caesar Wheel
Caesar Cipher
• can define transformation as:
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
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 C
• mathematically give each letter a number
a b c
0 1 2
n o
13 14
d e f
3 4 5
p q
15 16
g h i
6 7 8
r s
17 18
j k l m
9 10 11 12
t u v w x y Z
19 20 21 22 23 24 25
• then have Caesar cipher as:
C = E(p) = (p + k) mod (26)
p = D(C) = (C – k) mod (26)
Cryptanalysis of Caesar Cipher
• only have 26 possible ciphers
– A maps to A,B,..Z
•
•
•
•
•
could simply try each in turn
a brute force search
given ciphertext, just try all shifts of letters
do need to recognize when have plaintext
eg. break ciphertext “ERE L ORYH BRX DOLFH"
Symmetric Encryption
• or conventional / secret-key / single-key
• sender and recipient share a common key
• all classical encryption algorithms are privatekey
• was only type prior to invention of public-key
in 1970’s
The language of cryptography
Alice’s
K encryption
A
key
plaintext
encryption
algorithm
ciphertext
Bob’s
K decryption
B key
decryption plaintext
algorithm
symmetric key crypto: sender, receiver keys identical
public-key crypto: encryption key public, decryption key secret
(private)
Symmetric Encryption
plaintext
plaintext
ciphertext
encryption algorithm
decryption algorithm
Asymmetric
Encryption
plaintext
plaintext
ciphertext
encryption algorithm
decryption algorithm
What is a Caesar Cipher?
• Caesar used to encrypt his messages using a very simple
algorithm, which could be easily decrypted if you know the key.
• He would take each letter of the alphabet and replace it with a
letter a certain distance away from that letter. When he got to
the end, he would wrap back around to the beginning.
• Example with a shift of 3:
I’m so
sneaky!
A B C D E F G H I J K L MN O P Q R S T U VWX Y Z
D E F G H I J K L MN O P Q R S T U VWX Y Z A B C
The Problem with Caesar’s Cipher
• It’s too easy to break! Let’s go back to our five letter alphabet.
• Say you had the word DBCA, but didn’t know the key. It would be easy to
make a list of all possible keys. If you expected the unencrypted text to be
in English, you could easily figure out which word was right:
Shift of 1
CABE
Shift of 2
BEAD  The clear winner!
Shift of 3
ADEC
Shift of 4
ECDB
• If you were using the full English alphabet, this would take longer, but for
someone trying to find our your secret, it’s a small price to pay!
How dare you
insult my cipher!
Though, you have
a good point…
How Would You Program This?
• It’s unbelievably simple!
• The mod function is one of the most basic
components of a lot of programming
languages. You’ll learn the mod function for
python early on. That means all we have to
deal with is indexing the letters.
• Believe it or not, this also is no problem. The
solution lies in ASCII.
Wait, What’s ASCII?
• Computers have to represent
everything as numbers,
Numbers
including things as basic as
associated
text.
with letters?
This sounds • ASCII is the standard character
encoding scheme, where each
strangely
symbol is assigned a number.
familiar…
• These symbols range from
upper and lower case letters
to numbers to things like
punctuation and arrows.
There are many tables online
that allow you to look up the
number associated with each
symbol.
The ASCII Table
Using ASCII for Caesar’s Cipher
• You probably noticed that the letter A is associated
with the number 65, B with 66, C with 67, and so on.
• Most programming languages have a function that
can take a letter and find out it’s ASCII value.
• What would you need to do to make the ASCII
encoded letters usable for Caesar’s Cipher?
– Subtract 65 from each letter!
• Since it’s really simple to code for a computer to use
mod and assign the correct index for each letter, you
can probably see how programming a simple
encoder/decoder would be a cinch!
But I Don’t Want to Make a Table!
• That’s fine! If you know what the shift is, you can
use something called modulo, which is commonly
shortened to mod.
• Let’s say we wanted to find 8 mod 5. We would
divide 8 by 5 and find the remainder. So in this
case, 8 mod 5 = 3.
• In this case, 5 is called the modulus.
• Can you solve these?
19 mod 5
2 mod 5
25 mod 5
4
2
0
How Is That Helpful?
• When using a Caesar cipher, you assign each letter to an index
starting from 0.
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
0
9
1
2
3
4
5
6
7
8
10
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
2
0
2
1
2
2
2
3
2
4
• You would then compute the following.
(plain letter index + key) mod (total number of letters)
• This will give you the index of the encrypted letter!
• As you can see, the modulus is the total number of letters in
the alphabet. For English, this modulus is 26.
2
5
A Simple Example
• Let’s say we have a 5 letter alphabet with only the letters A-E
• First, we assign each letter an index, starting from 0.
A
B
C
D
E
0
1
2
3
4
• We then have to choose a key. For this example, we’ll use 2.
• Let’s try encoding the word BEAD using the formula for the previous slide.
• The index of the letter B is 1. The key is 2. The modulus is 5, since the
alphabet is 5 letters.
• Let’s use the algorithm: (1+2) = 3. 3 mod 5 = 3. The index of D is 3, so B
would become the letter D.
• Using algorithm on each letter, can you encode the full word?
DBCA
Why Does Mod-ing Work?
• The mod accounts for wrapping back around once you reach
the end of the alphabet.
A
B
C
D
E
0
1
2
3
4
• When converting the letter E using the key 2, you first add 4 +
2, which gives you 6. As you can see, the index 6 is beyond
the scope of this alphabet. When you do 6 mod 5, you get the
remainder of 1, which is how much you need to go back and
count from the beginning of the alphabet.
Caesar Cipher
• can define transformation as:
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
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 C
• mathematically give each letter a number
a b c
0 1 2
n o
13 14
d e f
3 4 5
p q
15 16
g h i
6 7 8
r s
17 18
j k l m
9 10 11 12
t u v w x y Z
19 20 21 22 23 24 25
• then have Caesar cipher as:
C = E(p) = (p + k) mod (26)
p = D(C) = (C – k) mod (26)
Simple Caesar Cipher
E(Lp) = (Lp + 3) mod 26
Generalized Caesar Cipher
ECaesar(Lp, k) = (Lp + k) mod 26
Key
“a sequence of random or pseudorandom bits used initially to set up and periodically
change the operations performed in crypto-equipment for the purpose of encrypting
or decrypting electronic signals...” -- National Information System Security Glossary (NSTISSC)
Is the Caesar Cipher (keyed version) symmetric or asymmetric?
rot13(Lp) = ECaesar(Lp, 13)
Note that rot13 = rot13-1 (i.e. rot13 decodes any message encoded with rot13)
In general, what is DCaesar(Ln, k) in terms of ECaesar(Ln, k) ?
Encode
ECaesar(Lp, k) = (Lp + k) mod 26
Decode
DCaesar(Lc, k) =
Symmetric encryption is also known as key encryption,
because the key must be kept private from…
code breaker
A historical example of substitution cipher –
shift (or Caesar) cipher
ABCDEFGHIJKLMNOPQRSTUVWXYZ
• Choose k
• Shift all letters by k
• For example, if k = 5
• A becomes F, B becomes G, C becomes H, and so
on…
• What will replace X?
Modular arithmetic
• In the Caesar cipher, the following algorithm is used
• If n is the number of a letter in the alphabet, this letter is
replaced by another letter, whose number is
(n+k) modulo 26 (shortly (n+k) mod 26)
• This is a remainder of division of (n+k) by 26
• For example, take k=5 and take letter X
• Its number n = 24
• (n+k) mod 26 = 24 + 5 mod 26 = 3
• So X is replaced with C
Exercise
• Use shift cipher with k=7 to encrypt the text
“TOP SECRET” (ignore space)
• Answer:
– TVW ZLJYLA
Cryptanalysis
“operations performed in converting encrypted messages to
plain text without initial knowledge of the crypto-algorithm
and/or key employed in the encryption.”
-- National Information System Security Glossary (NSTISSC)
code breaker
Common Cryptanalysis Attacks
Attack Type
Cryptanalysis Knowledge
ciphertext only
• encryption algorithm (less the key)
• ciphertext to be deciphered
known plaintext
• encryption algorithm (less the key)
• ciphertext to be deciphered
• a segment of plaintext with corresponding
ciphertext
chosen plaintext
• encryption algorithm (less the key)
• ciphertext to be deciphered
• a segment of plaintext selected by cryptanalyst
with corresponding ciphertext
How difficult is cryptanalysis on a keyed Caesar cipher?
What About Decoding?
• To decode, you do the following:
(cipher letter index – key + total number of letters) mod (total number of letters)
• Does anyone know why we can’t just do:
(cipher letter index – key) mod (total number of letters)?
– By adding the total number of letters, you don’t have to
end up taking the mod of a negative number.
• See if you can decode DBCA to get back to the word BEAD.
Cryptanalysis of Caesar Cipher
• only have 26 possible ciphers
– A maps to A,B,..Z
•
•
•
•
•
could simply try each in turn
a brute force search
given ciphertext, just try all shifts of letters
do need to recognize when have plaintext
eg. break ciphertext "GCUA VQ DTGCM"
Download