Danger

Nothing here should be used for any security purposes.

  • If you need cryptographic tools in a Python environment use pyca.

  • If you need efficient and reliable abstract math utilities in a Python-like environment consider using SageMath.

Types

Imported with:

import toy_crypto.types

Helpful(?) type declarations and guards.

These are intended to make things easier for me, the author (jpgoldberg). They are not carefully thought out. This module is probably the least stable of any of these unstable modules.

class toy_crypto.types.Bit(b: SupportsBool)

Because I made poor choices earlier of how to represent bits, I need an abstraction.

Parameters:

b (SupportsBool)

toy_crypto.types.Byte

And int representing a single byte.

Currently implemented as a type alias. As a consequence, type checking is not going to identify cases where an int out of the range of a byte is used.

class toy_crypto.types.PositiveInt

Positive integer.

alias of int

class toy_crypto.types.Prob

Probability: A float between 0.0 and 1.0

alias of float

class toy_crypto.types.SupportsBool(*args, **kwargs)
toy_crypto.types.is_byte(val: Any) bool

True iff val is int s.t. 0 <= val < 256.

Parameters:

val (Any)

Return type:

bool

toy_crypto.types.is_positive_int(val: Any) TypeGuard[PositiveInt]

true if val is a float, s.t. 0.0 <= val <= 1.0

Parameters:

val (Any)

Return type:

TypeGuard[PositiveInt]

toy_crypto.types.is_prob(val: Any) TypeGuard[Prob]

true if val is a float, s.t. 0.0 <= va <= 1.0

Parameters:

val (Any)

Return type:

TypeGuard[Prob]