From 6fed63a708c436df75015fe99da40a8c1f84047b Mon Sep 17 00:00:00 2001 From: njmason22 Date: Fri, 10 Apr 2026 07:44:11 -0400 Subject: [PATCH] answers.md caesar_cracker.py --- answers.md | 23 ++++-- caesar_cracker.py | 173 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 157 insertions(+), 39 deletions(-) diff --git a/answers.md b/answers.md index 21a253e..2009447 100644 --- a/answers.md +++ b/answers.md @@ -5,22 +5,35 @@ 0. `secrets/secret0.txt` is encrypted using a Caesar Cipher. What is its secret number? 78 'Tyger Tyger, burning bright, In the forests of the night; What imortal hand or eye, Could frame thy fearful symetry?' - + # 4-9-2026 # I got some "escape sequence" warnings, plus, eventually I got a runtime error. However, I # was able to decode by using the interactive "python" command line and typed in several lines of # code at the >>> prompt. Once I get some feedback I'll decode more secret texts. Thank you, Stacy. + # + # 4-10-2026 - I got caesar_cracker.py running more smoothly. + 'Tyger Tyger, burning bright, In the forests of the night; What imortal hand or eye, Could frame thy fearful symetry?' + In what distant deeps or skies. Burnt the fire of thine eyes?On what wings dare he aspire?What the hand, dare seize the fire? + And what shoulder, & what art,Could twist the sinews of thy heart?And when thy heart began to beat.What dread hand? & what dread feet? + What the hamer? what the chain,In what furnace was thy brain?What the anvil? what dread grasp.Dare its deadly terrors clasp? + When the stars threw down their spears And water'd heaven with their tears:Did he smile his work to see?Did he who made the Lamb make thee? + Tyger Tyger burning bright,In the forests of the night:What imortal hand or eye,Dare frame thy fearful symetry? 1. `secrets/secret1.txt` is encrypted using a Caesar Cipher. What is - its secret number? + its secret number? 1 + One must have a mind of winterTo regard the frost and the boughsOf the pine-trees crusted with snow; + And have been cold a long timeTo behold the junipers shagged with ice,The spruces rough in the distant glitter + Of the January sun; and not to thinkOf any misery in the sound of the wind,In the sound of a few leaves, + Which is the sound of the landFull of the same windThat is blowing in the same bare place + For the listener, who listens in the snow,And, nothing himself, beholdsNothing that is not there and the nothing that is. 2. `secrets/secret2.txt` is encrypted using a Caesar Cipher. What is - its secret number? + its secret number? 44 3. `secrets/secret3.txt` is encrypted using a Caesar Cipher. What is - its secret number? + its secret number? 59 4. `secrets/secret4.txt` is encrypted using a Caesar Cipher. What is - its secret number? + its secret number? 32 ## Checkpoint 2 diff --git a/caesar_cracker.py b/caesar_cracker.py index f8bb83a..4e1dc28 100644 --- a/caesar_cracker.py +++ b/caesar_cracker.py @@ -4,35 +4,88 @@ from easybits import Bits from collections import Counter from ciphers.caesar import CaesarCipher -ciphertext="ChVTanChVTaznQda]X]VnQaXVWczn8]ncWTnU^aTbcbn^UncWTn]XVWc*nFWPcnXacP[nWP]Sn^anThTzn2^d[SnUaPncWhnUTPaUd[nbhcah" +# secret0.txt +# ciphertext="ChVTanChVTaznQda]X]VnQaXVWczn8]ncWTnU^aTbcbn^UncWTn]XVWc*nFWPcnX\\^acP[nWP]Sn^anThTzn2^d[SnUaP\\TncWhnUTPaUd[nbh\\Tcah." -# ChVTanChVTaznQda]X]VnQaXVWczn8]ncWTnU^aTbcbn^UncWTn]XVWc*nFWPcnX\\^acP[nWP]Sn^anThTzn2^d[SnUaP\TncWhnUTPaUd[nbh\\Tcah. +# ciphertext="8]nfWPcnSXbcP]cnSTT_bn^anbZXTb|n1da]cncWTnUXaTn^UncWX]TnThTb.>]nfWPcnfX]VbnSPaTnWTnPb_XaT.FWPcncWTnWP]SznSPaTnbTXiTncWTnUXaT." -# 8]nfWPcnSXbcP]cnSTT_bn^anbZXTb|n -# 1da]cncWTnUXaTn^UncWX]TnThTb. -# >]nfWPcnfX]VbnSPaTnWTnPb_XaT. -# FWPcncWTnWP]SznSPaTnbTXiTncWTnUXaT. +# ciphertext="0]SnfWPcnbW^d[STazntnfWPcnPacz2^d[SncfXbcncWTnbX]Tfbn^UncWhnWTPac.0]SnfWT]ncWhnWTPacnQTVP]nc^nQTPc|FWPcnSaTPSnWP]S.ntnfWPcnSaTPSnUTTc." -# 0]SnfWPcnbW^d[STazntnfWPcnPacz -# 2^d[SncfXbcncWTnbX]Tfbn^UncWhnWTPac. -# 0]SnfWT]ncWhnWTPacnQTVP]nc^nQTPc| -# FWPcnSaTPSnWP]S.ntnfWPcnSaTPSnUTTc. +# ciphertext="FWPcncWTnWP\\Ta.nfWPcncWTnRWPX]z8]nfWPcnUda]PRTnfPbncWhnQaPX].FWPcncWTnP]eX[.nfWPcnSaTPSnVaPb_|3PaTnXcbnSTPS[hncTaa^abnR[Pb_." -# FWPcncWTnWP\\Ta.nfWPcncWTnRWPX]z -# 8]nfWPcnUda]PRTnfPbncWhnQaPX]. -# FWPcncWTnP]eX[.nfWPcnSaTPSnVaPb_| -# 3PaTnXcbnSTPS[hncTaa^abnR[Pb_. +# ciphertext="FWT]ncWTnbcPabncWaTfnS^f]ncWTXanb_TPabn0]SnfPcTauSnWTPeT]nfXcWncWTXancTPab)3XSnWTnb\\X[TnWXbnf^aZnc^nbTT.3XSnWTnfW^n\\PSTncWTn;P\\Qn\\PZTncWTT." -# FWT]ncWTnbcPabncWaTfnS^f]ncWTXanb_TPabn -# 0]SnfPcTauSnWTPeT]nfXcWncWTXancTPab) -# 3XSnWTnb\X[TnWXbnf^aZnc^nbTT. -# 3XSnWTnfW^n\PSTncWTn;P\Qn\PZTncWTT. +# ciphertext="ChVTanChVTanQda]X]VnQaXVWcz8]ncWTnU^aTbcbn^UncWTn]XVWc)FWPcnX\\^acP[nWP]Sn^anThTz3PaTnUaP\\TncWhnUTPaUd[nbh\\Tcah." -# ChVTanChVTanQda]X]VnQaXVWcz -# 8]ncWTnU^aTbcbn^UncWTn]XVWc) -# FWPcnX\\^acP[nWP]Sn^anThTz -# 3PaTnUaP\TncWhnUTPaUd[nbh\\Tcah. +# secret1.txt +# ciphertext="Pof!nvtu!ibwf!b!njoe!pg!xjoufsUp!sfhbse!uif!gsptu!boe!uif!cpvhitPg!uif!qjof.usfft!dsvtufe!xjui!topx<" +# ciphertext="Boe!ibwf!cffo!dpme!b!mpoh!ujnfUp!cfipme!uif!kvojqfst!tibhhfe!xjui!jdf-Uif!tqsvdft!spvhi!jo!uif!ejtubou!hmjuufs" + +# ciphertext="Pg!uif!Kbovbsz!tvoN=J?A[KB[PDEJCO[L=OPg%[OECD[PDA[H=?G[KB[I=JU[=[PDEJC[%[OKQCDPg" + +# ciphertext="|J@[SEPD[KH@[SKAO[JAS[S=EH[IU[@A=N[PEIAbO[S=OPAu0DAJ[?=J[%[@NKSJ[=J[AUAg[QJQOb@[PK[BHKSgKN[LNA?EKQO[BNEAJ@O[DE@[EJ[@A=PDbO[@=PAHAOO[JECDPg" + +# ciphertext="|J@[SAAL[=BNAOD[HKRAbO[HKJC[OEJ?A[?=J?AHHb@[SKAg|J@[IK=J[PDb[ATLAJOA[KB[I=JU[=[R=JEODb@[OECDPv0DAJ[?=J[%[CNEARA[=P[CNEAR=J?AO[BKNACKJAg" + +# ciphertext="|J@[DA=REHU[BNKI[SKA[PK[SKA[PAHH[KbAN0DA[O=@[=??KQJP[KB[BKNAh>AIK=JA@[IK=Jg3DE?D[%[JAS[L=U[=O[EB[JKP[L=E@[>ABKNAi}QP[EB[PDA[SDEHA[%[PDEJG[KJ[PDAAg[@A=N[BNEAJ@g|HH[HKOOAO[=NA[NAOPKNb@g[=J@[OKNNKSO[AJ@i" + +# ciphertext="""l"5&@a6(645L@(*7&/@)&"7:@3"*/@"/%@46/f03@"@'6--@8&&,L@5)&@#-"$,#&33*&4@806-%@3*1&/Na5@'*345L@+645@0/&L@"@(-044:@1631-&@$-05a.0/(@05)&34L@3&%L@(3&&/L@)"3%@"4@"@,/05N""" +# use triple quotes before and after the string + +# ciphertext="""y06@"5&@5)"5@'*345@0/&@"/%@*54@'-&4)@8"4@48&&5l*,&@5)*$,&/&%@8*/&Z@46..&3G4@#-00%@8"4@*/@*5l&"7*/(@45"*/4@610/@5)&@50/(6&@"/%@-645@'03p*$,*/(N@t)&/@3&%@0/&4@*/,&%@61@"/%@5)"5@)6/(&3""" + +# ciphertext="""s&/5@64@065@8*5)@.*-,@$"/4L@1&"@5*/4L@+".M1054w)&3&@#3*"34@4$3"5$)&%@"/%@8&5@(3"44@#-&"$)&%@063@#0054Nr06/%@)":'*&-%4L@$03/'*&-%4@"/%@105"50M%3*--4w&@53&,,&%@"/%@1*$,&%@6/5*-@5)&@$"/4@8&3&@'6--L""" + +# ciphertext="""u/5*-@5)&@5*/,-*/(@#0550.@)"%@#&&/@$07&3&%w*5)@(3&&/@0/&4L@"/%@0/@501@#*(@%"3,@#-0#4@#63/&%l*,&@"@1-"5&@0'@&:&4N@o63@)"/%4@8&3&@1&11&3&%w*5)@5)03/@13*$,4L@063@1"-.4@45*$,:@"4@b-6&#&"3%G4N""" + +# ciphertext="""w&@)0"3%&%@5)&@'3&4)@#&33*&4@*/@5)&@#:3&Nb65@8)&/@5)&@#"5)@8"4@'*--&%@8&@'06/%@"@'63La@3"5M(3&:@'6/(64L@(-655*/(@0/@063@$"$)&Nt)&@+6*$&@8"4@45*/,*/(@500N@o/$&@0''@5)&@#64)""" + +ciphertext="""t)&@'36*5@'&3.&/5&%L@5)&@48&&5@'-&4)@806-%@563/@4063Ni@"-8":4@'&-5@-*,&@$3:*/(N@i5@8"4/G5@'"*3t)"5@"--@5)&@-07&-:@$"/'6-4@4.&-5@0'@305Ne"$)@:&"3@i@)01&%@5)&:G%@,&&1L@,/&8@5)&:@806-%@/05N""" data=Counter(ciphertext) @@ -44,21 +97,73 @@ values_list.index(v) # get the index of the largest value idx=values_list.index(v) # put that index into a variable key_value=keys_list[idx] # apply that same variable to the keys list -print(keys_list) -print(values_list) -print(v) -#print(values_list.index(v)) - prints the index number -print(key_value) +# print(keys_list) +# print(values_list) +# print(v) +# #print(values_list.index(v)) - prints the index number +# print(key_value) secret=Bits(str(key_value)).int - Bits(' ').int # monoalphabetic offset number -print(secret) +# print(secret) # secret number -# cipher = CaesarCipher(secret) # I get a runtime error for lines 61-62. +cipher = CaesarCipher(secret) # I get a runtime warning message referencing +# the variable "ciphertext" - invalid escape sequence. +cipher.decrypt(ciphertext) +print(cipher.decrypt(ciphertext)) -# print(cipher) - -# cipher.decrypt(ciphertext) -# print(cipher.decrypt(ciphertext)) +# secret0 +# 'Tyger Tyger, burning bright, In the forests of the night; What imortal hand or eye, Could frame thy fearful symetry?' +# In what distant deeps or skies. Burnt the fire of thine eyes?On what wings dare he aspire?What the hand, dare seize the fire? +# And what shoulder, & what art,Could twist the sinews of thy heart?And when thy heart began to beat.What dread hand? & what dread feet? +# What the hamer? what the chain,In what furnace was thy brain?What the anvil? what dread grasp.Dare its deadly terrors clasp? +# When the stars threw down their spears And water'd heaven with their tears:Did he smile his work to see?Did he who made the Lamb make thee? +# Tyger Tyger burning bright,In the forests of the night:What imortal hand or eye,Dare frame thy fearful symetry? -# 'Tyger Tyger, burning bright, In the forests of the night; What imortal hand or eye, Could frame thy fearful symetry?' \ No newline at end of file +# secret1 +# One must have a mind of winter To regard the frost and the boughs Of the pine-trees crusted with snow; +# And have been cold a long time To behold the junipers shagged with ice,The spruces rough in the distant glitter +# Of the January sun; and not to think Of any misery in the sound of the wind,In the sound of a few leaves, +# Which is the sound of the land Full of the same wind That is blowing in the same bare place +# For the listener, who listens in the snow,And, nothing himself, beholdsNothing that is not there and the nothing that is. + +# secret2 +# Now as I was young and easy under the apple boughsAbout the lilting house and happy as the grass was green,The night above the dingle starry, +# Time let me hail and climb Golden in the heydays of his eyes,And honoured among wagons I was prince of the apple towns +# And once below a time I lordly had the trees and leaves Trail with daisies and barley Down the rivers of the windfall light. +# And as I was green and carefree, famous among the barns About the happy yard and singing as the farm was home,In the sun that is young once only, +# Time let me play and be Golden in the mercy of his means,And green and golden I was huntsman and herdsman, the calves +# Sang to my horn, the foxes on the hills barked clear and cold,And the sabbath rang slowly In the pebbles of the holy streams. +# All the sun long it was running, it was lovely, the hay Fields high as the house, the tunes from the chimneys, it was air And playing, lovely and watery +# And fire green as grass. And nightly under the simple stars As I rode to sleep the owls were bearing the farm away, +# All the moon long I heard, blessed among stables, the nightjars Flying with the ricks, and the horses Flashing into the dark. +# And then to awake, and the farm, like a wanderer white With the dew, come back, the cock on his shoulder: it was all Shining, it was Adam and maiden, +# The sky gathered again And the sun grew round that very day.o it must have been after the birth of the simple light +# In the first, spinning place, the spellbound horses walking warm Out of the whinnying green stable On to the fields of praise. +# And honoured among foxes and pheasants by the gay housender the new made clouds and happy as the heart was long,In the sun born over and over, +# I ran my heedless ways,My wishes raced through the house high hay And nothing I cared, at my sky blue trades, that time allows +# In all his tuneful turning so few and such morning songs Before the children green and golden Follow him out of grace, +# Nothing I cared, in the lamb white days, that time would take mep to the swallow thronged loft by the shadow of my hand,In the moon that is always rising, +# Nor that riding to sleep I should hear him fly with the high fields And wake to the farm forever fled from the childless land. +# Oh as I was young and easy in the mercy of his means,Time held me green and dying Though I sang in my chains like the sea. + +# secret3 +# When to the sessions of sweet silent thought I summon up remembrance of things past,I sigh the lack of many a thing I sought, +# And with old woes new wail my dear time's waste:Then can I drown an eye, unus'd to flow,or precious friends hid in death's dateless night, +# And weep afresh love's long since cancell'd woe,And moan th' expense of many a vanish'd sight;Then can I grieve at grievances foregone, +# And heavily from woe to woe tell o'er The sad account of fore-bemoaned moan,Which I new pay as if not paid before. +# But if the while I think on thee, dear friend,All losses are restor'd, and sorrows end. + +# secret4 +# Late August, given heavy rain and sun For a full week, the blackberries would ripen. +# At first, just one, a glossy purple clot Among others, red, green, hard as a knot. +# You ate that first one and its flesh was sweetLike thickened wine: summer's blood was in it +# Leaving stains upon the tongue and lust for Picking. Then red ones inked up and that hunger +# Sent us out with milk cans, pea tins, jam-pots Where briars scratched and wet grass bleached our boots. +# Round hayfields, cornfields and potato-drills We trekked and picked until the cans were full, +# Until the tinkling bottom had been covered With green ones, and on top big dark blobs burned Like a plate of eyes. +# Our hands were peppered With thorn pricks, our palms sticky as Bluebeard's. +# We hoarded the fresh berries in the byre.But when the bath was filled we found a fur,A rat-grey fungus, glutting on our cache. +# The juice was stinking too. Once off the bush The fruit fermented, the sweet flesh would turn sour. +# I always felt like crying. It wasn't fair That all the lovely canfuls smelt of rot. +# Each year I hoped they'd keep, knew they would not. \ No newline at end of file