Unit II
Unit II
3
Letter Frequencies
4
Letter Frequencies
5
N-gram Frequencies
• Digraph Frequency
– th he an in er on re ed nd ha at en es of nt ea ti to
io le is ou ar as de rt ve
• Trigraph Frequency
– the and tha ent ion tio for nde has nce tis oft men
6
Modular Arithmetic Cipher
• Use a more complex equation to calculate
the ciphertext letter for each plaintext letter
• E(a,b) : i ai + b mod 26
– Need gcd(a,26) = 1
– Otherwise, not reversible
– So, a2, 13, 26
– Caesar cipher: a=1, b=3
7
Block vs Stream Ciphers
• block ciphers process messages into
blocks, each of which is then en/decrypted
• like a substitution on very big characters
– 64-bits or more
• stream ciphers process messages a bit or
byte at a time when en/decrypting
• many current ciphers are block ciphers
• hence are focus of course
Modern Block Ciphers
• will now look at modern block ciphers
• one of the most widely used types of
cryptography algorithms
• provide strong secrecy and/or
authentication services
• in particular will introduce DES (Data
Encryption Standard)
Block Cipher Principles
• block ciphers look like an extremely large
substitution
• would need table of 264 entries for a 64-bit block
• arbitrary reversible substitution cipher for a large
block size is not practical
– 64-bit general substitution block cipher, key size 264!
• most symmetric block ciphers are based on a
Feistel Cipher Structure
• needed since must be able to decrypt ciphertext
to recover messages efficiently
Block Ciphers
• The message is broken into blocks,
– Each of which is then encrypted
– (Like a substitution on very big characters -
64-bits or more)
11
Substitution and Permutation
• In his 1949 paper Shannon also
introduced the idea of substitution-
permutation (S-P) networks, which now
form the basis of modern block ciphers
– An S-P network is the modern form of a
substitution-transposition product cipher
– S-P networks are based on the two primitive
cryptographic operations we have seen
before
12
Substitution
• A binary word is replaced by some other
binary word
• The whole substitution function forms the key
• If use n bit words,
– The key space is 2n!
• Can also think of this as a large lookup table,
with n address lines (hence 2n addresses),
each n bits wide being the output value
• Will call them s-boxes
13
Cont.
14
Permutation
• A binary word has its bits reordered
(permuted)
• The re-ordering forms the key
• If use n bit words,
– The key space is n! (Less secure than
substitution)
• This is equivalent to a wire-crossing in
practice
– (Though is much harder to do in software)
• Will call these p-boxes
15
Cont.
16
Substitution-permutation
Network
• Shannon combined these two primitives
• He called these mixing
transformations
• A special form of product ciphers where
– S-boxes
• Provide confusion of input bits
– P-boxes
• Provide diffusion across s-box inputs
17
C. Shannon and Substitution-
Permutation Ciphers
• in 1949 Shannon introduced idea of substitution-
permutation (S-P) networks
– modern substitution-transposition product cipher
• these form the basis of modern block ciphers
• S-P networks are based on the two primitive
cryptographic operations we have seen before:
– substitution (S-box)
– permutation (P-box) (transposition)
• provide confusion and diffusion of message
Diffusion and Confusion
• Introduced by Claude Shannon to thwart
cryptanalysis based on statistical analysis
– Assume the attacker has some knowledge of
the statistical characteristics of the plaintext
• cipher needs to completely obscure
statistical properties of original message
• a one-time pad does this
Diffusion and Confusion
Created by Horst Feistel et al. at IBM
One of the earliest block ciphers
“Father” of DES
Limited commercial usage with banking
software
About the Cipher
Block Cipher
Plaintext blocks of 128 bits
128 bit key
72 bit sub-keys
Ciphertext blocks of 128 bits
Feistel network
16 rounds per encryption
The Encryption Round
The Function
XOR block with sub-key
Block nibble swap
Based on bits of first sub-key byte
Send nibbles to s-boxes
Left nibble to box 1, right nibble to box
2
Bit permutation
Our Approach
Separate the cipher from the practical
program.
Have separate “helper classes”.
Permutation Class
KeyHandler Class
SboxClass
Keep readability high.
High modularity for easy testing and
optimization.
Allow output as a hex string.
Use Java - stick to what we know best!
Sample Encrypted
Texts
• INPUT • OUTPUT
• •
• test • be15cc3974c2f0ab55e38a881efafa
23
• sample input
• 09b20463d448c50de9fc6ad609787a
8d
Timed Results (Version 1)
• 1,000,000 round encryption:
40 8 48 16 56 24 64 32
39 7 47 15 55 23 63 31
38 6 46 14 54 22 62 30
37 5 45 13 53 21 61 29
36 4 44 12 52 20 60 28
35 3 43 11 51 19 59 27
34 2 42 10 50 18 58 26
33 1 41 9 49 17 57 25
40 8 48 16 56 24 64 32
39 7 47 15 55 23 63 31
38 6 46 14 54 22 62 30
37 5 45 13 53 21 61 29
36 4 44 12 52 20 60 28
35 3 43 11 51 19 59 27
34 2 42 10 50 18 58 26
33 1 41 9 49 17 57 25