answers.md caesar_cracker.py

This commit is contained in:
njmason22
2026-04-11 10:17:48 -04:00
parent 6fed63a708
commit 1b5a93acf7
2 changed files with 34 additions and 6 deletions

View File

@@ -74,6 +74,7 @@ from ciphers.caesar import CaesarCipher
# 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"
# secret4.txt
# 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
@@ -85,7 +86,28 @@ from ciphers.caesar import CaesarCipher
# 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"""
# 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"""
# checkpoint 2 - polyalphabetic encryption/decryption
# ciphertext=":y]JfTp\j[YTUyiQUnd_X[UcpngNQbflZhY]pgnhRPTenJbS|yjWTTcyiQUn`[`hdaV_#"
# length of keyword is probably 6
# 6 columns - now use frequency analysis and monoalphabetic encryption/decryption
# ciphertext=":pUdpfpT|c`V"
# ciphertext="y\y_nlgeyy[_"
# ciphertext="]jiXgZnnji`#"
# ciphertext="J[Q[NhhJWQh"
# ciphertext="fYUUQYRbTUd"
ciphertext="TTncb]PSTna"
data=Counter(ciphertext)
@@ -103,12 +125,14 @@ key_value=keys_list[idx] # apply that same variable to the keys list
# #print(values_list.index(v)) - prints the index number
# print(key_value)
secret=Bits(str(key_value)).int - Bits(' ').int # monoalphabetic offset number
print(data)
# print(secret) # secret number
secret=Bits(str(key_value)).int - Bits('e').int # monoalphabetic offset number
print(secret) # secret number
cipher = CaesarCipher(secret) # I get a runtime warning message referencing
# the variable "ciphertext" - invalid escape sequence.
# the variable "ciphertext" - invalid escape sequence.
cipher.decrypt(ciphertext)
print(cipher.decrypt(ciphertext))