580 likes | 788 Views
Classical cryptography. plain text English -a contiguous stream of alphabetic characters Remove all non-alphabetic characters - comma , spaces, full stop, etc . a stream of small letters cipher text a stream of Capital letters Message: →
E N D
plain text English -a contiguous stream of alphabetic characters • Remove all non-alphabetic characters - comma, spaces, full stop, etc. • a stream of small letters • cipher text a stream of Capital letters • Message: → • A shy failure is nobler than an immodest success. • plaintext • ashyfailureisnoblerthananimmodestsuccess. • encrypted as → • BTIZGBJMVSFJTOPCMFSUIBOJNNPEFTUTVDDFTT. • insert punctuation marks with some amount of guess work
‘Shift cipher’ – also called ‘Caeser cipher’ • Possibly simplest of cryptosystems • Shift Cipher with a shift of 3 Note→x, y,&zin plain text replaced by A, B, & C in cipher text Plain text: turtlescantellmoreabouttheroadsthanhares Cipher text: WXUWOHVFDQWHOOPRUHDERXWWKHURDGVWKDQKDUHV
Decryption → reverse process – replace CT letter by one 3 positions before & form PT • overlapping circular discs → visualize encryption / decryption process • Maximum flexibility offered →25 Shifts → 25 keys • PT – inside • CT – Outside • Shift - : -3
Represent PT & CT characters with corresponding number sequences • a → 0, . . . . z → 25: Use modular algebra (mod 26) for encryption / decryption • PT sequence {x0, x1, x2,. . . xn-1,} • CT sequence {y0, y1, y2,. . . yn-1,} • xi , yi ℤ26 • shift cipher encryption → yi≡ (xi + k)(mod 26) • Decryption → zi≡ (yi - k)(mod 26) • K key • Note zi= xi for all i. • Two letters in CT → encrypt → two distinct letters in CT
cryptanalysis • break through the encryption-decryption process – what Eve does – cryptanalysis • Eve → Try all 25 shifts with CT a tame affair ! • CT: CSYWIINYWXXLIZMWMFPITEVXSJVIEPMXC • 18: ukqoaafqoppdareoexhalwnpkbnawhepu • 19: vlrpbbgrpqqebsfpfyibmxoqlcobxifqv • 20: wmsqcchsqrrfctgqgzjcnyprmdpcyjgrw • 21: xntrdditrssgduhrhakdozqsneqdzkhsx • 22: youseejustthevisiblepartofreality • 23: zpvtffkvtuuifwjtjcmfqbsupgsfbmjuz
Substitution Cipher • Encryption: - PT → Use LUT → CT • LUT 26 entries • Decryption: - CT → Use Inverse LUT → PT • shift also a substitution Cipher; • but shift representation more ‘elegent’
Values • Once a man unearthed in his field a marble statue of great beauty and he took it to a collector who loved all beautiful things and offered it to him for sale and the collector bought it for a large price and they parted. And as the man walked home with his money he thought and he said to himself ‘How much life this money means! how can anyone give all this for a dead carved stone buried and undreamed of in the earth for a thousand years!’. And now the collector was looking at his statue and he was thinking and he said to himself ‘What beauty! What life! The dream of what a soul and fresh with the sweet sleep of a thousand years! How can anyone give all this for money dead and dreamless? • The Forerunner (Kahlil Gibran)
Cryptanalysis – substiution cipher • brute force search as in shift cipher • try 26 substitutions for ‘a’; 25 for ‘b’- 26 25 for two together • wadethrough 26! Choices! • Use statistical properties of English texts • frequencies of individual letters & letter combinations
Percentage of occurrence of 26 letters In English text • Make same for CT, compare, & identify PT letters • Use similar comparisons with digrams & trigrams as aids • + commonsense! • Match & snatch letters
most frequent letter pairs (in decreasing order) most frequent 3-letter combinations (in decreasing order)
Letter frequencies in CT Frequencies of most occurring digrams in CT
A & O ← highest frequencies in CT • most likely represent e & t in PT? • Frequency values of 121 & 118 too close to venture assertion • Digrams - OZ & ZA most frequent in CT • Trigrams - OZA most frequent in CT - Eureka – represents ‘the’ in PT: A, O, Ze, t, h • ASO - high frequency in CT match with ent • S in CT: ‘n’ in PT • next most frequent set : PT: a–o–i–s–r–d–l– • CT: M–D–T–Y–I–J–L– • digram ‘DS’ in CT ~ ‘in’ / ‘an’ in plain text • ‘D’ ~ ‘i’ or a • high frequency digramMT in CT • ‘M’ ~ ‘a’ & ‘D’ ~ ‘i’
Digrams AJ & JA - high frequencies in CT • Since A ~ e, corresponding high frequency digrams in PT – ‘er’ & ‘re’J ~ r • DSE ~ ing (since DS ~ is) E ~ g • Guesses so far: • Use guesses so far • & Convert first few lines of CT • Fill in additional letters wherever possible • Complete cryptanalysis
He had selected two examples of student composition. The first was a rambling disconnected thing with interesting ideas that never built into anything. The second was a magnificent piece by a student who was mystified himself about why it had come so well. He read both and then asked for a show of hands on who thought the first was the best. Two hands went up. He asked how many liked the second better. Twenty-eight hands went up. "Whatever it is "he said, " that caused the overwhelming majority to raise their hands for the second one is what I mean by quality. So you know what it is. There was a long reflective silence after this and he just let it last. This was just intellectually outrageous, and he knew it. He was't teaching anymore, he was indoctrinating. He had erected an imaginary entity defined it as incapable of definition, told the students over their own protests that they knew what it was and demonstrated this by a technique that was as confusing logically as the term itself. He was able to get away with this because logical refutation required more talent than any of the students had. In subsequent days he continually invited their refutations, but none came. He improvised further. (From “Zen and the Art of Motorcycle Maintenance” Robert M Pirsig)
affine cipher • Encryption → linear relation: y = ax + b # • a & b ℤ26 • x & y: Integers representing PT & CT letters • Affine cipher is a substitution cipher • Shift cipher a special case of affine cipher with a = 1 • # x = a-1(y – b) • For decryption distinct solution required each y ℤ26 • a-1 (mod 26) should exist gcd(a, 26) = 1 or a ℤ26* • All odd integers 13 – ok • 25 possible values for b • Brute force cryptanalysis • →derive & examine 26 × 25 = 275 texts
Better approach → use letter frequencies & • Identify a & b • PT→ IZRWVMCTWUZUWHIOAPLXOWZRAEZWZSIVZHEVSZWAVVAPQILLYWHOCSIVURAOZRIZIOAPLXOWZRAEZKEILWZYHEVSZWAVUINAPQILLYOCRIJCURAOVZRIZKEILWZYCTWUZUORCZRCPWZWUXCHWVCXAPVAZRCZRCPCEFAVFPASCCXCXZAUENZPISZKEILWZYHPAQIXCUSPWFZWAVAHZRCOAPLXIUOCGVAOWZ
Z & A – most frequent letters in CT should represent • Two first few in English text – try – e & t • Equations relating a & b: • 26 ≡ (5a + b) (mod 26) • 1 ≡ (20a + b) (mod 26) • Subtract →15a≡ -25 (mod 26) ≡ 1 (mod 26) • Multiply by 7 (≡ 15-1(mod 26)) • a = 7 b = 17 • y = 7x + 17 x≡ 7-1(y – 17) (mod 26) • x = 15(y – 17) • IZRWV. . . Of CT becomes joelw. . . Wrong shot!
Try CT - A & Z → t & e in PT • Try CT- A & Z → e & a in PT . . . • Try CT - A & Z → t & o in PT → ok! → a= 5 & b= 4 • PT → A thing exists if a world without it can’t function normally. If we can show that a world without quality functions abnormally we have shown that quality exists whether it is defined or not. He thereupon proceeded to subtract quality from a description of the world as we know it$-(p-193) (From “Zen and the Art of Motorcycle Maintenance” Robert M Pirsig)
Vigenere Cipher • shift cipher & substitution cipher ← mono alphabetic cryptosystems • encrypt letters one at a time – independently and separately • Vigenere Cipher ← poly alphabetic cryptosystem – encrypts m PT letters at a time • Procedure: • Split PT - blocks of m letters each • Corresponding number set ← {x1, x2, . . . xm } • Associate {k1, k2, . . km} with {x1, x2, . . . xm } • Form integral sequence: y1 (x1 + k1)(mod 26); y2 (x2 + k2)(mod 26); . . ym (xm + km)(mod 26) • Convert {y1, y2, . . . ym } back into letter sequence ← a CT block
Decryption follow reverse process: • Split CT into successive blocks of m letters each • CT block {y1, y2, y3, . . ym} • Use key sequence – k1, k2, k3, . . . km • Use equations: x1 (y1 - k1)(mod 26); • x2 (y2 – k2)(mod 26); . . xm (ym – km)(mod 26) • form integral sequence –{x1, x2, x3, . . xm} • Convert {x1, x2, x3, . . xm} – into corresponding m letter PT sequence • CA two parts – identify m value & all ki values • Look for periodicity of identifiable patterns in CT & guess m value • identify ki values
Kasiski’s test • Sequences – the, ing, and, . . occur with good frequency in English text • Can occur at multiples of intervals of m • Similar occurrences with 4 & 5 letter sequences • Hunt for such repetitions in CT • Identify m • See Tables m = 6
Four letter sequences Six letter sequence
Index of Coincidence • Normal English text: p0 probability of occurrence for ‘a’ • p02 ← probability that two letters chosen at random - both ‘a’ = 0.0067 • Add all such probabilities ‘Index of coincidence - I’ • Ip –index of coincidence for plain text: • = 0.0655 • = 0.0385 • Ir ← For text with letters randomly & independently selected - equal probability for all letters
Ip of 0.0655 >> Ir of 0.0385 • difference - conspicuous enough to discriminate • m = 6: arrange cipher text letters in matrix form with six columns - fill cells column-wise • letters in each row ← distribution characteristic plain text: If m = 6 is true IC = Ip else IC = Ir IC values for different values of m m = 6!
With m =6, proceed with identification of 6 key values –integers k0, k1, k2, k3, k4, & k5 • divide CT into 6 subsequences: • 0th, 6th, 12th, . . letters in first subsequence • 1st, 7th, 13th . . . letters in second . . . • 5th, 11th, 17th, . letters are 6th subsequence • each subsequence • ← distribution characteristic of plain text
Letter frequencies of first subsequence • J : highest frequency represents e in PT • k0 = 5 (f) Figures in blue colour: proportionate values (frequencies) of plain text letters shifted by 5
Letter frequencies of second subsequence • k1 = 24 (y) Figures in blue colour: proportionate values (frequencies) of plain text letters shifted by 24
Letter frequencies of third subsequence • k2 = 14 (o) Figures in blue colour: proportionate values (frequencies) of plain text letters shifted by 14
Letter frequencies of fourth subsequence • k3 = 3 (d) Figures in blue colour: proportionate values (frequencies) of plain text letters shifted by 3
Letter frequencies of fifth subsequence • k4 = 4 (e) Figures in blue colour: proportionate values (frequencies) of plain text letters shifted by 4
Letter frequencies of sixth subsequence • k5 = 17 (r) Figures in blue colour: proportionate values (frequencies) of plain text letters shifted by 17
IC values ( 105) with possible shifts for first subsequence -maximum value is in bold letters. Confirmation of k0 = 5 See text for similar results for all other k values Key fyoder
Man, so long as he remains free, has no more constant and agonizing anxiety than to find as quickly as possible someone to worship. But man seeks to worship only what is incontestable - so incontestable indeed that all men at once agree to worship it all together. For, the chief concern of those miserable creatures is not only to find something that I or someone else can worship but to find something that all believe in and worship. And the absolutely essential thing is that they should do so all together. It is this need for universal worship that is the chief torment of every man individually and of mankind as a whole. From the beginning of time for the sake of that universal worship they have put each other to the sword. They have set up gods and called upon each other ‘give up your gods and come and worship ours or else death to you and your gods’. And so it will be to the end of the world. Even when the gods have vanished from the earth, they will prostrate themselves before idols just the same. You knew you couldn’t help knowing this fundamental mysrty of human nature. But you rejected the only absolute banner which was offered to you to make all men worship you alone incontestably. The banner of earthly bread which you rejected in the name of freedom and the bread from heaven. And look what you have done further and all again in the name of freedom. I tell you man has no more agonizing anxiety than to find someone to whom he can hand over with all speed the gift of freedom with which the unhappy creature is born. But only he can gain possession of men’s freedom who is able to set their conscience at ease. With the bread you were given an incontestable banner. Give him bread and man will worship you. For, there is nothing more incontestable than bread. But if at the same time someone besides yourself, should gain possession of his conscience, oh!, then he will even throw away your bread and follow him who has ensnared his conscience. (The Brothers Karamazov, Fyodor Dostoyevsky)
Hill Cipher • Hill Cipher ← a poly alphabetic cipher • generalized version of affine cipher & Vigenere cipher combined • Encrypt m letters at a time • {y1, y1,. . y1} in CT replaces { x1, x2, . . xm} in PT • y1 =a11x1 + a12x2 + . . . + a1mxm • y2 =a21x1 + a22x2 + . . . + a2mxm • . . . • ym =am1x1 + am2x2 + . . . + ammxm • where aij ℤ26 • Y = AX A← mm encryption matrix
Decryption: X = A-1Y • A-1 ← A inverse modulo 26 • Necessary condition A 0 & gcd (A, 26) = 1 • Encrypt arootisaflowerthatdisdainsfame • PT – a & r H & P in CT • HPOYDCGUWTCCRFYVRDPQVPOEZWTUYY
CT LCPQHYYRZLUIAWUBEOYVDZMVLCFKSOZBCCZHRDPKEKPRSOKNDDBRJZDTDZMVLCFKSOTGFUNQFUNP • A 43(mod 26) 17(mod 26) • 43-1 23(mod 26) gcd(43, 26) = 1 A-1 exists • Decrypted final PT • Had I filled myself with all that you know, what room should I have for all that you do not know ? • (Sand and Foam - Kahlil Gibran)
CT: TFJWEGFWEHKAUDJWIWZGPVQSWEGFWEHKAIAQCWMHBHIKFALBUQXJFIADPNDCZUUAKTUHNHGKRHLOFYOCMTFQQYZAAKVSIGDBXAGBMJFWRJFINWGWMDVQFRQTGAFGPPBDZPQKASLQQSTASDJFBKMQJJRYAMBAUKWRPXLQMJVDEVTMODLMBCZJAHJBHKMMHFQCQQSDTLVFUFZWKOQAZZUFZMBNBRJTOSJLDBFTAUMUYZEGCAFICZXIQDFDLCPZAWVEGCNGAUGROUDKMLMBPFYNDGAJNWALBFTRGQHBZTNSEIOKBTYMQCTXCAFFNGADCMOJQUOAUFZAVHQRTDBVCZAUPBNYLOUDJFIWRHWAVMQCNLOKXZEGIDOHSSSWDHRMPIOUNWKPDPZECXYGUUHKEXZUUMMHTFJOCKALBVQFKFHFZWYVFRMMJGTXUQOUSCIDPOPXOKGWMEQUXOKJFIFCDIAYHQPDOVJFIGWMHHHAFIOIMYVFNDCJNWJFIBUQUYDHKEUCZRAKOCTGUVTFJUHMYVFYNRYKCUHMAUOSIHDNEVICFYNUBZWDVPSKOFTJMKMRPADAUEWSVREAZTFJZWFNYERBUEUTBHDQVUQEURQTQILYRFSZRWMXLESKFHEUAAANLAILIMDOHUCZKQLCTRBRQADPCYLYXTTFJIYXGDZGTUDOHIWARQTQILJNWYOJVYHDOVKTKNIPATBBWDIBLZFPSBBNRAJFIGSJEMFDHFTDEECGUMMPKWVDHTPBITKXKDNIPHSTGDZNSLUCZVWUEEFZHEEDTOFYCZJYZTAWVTKLJFIXQJHHMOBZYCBIJHZAFMMHHHHGUJHGBPMKAENHHRULAIOKEQTNLRPNYJFIZCNJHPHSTXYVFSFKPDYOGUKJQWRDQR$
Cryptanalysis determine nine elements of (3 3) A matrix • t, h, & e in PT T in CT as • a1119 + a127 + a134 = 19 (mod 26) • s, c, & a in PT W in CT as • a1118 + a122 + a130 = 22 (mod 26). • r, e, & c in PT F in CT as • a1117 + a124 + a132 = 5 (mod 26). • Solving above 3equations & get • [a11a12a13] = [1 2 3]. • Solving other sets of equations also &
Permutation cipher / ‘transposition cipher • Divide letters of PT groups of m letters each • encryption ← shuffle or permute letters • encryption with m = 5
Encrypt: - • Love which is not always springing is always dying. • PT lovew hichi snota lways sprin gingi salwa ysdyi ngxxx←padded • CTLVWOEHCIIHSOANTLASWYSRNPIGNIIGSLAAWYDISYNXXGX • CTSRNTAGTAEHTRACETRSUEWTOIHUBCTAKOEBNSAEHVTEAHHRETDSSELHLSXXXX. • PT Strange that creatures without backbones have the hardest shells. • (Both from ‘Sand and Foam’ - Kahlil Gibran)
Permutation cipher Hill cipher with matrix coefficients as 0 & 1 • Encryption matrix
Decryption matrix • Matrices inverses of each other • product identity matrix • Each row & Each column only one element has unity value • Matrices are transposes of each other