[+] A4 P4.3
This commit is contained in:
@@ -122,7 +122,7 @@ def grid_break(ciphertext: str, candidates: set[str]) -> set[int]:
|
|||||||
# Since grid[row][col] = list[row * num_cols + col],
|
# Since grid[row][col] = list[row * num_cols + col],
|
||||||
# The final index of a letter is (i % k * cols + i // k)
|
# The final index of a letter is (i % k * cols + i // k)
|
||||||
#
|
#
|
||||||
# We first filter only possible k, and then filter for messages where only the candidates exists
|
# We first filter only possible k, then filter for messages where only the candidates exists
|
||||||
c = ciphertext
|
c = ciphertext
|
||||||
n = len(c)
|
n = len(c)
|
||||||
return {k for k in range(1, n) if n % k == 0 and
|
return {k for k in range(1, n) if n % k == 0 and
|
||||||
@@ -138,10 +138,7 @@ def run_example_break(ciphertext_file: str, candidates: set[str]) -> list[str]:
|
|||||||
with open(ciphertext_file, encoding='utf-8') as f:
|
with open(ciphertext_file, encoding='utf-8') as f:
|
||||||
ciphertext = f.read()
|
ciphertext = f.read()
|
||||||
|
|
||||||
# (Not to be handed in) Try completing this function by calling grid_break and returning a
|
return [grid_decrypt(k, ciphertext) for k in grid_break(ciphertext, candidates)]
|
||||||
# list of the possible plaintext messages.
|
|
||||||
|
|
||||||
return [ciphertext] + list(candidates) # This is a dummy line, please replace it!
|
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user