Counting in GamblingWhat fraction of poker hands are “a pair of Jacks?” of Jacks... Counting in Cryptography# possible passwords # possible keys lec 10W.4 3/22/19... If there are 4 men
Trang 1First Principles
Trang 2Counting in Gambling
What fraction of poker hands
are “a pair of Jacks?”
of Jacks)
Trang 3# ops to update a data
structure (# comparisons needed to sort n
items)
# steps in a computation (#
multiplies to compute d n )
Counting in Algorithms
Trang 4Counting in Cryptography
# possible passwords
# possible keys
lec 10W.4 3/22/19
Trang 5Sum Rule
If sets A and B are disjoint , then
| A ∪ B | = | A | + | B |
Trang 6lec 10W.6
The Sum Rule
• Class has 17 women, 25 men so
total enrollment = 17 + 25 = 42
• 26 lower case letters, 26 upper case letters, and 10 digits, so # characters = 26+26+10 = 62
3/22/19
Trang 7If there are 4 men and 3
women, there are
4⋅3 = 12 different man/woman couples
The Product Rule
Trang 8Product Rule
If |A| = m and | B | = n , then
|A × B | = m⋅ n
A = { a, b, c, d }, B = { 1, 2, 3 }
A × B = {( a , 1 ),( a , 2 ),( a , 3 ),
( b , 1 ),( b ,2 ),( b , 3 ), ( c , 1 ),( c , 2 ),( c , 3 ), ( d , 1 ),( d , 2 ),( d , 3 ) }
Trang 9Product Rule: Counting Strings
# length- 4 binary strings
= |B × B × B × B|
= | B 4 | where B ::= { 0 , 1 }
= 2 · 2 · 2 · 2 = 2 4
Trang 10Product Rule: Counting Strings
# length n strings from an
alphabet of size m is
m n
Trang 11Example: Counting Passwords
• characters are digits & letters
• between 6 & 8 characters long
• starts with a letter
• case sensitive
Password conditions:
Trang 12L ::= {a,b,…,z,A,B,…,Z}
D ::= {0,1,……,9}
P n ::= length n words
starting w/letter
= L × (L ∪ D) n-1
Counting Passwords
Trang 13|L × (L ∪ D) n-1 |
= |L|·|(L ∪ D)| n-1
= |L|·(|L| + |D|) n-1
Counting Passwords
Trang 14Counting Passwords
set of passwords:
P ::= P 6 ∪ P 7 ∪P 8
|P| = |P 6 |+|P 7 |+|P 8 | = 52·(625+626+627) ≈ 19·1014
Trang 15cases by 1st occurrence of 7 :
x : any digit o : any digit ≠ 7
103
= 3439
# 4 -digit nums w/ ≥ one 7
+ 9·102 + 92·10 + 93
Trang 16at least one 7 : another way
| 4 -digit nums w/ ≥ one 7 |
= | 4 -digit nums|
− |those w/ no 7 |
= 104 − 94 = 3439
Trang 17Cracking Passwords by Exhaustive Search
• Suppose a password has to be a string of letters and digits beginning with a letter
• So there are 52∙62n-1 passwords of length n
• Suppose a computer can try a password every billionth of a second (one nanosecond per try)
• How big does n have to be for it to take more than a day to try them all?
Trang 18More than a day:
• 52∙62n-1 > number of nanoseconds in a day = 24∙60∙60∙109
• 62n-1 > 1.66∙1012
• n-1 > log (1.66∙1012)/log 62 ≈ 6.8
• So if passwords are at least 8 characters long it would take more than a day to try them all by exhaustive search
Trang 19FINIS