answers.md caesar_cracker.py

This commit is contained in:
njmason22
2026-04-09 21:21:32 -04:00
parent 363a7a1187
commit 0844e968fe
3 changed files with 71 additions and 1 deletions

64
caesar_cracker.py Normal file
View File

@@ -0,0 +1,64 @@
# Nelson Mason -- LAI677LEC LOA -- 4-9-2026
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"
# ChVTanChVTaznQda]X]VnQaXVWczn8]ncWTnU^aTbcbn^UncWTn]XVWc*nFWPcnX\\^acP[nWP]Sn^anThTzn2^d[SnUaP\TncWhnUTPaUd[nbh\\Tcah.
# 8]nfWPcnSXbcP]cnSTT_bn^anbZXTb|n
# 1da]cncWTnUXaTn^UncWX]TnThTb.
# >]nfWPcnfX]VbnSPaTnWTnPb_XaT.
# FWPcncWTnWP]SznSPaTnbTXiTncWTnUXaT.
# 0]SnfWPcnbW^d[STazntnfWPcnPacz
# 2^d[SncfXbcncWTnbX]Tfbn^UncWhnWTPac.
# 0]SnfWT]ncWhnWTPacnQTVP]nc^nQTPc|
# FWPcnSaTPSnWP]S.ntnfWPcnSaTPSnUTTc.
# FWPcncWTnWP\\Ta.nfWPcncWTnRWPX]z
# 8]nfWPcnUda]PRTnfPbncWhnQaPX].
# FWPcncWTnP]eX[.nfWPcnSaTPSnVaPb_|
# 3PaTnXcbnSTPS[hncTaa^abnR[Pb_.
# FWT]ncWTnbcPabncWaTfnS^f]ncWTXanb_TPabn
# 0]SnfPcTauSnWTPeT]nfXcWncWTXancTPab)
# 3XSnWTnb\X[TnWXbnf^aZnc^nbTT.
# 3XSnWTnfW^n\PSTncWTn;P\Qn\PZTncWTT.
# ChVTanChVTanQda]X]VnQaXVWcz
# 8]ncWTnU^aTbcbn^UncWTn]XVWc)
# FWPcnX\\^acP[nWP]Sn^anThTz
# 3PaTnUaP\TncWhnUTPaUd[nbh\\Tcah.
data=Counter(ciphertext)
keys_list = list(data.keys()) # unpack into a key list
values_list = list(data.values()) # and a values list
v=max(values_list) # get the largest value - most frequent - frequency analysis
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)
secret=Bits(str(key_value)).int - Bits(' ').int # monoalphabetic offset number
print(secret)
# cipher = CaesarCipher(secret) # I get a runtime error for lines 61-62.
# print(cipher)
# cipher.decrypt(ciphertext)
# print(cipher.decrypt(ciphertext))
# 'Tyger Tyger, burning bright, In the forests of the night; What imortal hand or eye, Could frame thy fearful symetry?'