Direct operations
pychef.ops provides plain functions for common transformations. They need no
recipe list and no pipeline object:
>>> from pychef.ops import from_hex, to_base64, sha256
>>> data = from_hex("414243")
>>> data
b'ABC'
>>> to_base64(data)
'QUJD'
>>> sha256(data)[:16]
'b5d4045c3f466fa9'
Each function runs the registered CyberChef operation through the regular engine,
so results match bake and Pipeline. Options are keyword-only and named;
unknown values are rejected by the operation.
Types
Input:
str(UTF-8 encoded when bytes are needed) or bytes-like (bytes,bytearray,memoryview). Anything else raisesTypeError.Decoders (
from_*,xor,gzip_*) returnbytes.Encoders (
to_*,url_*,html_*) and hashes returnstr.rot13andreversereturn the type they were given:strforstr,bytesfor bytes-like.
Policy
Calls use ExecutionPolicy.safe() unless you choose otherwise (see also the
nesting rules at the end of this page). Resolution order:
an explicit policy= (run_operation only), then the innermost active
policy – a using_policy() block or a running bake/Pipeline/Chef
execution (for example inside a Pipeline.apply callable), whichever was entered
last – then the safe default.
>>> from pychef import ExecutionLimitError, ExecutionPolicy
>>> from pychef.ops import to_hex, using_policy
>>> with using_policy(ExecutionPolicy(max_input_bytes=2)):
... try:
... to_hex(b"abc")
... except ExecutionLimitError as error:
... print(error.limit)
max_input_bytes
Network operations are denied under the default policy, exactly as in bake.
Function reference
Function |
Returns |
CyberChef operation |
Notes |
|---|---|---|---|
|
|
From Hex |
|
|
|
To Hex |
Default delimiter |
|
|
From Base64 |
|
|
|
To Base64 |
|
|
|
From Base32 / To Base32 |
|
|
|
URL Encode |
|
|
|
URL Decode |
|
|
|
To HTML Entity |
|
|
|
From HTML Entity |
|
|
|
ROT13 |
Result type follows input type |
|
|
Reverse |
Text defaults to |
|
|
XOR |
Empty keys are rejected |
|
|
Gzip / Gunzip |
|
|
|
(uses |
Same functions and format as |
Errors
Invalid input types raise TypeError. Bad option values raise ValueError or
an OperationError from the underlying operation; limit and permission problems
raise ExecutionLimitError and OperationPermissionError.
Any other operation
>>> from pychef.ops import run_operation
>>> run_operation("To Hex", b"AB", args=("Colon", 0))
'41:42'
value is the input, args the positional operation arguments, and
policy the engine policy. The three never overlap. The result is str or
bytes depending on the operation.