Question
Pythton : Here we will break a Hill cipher with block size 2 using frequency analysis. First lets see how to work with matrices mod
Pythton : Here we will break a Hill cipher with block size 2 using frequency analysis.
First lets see how to work with matrices mod 26
We can define a Matrix M modulo 26 as follows.
R = IntegerModRing(26) M = Matrix(R,[[3,1],[2,3]])
Now we could find the inverse of M:
M^(-1)
Now define the Hill Cryptosystem
system=HillCryptosystem(AlphabeticStrings(),2) R=IntegerModRing(26) alphabet=AlphabeticStrings()
We can encrypty a message using M:
plaintext=alphabet.encoding("HILLCIPHERSARECOOL") ciphertext=system.enciphering(M,plaintext) ciphertext
%md ## And decrypt it:
And decrypt it:
system.enciphering(M^(-1),ciphertext)
Question:
#1. We intercept the message below, saved to CT:
CT=AlphabeticStrings().encoding("BZKIKNZIXUUKGKEQZAUVSQHMEPMAHMEPDKZWIFQDJMNAFNVGBISRIVFCBZSIMAVOOSKUGKBIVGJMZGEXNOKSYRGCCKMDJIBZOVUKFNEXYNZIXAMUANABOIRQIXQABIZAUVKQVBABLAIEBVEQANLACYYKFOEMISWNGDYMFNDSCVANRMBWANACDZCVSQPMSNWWRMREANXKBMBIGDAFSQNBQIBWZMEATEPIMIRQFTMWICBZWOANQKUKSRCOTJSWQKMYFWJMXTQIBWZMIETJIVBZKIKNZINUBIKNIVFCSKXNEQXNWYYRGDUIRMKKJPAOBZGVWOANBELEFWHMEPAFUDAVNOEDXCVGUINOKNANXGDWSRZIIEFWSRCDQDSWBIGOIVEAANQVOVMMAKABGEOEILMBOVTROCDIQYOVLASPQIDVEXLOEXTIBZANVGMXDIKFGDRMYNWVEVBWEPKAWARAVZNOWYYRGDUIAFSQLOJNSPRQAKBZOVTEQPDWAFUPWNWVOIRNBIIVFXYCBZIVBIUAQSRVJTNOWYJZODKQOHGCRNCPBELEFWZIFYXAWNKQCODWLXCITMTAKFEAHCTJAVHMUYGDAFSQZBNONOQQZBQVIVTEPICVHMEPIPGENVWAZAPODISROVQKSXCVBISKXNIVFCONLWGSXABZQISRMQPAQDLONAKXO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OPOZTKVJYFILODWJZGDQDUWLOGXOVEXEPWIBZKNBZWIDIWRAVSPPTOVBZKNKXSIUCXJHKTJGDLWRQGSBZBZWILAANJTPOLZWIIENNOPPCXGSNPCIEGOUINOLWRQKXAQKXYIKQSKUXWIANPTOVMVCDUIBZKQHMUYGSBZBZCVGCOVRMTEPIMIRQANLGEPJZSPBZKIKNZIRHOILXCPZZUIIXKJUVQIPMOKQDPOFNDWWNUIBZKIKNZIXUXNAQUVCPBZUILOZEEVCIJZYCKALAHMURQBSKISMNEPRMVGUKFPAVNOKNLMQEGDCMQVHMLAJWAKUYHMUYFWJMDVWIWYMUUKJMDWLREPCIONBWXNNOWYJZODTRYCKQGDIZNOWYYRGDUIBZKNNOGSTJKXGCBZMIPVZIAKLAHICACPXJAFOVQIBABZGDUMGXICQKFPGVGVANCMOBANDTBWUIGDRMBZUICU")
#2. We now define a function that counts how often pairs of letters occur in a message:
For example:string=alphabet.encoding("COCONUTS") countBigrams(string)
CO : 2 TS : 1 NU : 1
Problem: Use this and the frequency of digrams (pairs of English letters) here: https://en.wikipedia.org/wiki/Bigram#Bigram_frequency_in_the_English_language to decrypt the message.
(Make guesses as to what you think pairs of letters encrypt to, and then find the encryption matrix the same way as the known plaintext attack
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started