ctfsolver.managers.manager_crypto

manager_crypto.py

This module provides cryptographic utility functions for CTF (Capture The Flag) challenges, including XOR encryption, Base64 decoding, and regular expression-based extraction of flags and encoded strings from text.

Classes:

ManagerCrypto: A class containing methods for cryptographic operations and pattern matching.

Typical usage example:

crypto = ManagerCrypto() decoded = crypto.decode_base64(encoded_text) flags = crypto.re_match_flag(text, “FLAG”)

initializing_all_ancestors(*args, **kwargs)[source]

Initializes all ancestors of the class (placeholder).

xor(text

str, key: str) -> str: XORs the input text with the provided key.

decode_base64(text

str) -> str: Decodes a Base64-encoded string.

re_match_base64_string(text

str, strict=False) -> list[str]: Finds Base64 strings in the input text using regular expressions.

re_match_flag(text

str, origin: str) -> list[str]: Extracts flags matching the given origin from the text.

re_match_partial_flag(text

str, origin: str) -> list[str]: Extracts partial or complete flags matching the given origin from the text.

Classes

ManagerCrypto

ManagerCrypto provides utility methods for common cryptographic operations and flag extraction used in CTF challenges.

Module Contents

class ManagerCrypto(*args, **kwargs)[source]

ManagerCrypto provides utility methods for common cryptographic operations and flag extraction used in CTF challenges. .. method:: initializing_all_ancestors(*args, **kwargs)

Initializes all ancestors of the class. (Currently a placeholder.)

xor(text

str, key: str) -> str: XORs the input text with the provided key and returns the result as a string.

decode_base64(text

str) -> str: Decodes a base64-encoded string and returns the decoded text.

re_match_base64_string(text

str, strict: bool = False) -> list[str]: Finds and returns all base64 strings in the input text. If strict is True, matches only strings with padding.

re_match_flag(text

str, origin: str) -> list[str]: Searches for flags in the input text matching the pattern ‘{origin}{…}’ and returns all matches.

re_match_partial_flag(text

str, origin: str) -> list[str]: Searches for partial flags in the input text matching the pattern ‘{origin}{…}’ or ‘{…}’ and returns all matches.

initializing_all_ancestors(*args, **kwargs)[source]
Description:

Initializes all the ancestors of the class

xor(text, key)[source]

Description: XOR the text with the key

Parameters:
  • text (str) – Text to XOR

  • key (str) – Key to XOR

Returns:

XORed text

Return type:

str

decode_base64(text)[source]

Description: Decode the base64 text

Parameters:

text (str) – Base64 encoded text

Returns:

Decoded text

Return type:

str

re_match_base64_string(text, strict=False)[source]

Description: Find the base64 string in the text

Parameters:
  • text (str) – Text to search for base64 string

  • strict (bool, optional) – If True, it will only return the base64 string. Defaults to False.

Returns:

list of Base64 string found in the text

Return type:

str

re_match_flag(text, origin)[source]

Description: Find the flag in the text

Parameters:
  • text (str) – Text to search for the flag

  • origin (str) – Origin of the flag

Returns:

list of flag found in the text

Return type:

str

re_match_partial_flag(text, origin)[source]

Description: Find the flag in the text or partial flag

Parameters:
  • text (str) – Text to search for the flag

  • origin (str) – Origin of the flag

Returns:

list of flag found in the text

Return type:

str