optimisticninja / liberprimus-tool

Python tool/libraray for evolving solutions toward the Liber Primus from Cicada 3301
1 stars 1 forks source link

bug: Fix printing header of non-pages #9

Open optimisticninja opened 2 months ago

optimisticninja commented 2 months ago

Currently, when operating over a segment that may include multiple pages, the header looks as follows: (this is for pages 12/13 which is actually operating over segment 5, not page 5).

This can be referenced in #3 as a means to display as page:segment:paragraph:sentence:word, etc.

...

=== PAGE 5 ===
$
%
A-COAN.DURNG-A-LESSON-THE-MAS/
TER-EXPLAINED-THE-I.THE-/
I-IS-THE-UOICE-OF-THE-CIRCU/
MFERENCE-HE-SAID.WHEN-AS/
CED-BY-A-STUDENT-TO-EXPLAIN/
-WHAT-THAT-MEANT-THE-MASTER-SA/
ID-IT-IS-A-UOICE-INSIDE-YOUR-H/
EAD.I-DONT-HAUE-A-UOICE-I/
N-MY-HEAD-THOUGHT-THE-STUDENT-/
AND-HE-RAISED-HIS-HAND-TO-TE/
LL-THE-MASTER.THE-MASTER-STOP/
%
PED-THE-STUDENT-AND-SAID-THE-/
UOICE-THAT-JUST-SAID-YOU-HAU/
E-NO-UOICE-IN-YOUR-HEAD-IS-THE-/
I.AND-THE-STUDENTS-WERE-ENL/
IGHTENED./
&

=== PAGE 14 ===
...
d4v1-sudo commented 2 months ago
class SolutionSpec(DNA):
    # ...

    def run(self, silent=False):
        """ Generic cradle to run decryptions """
        segment_num = 0
        for num, text in zip(self.retrieval.nums, self.retrieval.retrieve()):
            # if it's a new segment
            if num != segment_num:
                segment_num = num
                if not silent:
                    # show the correct segment information
                    mode_name = self.retrieval.mode.__name__  # Get the attribute name of the mode
                    print(f"=== PAGE {segment_num} ({mode_name.upper()} {num}) ===")
            else:
                if not silent:
                    # If it's not a new segment, display the page information only
                    print(f"=== PAGE {num} ===")
            if not silent and self.show_runes:
                print(text)
                print("-----")
            if self.crypto.key:
                plaintext = self.crypto.scheme(text,
                                               key=self.crypto.key,
                                               shift=self.crypto.shift,
                                               lookup=self.crypto.lookup,
                                               skips=self.crypto.skips,
                                               excludes=self.crypto.excludes)
                if not silent:
                    print(plaintext)
                else:
                    self.plaintext = plaintext
            else:
                plaintext = self.crypto.scheme(text, lookup=self.crypto.lookup, shift=self.crypto.shift, skips=self.crypto.skips)
                if not silent:
                    print(plaintext)
                else:
                    self.plaintext = plaintext

    # ...
optimisticninja commented 2 months ago

This has a temporary fix in main now where i get the attribute name of the mode and insert it into a format string.

d4v1-sudo commented 2 months ago

This has a temporary fix in main now where i get the attribute name of the mode and insert it into a format string.

What about now?

optimisticninja commented 2 months ago

This has a temporary fix in main now where i get the attribute name of the mode and insert it into a format string.

What about now?

Yep, if you run main.py with no arguments you will see section 5 printed for pages 12 and 13. However, supplying --section or --lines doesn't print anything at the moment.