Cryptography Challenges

Some experiments in cryptography

View on GitHub

Build Status CircleCI

Introduction

This project contains experiments in cryptography. The goal is to learn about different cryptographic algorithms.

Glossary

Encryption Methods

Caesar Cipher

In cryptography, a Caesar cipher, also known as Caesar’s cipher, the shift cipher, Caesar’s code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence.

Caesar Cipher

ROT13

A special case of the Caesar cipher is known as ROT13 (“rotate by 13 places”, sometimes hyphenated ROT-13). ROT13 is a simple letter substitution cipher that replaces a letter with the 13th letter after it.

Because there are 26 letters (2×13) in the basic Latin alphabet, ROT13 is its own inverse; that is, to undo ROT13, the same algorithm is applied, so the same action can be used for encoding and decoding

Example for ROT13

Cryptoanalysis

Brute Force Attack

In cryptography a brute-force attack consists of the attacker trying out all possible keys until the cleartext is found.

Frequency Analysis

In cryptanalysis, frequency analysis (also known as counting letters) is the study of the frequency of letters or groups of letters in a ciphertext. The method is used as an aid to breaking classical ciphers.

Typical letter frequencies of an English text

Challenge 1

One day at school you find the following message under your desk. You suspect that it is encrypted using the Caesar Cipher. Your task is the following:

  1. Decrypt the message
  2. Write up what you did to find the cleartext message. This description should include more details on the cipher, i.e. the shift.
  3. As a bonus see if you can find out more about the cleartext.

The write-up should be a simple textfile. Add this textfile to the repository on GitHub. Then create a pull request against that text file.

Good luck!

P.S. A hint

Think about how many keys (i.e. possible shifts) you can chose from using the Caesar Cipher. One possible way of attacking the ciphertext is a so called brute-force attack in which you try out all keys until you find the right one.

The secret message

ofoxlopyboroqydovomdbymedon,tkcyxgkcrkfsxqkbyddoxnki.rogyuosxdrolkmuco
kdypkcmryyvlec,xydcebogroborogkc,ryvnsxqrkxncgsdrkqsbvronsnx'duxyg.drk
dgkcx'dxomocckbsvidrobyddoxzkbd.droqsbvgkcmedo,ledromyevnx'dpsqeboyedg
rycrogkcybgrkdrogkcnysxqdrobo.rockdezkxnbellonrscoioc,dbisxqdydrsxu.kp
ognyjoxusncczbkgvonsxdrocokdcsxpbyxdyprsw,vscdoxsxqdyszync,dkvusxq,ybc
voozsxq.droikvvvyyuonkbyexnrsckqo...pspdoox?cshdoox?yuki,drkdgkccmkbi.
ronsnx'duxygrscygxkqo.drolecbewlvonkvyxqklewzibykn.yeddrogsxnygc,nocob
dbyvvonliexnobklbsqrdlveocui.tkcyxgkczboddiceboronsnx'dvsfosxdronocobd
.rodbsondydrsxulkmu...drovkcddrsxqrobowowlobon...droqsbvcaeoojonrscrkx
n."tkcyx,iyeyuki?"crogybopknontokxc,rsusxqlyydc,kxnkpvoomocxyglykbnsxq
tkmuod.robmrymyvkdolbygxrksbgkcmedmryzzikxnexofox,gsdrdrsxcdbkxnclbksn
onnygxdrocsnoc.crogyboxywkuoez,vsuocrogkcdbisxqxyddynbkgkddoxdsyxdyrob
covp;ledsdnsnx'dgybu.crogkccobsyecvizboddi.roboioccoowondymrkxqomyvybv
suokukvosnycmyzo-lbygx,lveo,kxnqboox.tkcyxvodqyyprobrkxn."ew,snyx'd-"s
xdropbyxdypdrolec,kdokmrobcryedon,"kvvbsqrd,mezmkuoc,vscdoxez!"droqeig
kcylfsyecvikmykmr.rsclkcolkvvmkzgkczevvonvygyfobrscrksb,cyiyemyevntecd
coorscloknioioc.rorknkgscziqykdookxnkcyebpkmo,vsuoro'nokdoxcywodrsxqwy
vni.rscleppkbwckxnmrocdzecronkqksxcdklbsqrdybkxqozyvycrsbd.rscxivyxgyb
uyedzkxdckxnxsuocgoboczydvoccgrsdo.kgrscdvorexqpbywrscxomu,kxnkwoqkzry
xogkcmvszzondyrsclovd.rogyevn'fovyyuonzboddicmkbisprorknx'dlooxpsfopyy
djoby.groxrocdyynezsxdrokscvo,yxoypdrocdenoxdcmkvvon,"cdkxnez,mykmrron
qo!""srokbndrkd!"dromykmrcmkxxondrolecpybdroyppoxnob.droxrscoiocpshony
xtkcyx,kxnrsccmygvnoozoxon.ktyvdgoxdnygxtkcyx'cczsxo.rogkccebodromykmr
uxogronsnx'dlovyxqdrobo.rogkcqysxqdymkvvtkcyxyed,nowkxngrkdrogkcnysxqy
xdrolec?kxntkcyxgyevnx'drkfokmveogrkddycki.ledmykmrronqovyyuonkgkikxnm
vokbonrscdrbykd."go'vvkbbsfosxpsfowsxedoc!cdkigsdriyebzkbdxob.nyx'dvyc
oiyebgybucrood.kxnspkxiypiyezbomsyecvsddvomezmkuocmkecokxidbyelvoyxdrs
cdbsz,sgsvvzobcyxkvvicoxniyelkmudymkwzecdrorkbngki."rozsmuonezklkcolkv
vlkdkxnwknovsuorogkcrsddsxqkrywob.

Solution Entries

Challenge 2

Break the following encrypted message using a frequency analysis approach. You can use the script in scripts/frequency_analysis.py to analyze the ciphertext.

For you solution, please specify the frequencies of the letters from the ciphertext. Use those frequencies to guess the shift used and decrypt the ciphertext with the script in scripts/caesar.py.

The ciphertext

"AVARGL-RVTUG--AVARGL-AVAR--BARUHAQERQ."TYBEVNJVGUQERJUREPUHOOLYVGGYRS
BERNEZSEBZORSBERURERLRFNAQFGBBQSBENZBZRAG,JEVAXYVATUREABFRNAQOYVAXVATV
AGURFHAYVTUG.GURA,GELVATGBJNGPUVANYYQVERPGVBAFNGBAPR,FURJVGUQERJNSRJPN
HGVBHFFGRCFSEBZGURGERRNTNVAFGJUVPUFURUNQORRAYRNAVAT.FURPENARQUREARPXGB
VAIRFGVTNGRGURCBFFVOVYVGVRFBSNPYHZCBSOHFURFGBGUREVTUGNAQGURAJVGUQERJSN
EGUREGBBOGNVANORGGRENATYRSBEIVRJVATVGFQNEXERPRFFRF.GURDHVRGJNFCEBSBHAQ
RKPRCGSBEGURVAPRFFNAGOHMMVATBSVAFRPGFNAQGURBPPNFVBANYPUVEEHCBSFBZRUNEQ
LOVEQ,OENIVATGURZVQQNLFHA.TYBEVNCBHGRQ,"VORGURJRAGVAFVQRGURUBHFR,NAQV'
IRGBYQUVZNZVYYVBA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