SlideShare a Scribd company logo
Hill Cipher
Please email your Mathematica file to tleise@amherst.edu by 4pm on Monday.
Prime numbers play important roles in various encryption schemes. Hill ciphers are quite
simple, while other methods are much more sophisticated, like RSA public key
encryption that involves two very large prime numbers and is used for internet security.
To design a Hill cipher, we first assign a number to each letter of the alphabet, then add
three punctuation marks so that we have a prime number (29) of coded letters.
A B C D E F G H I J K L M N O
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
P Q R S T U V W X Y Z , . ?
16 17 18 19 20 21 22 23 24 25 26 27 28 0
The original message will be translated to a string of numbers, which will be partitioned
into groups of 3 letters and formed into a matrix P (each group of 3 comprising a
column). The matrix P is then multiplied by an invertible encryption matrix M (we want
to be able to get the message back!) and the resulting numbers translated back into letters
to create a coded message of apparent gibberish.
The extra bit of complication is that we want all numbers to be between 0 and 28, so we
must use the “mod p” (modulus) operator, which takes a number and repeatedly adds or
subtracts p until we have a number between 0 and p-1. In our case, we will use p=29.
For example, 25 mod 29 = 25, 30 mod 29=1, 183 mod 29 = 9 and -1 mod 29 = 28.
Exercise 1. Mod[n,p] calculates n mod p. Use Mathematica to find 201 mod 29.
Now we are ready to try out a Hill code. Suppose we want to encode “hide this message”
using the encryption matrix
!
M =
2 7 6
4 5 13
2 6 1
"
#
$
$
%
&
'
'
.
M = {{2,7,6},{4,5,13},{2,6,1}};
Step 1: Remove spaces from the message to be encoded and break it up into groups of 3
letters (add extra letters to end if necessary): HID ETH ISM ESS AGE
Step 2: Replace letters with their assigned numbers 0-28 and write each group as a
column of a matrix P, which we will call the “plaintext matrix.”
P = Transpose[{{8, 9, 4}, {5, 20, 8}, {9, 19, 13}, {5, 19,
19}, {1, 7, 5}}]; (* to turn rows into columns *)
Step 3: Calculate MP mod 29. We will call the resulting matrix the “code matrix” A.
A = Mod[M.P,29]
Step 4: Replace the numbers with letters to obtain the coded message.
PMPXUVZJ?YN,WQT
Step 5: The recipient of this coded message would return it to the matrix form and then
solve M.P=A (the solution is P= M-1
A). We must be careful in finding the inverse of the
matrix M, since we are working “mod 29” (this is called matrix algebra over the finite field
Z29). We use a handy theorem from number theory that lets us find the inverse of the
matrix M when working over a finite field Zp: M-1
=(detM)p-1
times the usual inverse of M.
Minverse=Mod[Det[M]^28 Inverse[M], 29]
Exercise 2. Create a message that is at least 24 letters long. For example, “HOORAY,
SPRING IS FINALLY HERE.” If the length of your message isn’t a multiple of three,
pad with extra punctuation marks. Translate into a plaintext matrix P.
Exercise 3. Make up a new 3x3 encryption matrix M. M should be invertible (that is, it
should have determinant not equal to 0 or any multiple of 29 since we are working
modulus 29) and contain only integers between 0 and 28.
Exercise 4. Compute the code matrix A and translate to the coded message.
Exercise 5. Use the code matrix A and the encryption matrix M to get back the original
plaintext matrix P (as in step 5).
Exercise 6. Suppose Naval Intelligence intercepts the following coded message and
believes it was encrypted using a Hill code. They think the first three words of the
message are “I THINK OUR”. Find the encryption matrix and decode the rest of the
message.
Coded message: QUAS.AGFOUFCEDCLKSGPE

More Related Content

PPT
Algebra 1 unit 1.1
PPTX
M1 l3
PPTX
Module 5. bsm
PPT
Moving Straight Ahead 2.3
PDF
Arrays in Visual Basic Programming
PPTX
Closure properties of numbers
PPTX
Str8ts Weekly Extreme #38 - Solution
PPTX
data structure and algorithms Unit 5
Algebra 1 unit 1.1
M1 l3
Module 5. bsm
Moving Straight Ahead 2.3
Arrays in Visual Basic Programming
Closure properties of numbers
Str8ts Weekly Extreme #38 - Solution
data structure and algorithms Unit 5

What's hot (20)

DOCX
G6 m4-d-lesson 9-t
PPTX
Computation theory Assignment Help
PPTX
002#pedagogy math test
PPT
Pre Algebra chapter 1 notes
PPTX
Arithmetic mean
PPTX
L10 binomial theorem
PDF
8th alg -l3.1
PPTX
Finding Point-Slope Equations
PDF
Day 1 examples u3f13
PDF
Day 1 examples u5w14
PDF
New day 1 examples
PPT
Chapter 4 Review Part 1
PPT
Chapter 3 part1
PPTX
Pythagorean Theorem And Distance Formula
PPT
Calc 5.1a
PPT
Square roots
PPTX
March 12, 2015
PPT
3.1 b solving systems graphically
PPT
02 11 Easter Sunday
PDF
7th pre alg -l29
G6 m4-d-lesson 9-t
Computation theory Assignment Help
002#pedagogy math test
Pre Algebra chapter 1 notes
Arithmetic mean
L10 binomial theorem
8th alg -l3.1
Finding Point-Slope Equations
Day 1 examples u3f13
Day 1 examples u5w14
New day 1 examples
Chapter 4 Review Part 1
Chapter 3 part1
Pythagorean Theorem And Distance Formula
Calc 5.1a
Square roots
March 12, 2015
3.1 b solving systems graphically
02 11 Easter Sunday
7th pre alg -l29
Ad

Similar to Hill code (20)

PPTX
Proficient Computer Network Assignment Help
PPT
Chapter 30
PPT
Chapter 30 - Cry
PPTX
PPTX
hill cipher.pptx jdfnjkfbkjbwjkrrrrwkfkj
PDF
27-Equivalent under modulo-27-Oct-2020Material_I_27-Oct-2020_Cryptography_.pdf
PPT
ch30.ppt
PPT
ch30.ppt
PDF
OTP basic
PPT
Lecture11
ODP
DOCX
Senior Research Final Draft3
PDF
How to invent a new cryptosystem.pdf
PPT
30 Cryptography
PDF
G0423538
ODP
PDF
Public Key Cryptography
PPTX
Cyber Security Part-3.pptx
PPT
Cryptography and its uses in daily life presentation
PPTX
Dynamic programming1
Proficient Computer Network Assignment Help
Chapter 30
Chapter 30 - Cry
hill cipher.pptx jdfnjkfbkjbwjkrrrrwkfkj
27-Equivalent under modulo-27-Oct-2020Material_I_27-Oct-2020_Cryptography_.pdf
ch30.ppt
ch30.ppt
OTP basic
Lecture11
Senior Research Final Draft3
How to invent a new cryptosystem.pdf
30 Cryptography
G0423538
Public Key Cryptography
Cyber Security Part-3.pptx
Cryptography and its uses in daily life presentation
Dynamic programming1
Ad

Recently uploaded (20)

PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
RMMM.pdf make it easy to upload and study
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Trump Administration's workforce development strategy
PDF
Hazard Identification & Risk Assessment .pdf
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
Empowerment Technology for Senior High School Guide
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
Weekly quiz Compilation Jan -July 25.pdf
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Final Presentation General Medicine 03-08-2024.pptx
RMMM.pdf make it easy to upload and study
Paper A Mock Exam 9_ Attempt review.pdf.
Trump Administration's workforce development strategy
Hazard Identification & Risk Assessment .pdf
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Empowerment Technology for Senior High School Guide
LDMMIA Reiki Yoga Finals Review Spring Summer
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
History, Philosophy and sociology of education (1).pptx
A powerpoint presentation on the Revised K-10 Science Shaping Paper
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Unit 4 Skeletal System.ppt.pptxopresentatiom
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Weekly quiz Compilation Jan -July 25.pdf

Hill code

  • 1. Hill Cipher Please email your Mathematica file to tleise@amherst.edu by 4pm on Monday. Prime numbers play important roles in various encryption schemes. Hill ciphers are quite simple, while other methods are much more sophisticated, like RSA public key encryption that involves two very large prime numbers and is used for internet security. To design a Hill cipher, we first assign a number to each letter of the alphabet, then add three punctuation marks so that we have a prime number (29) of coded letters. A B C D E F G H I J K L M N O 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 P Q R S T U V W X Y Z , . ? 16 17 18 19 20 21 22 23 24 25 26 27 28 0 The original message will be translated to a string of numbers, which will be partitioned into groups of 3 letters and formed into a matrix P (each group of 3 comprising a column). The matrix P is then multiplied by an invertible encryption matrix M (we want to be able to get the message back!) and the resulting numbers translated back into letters to create a coded message of apparent gibberish. The extra bit of complication is that we want all numbers to be between 0 and 28, so we must use the “mod p” (modulus) operator, which takes a number and repeatedly adds or subtracts p until we have a number between 0 and p-1. In our case, we will use p=29. For example, 25 mod 29 = 25, 30 mod 29=1, 183 mod 29 = 9 and -1 mod 29 = 28. Exercise 1. Mod[n,p] calculates n mod p. Use Mathematica to find 201 mod 29. Now we are ready to try out a Hill code. Suppose we want to encode “hide this message” using the encryption matrix ! M = 2 7 6 4 5 13 2 6 1 " # $ $ % & ' ' . M = {{2,7,6},{4,5,13},{2,6,1}}; Step 1: Remove spaces from the message to be encoded and break it up into groups of 3 letters (add extra letters to end if necessary): HID ETH ISM ESS AGE Step 2: Replace letters with their assigned numbers 0-28 and write each group as a column of a matrix P, which we will call the “plaintext matrix.” P = Transpose[{{8, 9, 4}, {5, 20, 8}, {9, 19, 13}, {5, 19, 19}, {1, 7, 5}}]; (* to turn rows into columns *)
  • 2. Step 3: Calculate MP mod 29. We will call the resulting matrix the “code matrix” A. A = Mod[M.P,29] Step 4: Replace the numbers with letters to obtain the coded message. PMPXUVZJ?YN,WQT Step 5: The recipient of this coded message would return it to the matrix form and then solve M.P=A (the solution is P= M-1 A). We must be careful in finding the inverse of the matrix M, since we are working “mod 29” (this is called matrix algebra over the finite field Z29). We use a handy theorem from number theory that lets us find the inverse of the matrix M when working over a finite field Zp: M-1 =(detM)p-1 times the usual inverse of M. Minverse=Mod[Det[M]^28 Inverse[M], 29] Exercise 2. Create a message that is at least 24 letters long. For example, “HOORAY, SPRING IS FINALLY HERE.” If the length of your message isn’t a multiple of three, pad with extra punctuation marks. Translate into a plaintext matrix P. Exercise 3. Make up a new 3x3 encryption matrix M. M should be invertible (that is, it should have determinant not equal to 0 or any multiple of 29 since we are working modulus 29) and contain only integers between 0 and 28. Exercise 4. Compute the code matrix A and translate to the coded message. Exercise 5. Use the code matrix A and the encryption matrix M to get back the original plaintext matrix P (as in step 5). Exercise 6. Suppose Naval Intelligence intercepts the following coded message and believes it was encrypted using a Hill code. They think the first three words of the message are “I THINK OUR”. Find the encryption matrix and decode the rest of the message. Coded message: QUAS.AGFOUFCEDCLKSGPE