Kryha Cryptanalysis - Superposition Method


Home Page
Kryha Home Page
Kryha Cryptanalysis Home Page

Principle

Superposition is a method that can be applied to all substitution ciphers. It was invented by Auguste Kerckhoffs.

The principle is simple: if we assume that two cryptograms have been encrypted with the same key, we superimpose them, that is, we place them one below the other. Each column contains letters that have been encrypted identically and therefore belong to the same alphabet. This alphabet corresponds to a substitution of the standard alphabet. We measure the number of coincidences, that is, the number of times two letters in the same column are equal. It can be shown that these coincidences are all the more significant when the letters composing each column belong to the same alphabet.

Here is the calculation of the IC (Index of Coincidence):

		IC = N / L

	N: number of coincidences
	L: number of letters (number of columns) in the superposition.
If the two texts are not superimposed, IC = 0.0385

If the two texts are superimposed, the IC value is a signature of the language used.

  • In German, IC = 0.0762
  • In English, IC = 0.0667
  • In French, IC = 0.0778
  • In Spanish, IC = 0.0770

Applications

Message-in-depth analysis

Using overlay, it is possible to prove that two or more messages have been encrypted with the same key. If a large number of overlay messages are available, the plaintext can be reconstructed. Decryption is then relatively easy. This is the attack carried out by Parker Hitt (see below).

Constructing a long pseudo-cryptogram

Several attack methods require very long cryptograms (several thousand characters). However, secret message exchanges generally involve relatively short messages (on the order of a few hundred characters).

Suppose we have two cryptograms, both composed of 200 characters. By testing all possible overlays of the two messages, we find that the last hundred characters of the first message were encrypted with the same key as the first hundred characters of the second message. Adding the last 100 characters of the second message to the first message yields a pseudo-cryptogram of 300 characters.

If this type of operation can be repeated, very long messages can be created, making them more vulnerable to attack.

Finding the Key Length

Instead of superimposing two different messages, the message can be superimposed on itself, but offset by a certain number of columns.

The goal here is to find the length of the substitution key.

Example: Finding the key Length of a Kryha cryptogram

If we have a cryptogram encrypted using a Kryha equipped with a 17-sector wheel, after 17 characters, we end up with the same sequence of shifts. However, we don't have the same alphabet, unless the sum of the shifts is equal to 0 (modulo 26).

Let L be the sum of the shifts (equal to 111 in the case of the standard wheel). We end up with the same alphabet at most after (sectors x 26) (442 for a 17-sector wheel). We also end up with the same alphabet if L has a value that divides 26. This is the case for L being even or equal to 13 (half of 26).

Let's take a concrete example. We encrypt a message and calculate the IC (Index of Coincidences) for each shift. It turns out to be maximum for a shift of 104 columns. This is compatible with a 4-sector wheel. My program superpose.py displays the column offset and the associated number of overlaps as well as the value of lC.

$ cat MSGS/nightingale.raw
My heart aches, and a drowsy numbness pains
         My sense, as though of hemlock I had drunk,
Or emptied some dull opiate to the drains
         One minute past, and Lethe-wards had sunk:
'Tis not through envy of thy happy lot,
         But being too happy in thine happiness,—
                That thou, light-winged Dryad of the trees
                        In some melodious plot
         Of beechen green, and shadows numberless,
                Singest of summer in full-throated ease.

O, for a draught of vintage! that hath been
         Cool'd a long age in the deep-delved earth,
Tasting of Flora and the country green,
         Dance, and Provençal song, and sunburnt mirth!
O for a beaker full of the warm South,
         Full of the true, the blushful Hippocrene,
                With beaded bubbles winking at the brim,
                        And purple-stained mouth;
         That I might drink, and leave the world unseen,
                And with thee fade away into the forest dim:

Fade far away, dissolve, and quite forget
         What thou among the leaves hast never known,
The weariness, the fever, and the fret
         Here, where men sit and hear each other groan;
Where palsy shakes a few, sad, last gray hairs,
         Where youth grows pale, and spectre-thin, and dies;
                Where but to think is to be full of sorrow
                        And leaden-eyed despairs,
         Where Beauty cannot keep her lustrous eyes,
                Or new Love pine at them beyond to-morrow.

Away! away! for I will fly to thee,
         Not charioted by Bacchus and his pards,
But on the viewless wings of Poesy,
         Though the dull brain perplexes and retards:
Already with thee! tender is the night,
         And haply the Queen-Moon is on her throne,
                Cluster'd around by all her starry Fays;
                        But here there is no light,
         Save what from heaven is with the breezes blown
                Through verdurous glooms and winding mossy ways.

I cannot see what flowers are at my feet,
         Nor what soft incense hangs upon the boughs,
But, in embalmed darkness, guess each sweet
         Wherewith the seasonable month endows
The grass, the thicket, and the fruit-tree wild;
         White hawthorn, and the pastoral eglantine;
                Fast fading violets cover'd up in leaves;
                        And mid-May's eldest child,
         The coming musk-rose, full of dewy wine,
                The murmurous haunt of flies on summer eves.

Darkling I listen; and, for many a time
         I have been half in love with easeful Death,
Call'd him soft names in many a mused rhyme,
         To take into the air my quiet breath;
                Now more than ever seems it rich to die,
         To cease upon the midnight with no pain,
                While thou art pouring forth thy soul abroad
                        In such an ecstasy!
         Still wouldst thou sing, and I have ears in vain—
                   To thy high requiem become a sod.

Thou wast not born for death, immortal Bird!
         No hungry generations tread thee down;
The voice I hear this passing night was heard
         In ancient days by emperor and clown:
Perhaps the self-same song that found a path
         Through the sad heart of Ruth, when, sick for home,
                She stood in tears amid the alien corn;
                        The same that oft-times hath
         Charm'd magic casements, opening on the foam
                Of perilous seas, in faery lands forlorn.

Forlorn! the very word is like a bell
         To toll me back from thee to my sole self!
Adieu! the fancy cannot cheat so well
         As she is fam'd to do, deceiving elf.
Adieu! adieu! thy plaintive anthem fades
         Past the near meadows, over the still stream,
                Up the hill-side; and now 'tis buried deep
                        In the next valley-glades:
         Was it a vision, or a waking dream?
                Fled is that music:—Do I wake or sleep?

$ python3 kryha_tui.py -o -s 3,2,5,1 \
	-i KPFQVGMASCHYNIORDELUBZWJXT \
	-c < MSGS/nightingale.raw >| /tmp/night_4sectors.cry

$ python groupe.py < /tmp/night_4sectors.cry
NZFBR QQGMS QNUQE CYWEB RLGAX HBMUD YEXKQ LQBVS NZRFF ILUVF
AUBOB ODPAK XORHJ JOMCC BJTKI VFOSP LOQRO OIPLS EPZJC PTHEB
XKBOV CQQCG OBVUL BMUTI PNABJ YZGUC HBZYM HXGXB XZANS YZEIU
TJNKN ZYESL EJSMH RMKAA CCPYV TEABR JVASZ UWSHK ISKFE KTJCJ
RNXKG UOAAD EXFLO SALJB WVUFR CWRPX HZTPZ OGHKF VDUBT BRMSH
QRHHS PGTMB VONDF NKHXO RZFZO DAUBF ZYJLE VAZLQ FLSLL GVUVD
BCWSA NXQTS TGQPZ SUKRU ZPFYU HBDPU SUGAY ILIKC PEQEC BNHCR
FCSFL HBBEG XPJWK QRAGQ PABLJ FHMGW NYJVH TXSNF SBUWJ ZQKYW
YWEHZ XRDIE JQRNU VKHJB RTIBZ RBXMD TPWLC XHJHA THPUO ESTAM
LBHDE ZZZRB IJCUC MAUME NTFDC HGSGO YJNAC JCLOK WBQRP URWQW
HGLVT JFJZM UPCJI BVRAG KKTUD MYMRG EDPQX EZYQE DPWOQ EUFOP
YYAFW HJZKQ AZLWJ KJMEF UAZWD CCLKC TPWAU MNKZI BVEYP ODAJC
PQISD KYWOJ MRKYM PPUBD YVMTS HOVSU OHLLQ NNUWZ IGMFF BCISC
GGCDO GPSRM LGDRF HURJJ HQEEK OMQRE WTCMV BGOHO GWDWS LHTXI
QEXMX XJKDU GJOUI TREMR ONXDD NPGEJ SUSUO HZGLP JALGR CBFCX
GGBFA RVGKE AEYSN DUFXS ZPJME ZGTHL FHUZK EVLPL VAYAJ OZZPY
FKYET BPRWF PKHVR JDQAP OHUYL YMNWN MOQRH BEGPC JSAAU QENDC
ZBVXC EIQKZ REQTQ JUXXD PTTYK ZJYWI RNAHI JYOMT KWVLH YCMGO
HLXFF QNVDK ZUOGF FGKYM MSJNY UCPIV YVVTB ZLPUB AKPLS JHSOB
QEZCQ EDPWT IIGDO PRGFP FJUXK EBRRM CVCIR QRWXZ IOKLY YXLDB
BWQQZ CXTQY SPJJB EDLQW QIPKK AFSXA BXDNG TVRHW SPEPU VFPNO
GNAZQ JNJPE VSNUU FOMVL AFEVY OLEVN CFUAI XVNPN JAIPY ZFHOW
EEHQO WSRFW BVOBS VDVNS ZRWNC AEUGL BSWRK DQJAM RNUIO YSXAK
JNSLL PHVPI HDJDD XCDNK ZWOPJ RDXWI CULOB SMSOM FETRN ZEPNW
CQOWT MTZEY AQOHD MOQNK LPYQK LIVXV YPHYZ POJCP JHZDH NXFYY
EQSUP UXAMR JAEQT UJDQG MPXPA RVBVV UZXNE DLILI RSPOM TYSAA
GONTC TDJFF SYJZP ITLCJ SNCVL CSMHL CJZOQ NKFRN BWMVW MJVGJ
BOUVT EQMDN WFUIP QLZCG OHPJZ IQUBM UDFYB GQHGV AIDZU QGISD
FEPAB QRABQ JHGPN SEAIH SYJRJ HUWER PUBFC WZUGJ YWZHE SZJCW
HURIJ ZSDOA UDMIR VZPPC LDSPW GYYGI TNKCG IWCCP FMDMM MBVSL
WHCTD OXODL ZCJAY QZAVC BXGIX NGUJL CKBKN RPOZN MNXEH UXYYW
ZTQPF RVRHQ OCQQZ XVJOL INJZS BUUSP PDDCB WYZSF SYATG JUWLF
BYFQJ YCHMT YFKFF ROQOW NLVHM BYAQG WUZRJ UQCBF EDJZR KYELS
ZBYNC JEJLD RZIPY FQQKK GCKCL PJDMI ITOPP BYBOC LIVGV QSPDT
LFNTN TFWCU FTHRY LDPRP OQDMH OWYOD BHOTB YLXEX RDFUA NKSQU
GMMYT WXSZV WMZAR TXGVC IXSQL AYBIJ PBAJH CQDPO APTFO MIMTV
XULTP HUFAG VHEUK MMMJA BXFQU LNMYG BBNSR IOTCL STUBH WZMFY
NNDLL ZTRKN CWZJO ECGUU EJOEM UAGQN LZEFM WOWYI HXLXW IQPRR
WXVVC PVIQC SPPSU KQOSY TTZFT OSZDF DTGSS AXWOH OUVFJ NUEFK
BSZUZ DEEEU QDZTH EDVDM JQCOH OVOZC JKJJJ LQBWC ZINSE BHITE
AJRVG MQZDV VIIBR ZNCJJ RUNGG OROGE NQUFG GEPOR HDBTZ DSNSY
ERQIS MOXNM OOBMA UVRAU BDQJC DWIXP NPIVF LQNVB VSIQE CJGWG
DPCPM ROZSF OEUBR MWZOK YYSEG ISNDQ ZXLXT HDYPH XLVKB EVVSY
BYPTG NATIW LYBNA IKACF MRYWF CKNXN VWYBU GABAU HXYQM BHFEZ
SYYKT BHEXI BZUNY ZQZXN URUFX WQHZB COFNP TPVKZ MTRKV UNYJP
NWSZS DXXDO DCTQG WJZDU GJIUV MQLUK VYFBZ NMFVS MCQGX DRIQZ
ULXOT UREVX WMKZG BRCKC BXDMS HVRIX URCUM JKZMP PQHHM TDHGH
DLEQU OFWXQ RAEQL HJQER YSYZM MXUXI AAHPD UBBRF TSXNM DJTQI
TGTAN JLZIG MFRCL GGFOM OFWSF EYCUX LCRZM QDHWL MMVMM PNQOU
NYXLU REOUV XWDXI BUWLV NDSFE SMQFJ AJKPO SRPUN NNWUH TMSZU
UVMGW CLBOX MEWLE RJDLJ BWIGL FWQZX RCIBU FBHPV POMFN QROJO
WBBHP WM

$ python3 superpose.py -c /tmp/night_4sectors.cry -t 110
   0 =>  2557, 1.000
   2 =>   113, 0.044
   4 =>   115, 0.045
   8 =>   124, 0.048
  18 =>   112, 0.044
  24 =>   116, 0.045
  33 =>   112, 0.044
  47 =>   110, 0.043
  57 =>   125, 0.049
  66 =>   119, 0.047
  67 =>   120, 0.047
  72 =>   110, 0.043
  76 =>   119, 0.047
  80 =>   114, 0.045
  85 =>   117, 0.046
 100 =>   120, 0.047
 104 =>   146, 0.057
 108 =>   111, 0.043
 112 =>   116, 0.045
 116 =>   116, 0.045
 117 =>   110, 0.043
 133 =>   131, 0.051
 136 =>   114, 0.045
 139 =>   114, 0.045
 146 =>   116, 0.045
 151 =>   123, 0.048
 156 =>   121, 0.047