Skip to content

Commit

Permalink
Made Cipheys output more friendly and fixed the what bug (#632)
Browse files Browse the repository at this point in the history
  • Loading branch information
bee-san authored May 21, 2021
1 parent 35e3de8 commit 9df16a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ciphey/basemods/Checkers/human.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from typing import Dict, Optional
import os
from rich.console import Console

console = Console()

from ciphey.iface import Checker, Config, ParamSpec, registry

Expand All @@ -11,8 +15,9 @@ def getParams() -> Optional[Dict[str, ParamSpec]]:

def check(self, text: str) -> Optional[str]:
with self._config().pause_spinner_handle():
response = input(f"Result {text.__repr__()} (y/N): ").lower()
response = console.input(f"Result [blue bold]{text.__repr__()}[/blue bold] ([green]y[/green]/[red]N[/red]): ")
if response == "y":
self.clear_terminal()
return ""
elif response in ("n", ""):
return None
Expand All @@ -24,3 +29,7 @@ def getExpectedRuntime(self, text: str) -> float:

def __init__(self, config: Config):
super().__init__(config)

def clear_terminal(self):
# https://stackoverflow.com/a/2084628
os.system('cls' if os.name == 'nt' else 'clear')
4 changes: 4 additions & 0 deletions ciphey/basemods/Checkers/what.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from ciphey.iface import Checker, Config, ParamSpec, T, registry
from loguru import logger
from pywhat import identifier
from rich.console import Console

console = Console()


@registry.register
Expand All @@ -16,6 +19,7 @@ def check(self, ctext: T) -> Optional[str]:
logger.trace("Trying PyWhat checker")
returned_regexes = self.id.identify(ctext, api=True)
if len(returned_regexes["Regexes"]) > 0:
console.print(f'\nI think the plaintext is a [yellow]{returned_regexes["Regexes"][0]["Regex Pattern"]["Name"]}[/yellow]')
return returned_regexes["Regexes"][0]["Regex Pattern"]["Name"]
return None

Expand Down

0 comments on commit 9df16a2

Please sign in to comment.