Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change checkers to become objects similar to decode #29

Merged
merged 10 commits into from
Jul 25, 2022
Merged

Conversation

bee-san
Copy link
Owner

@bee-san bee-san commented Jul 24, 2022

Problem

When we're using Caesar cipher, with the old design we'd need to do something like this:

def caesar():
    output = []
    for i in range(0, 26):
        output + crack()
    return output
    
check(output)

This is a bad idea because:

  1. We should align the happy path to the left and exit as soon as we find a solution.
  2. Decoders do not support returning multiple items so we would need to edit them to do so.

I propose a different solution:

def caesar(text, checker):
    output = []
    for i in range(0, 26):
        cracked_item = crack()
        if check(cracked_item):
            return success
    return failure

This saves time, is cleaner and gives decoder authors ultimate control over when we check if its plaintext or not.

This pull request turns checkers into objects so we can pass them to the decoders. We do not check in the decoders yet, that is for another PR.

@bee-san bee-san marked this pull request as ready for review July 25, 2022 12:59
@bee-san bee-san changed the title Bee loose checkers Change checkers to become objects similar to decode Jul 25, 2022
@bee-san bee-san requested a review from swanandx July 25, 2022 13:16
@bee-san bee-san merged commit c615b3e into main Jul 25, 2022
@delete-merged-branch delete-merged-branch bot deleted the bee-loose-checkers branch July 25, 2022 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants