Conventions

Below is a table of conversions between pseudocode and python functions located in playcrypt.tools and playcrypt.primitives. By importing those two modules you will have access to all of the functions used in the table below.

In our code we use strings to represent cipher and plain text messages. This means that we need several custom functions in order to perform common pseduocode tasks such as XORing two messages together.

Pseudocode

Python function

EXT-GCD(a, N) → (d, a’, N’)

egcd(a, b)

MOD-INV(a, N) → a -1 mod N

modinv(a, m)

s 1 || s 2 || … || s n

join(s) *

string → int

string_to_int(s, optional_length)

⟨x⟩ (int → string)

int_to_string(x)

⟨x⟩ s.t. length of string

int_to_string(x, l)

<s> + num mod 2 size

add_int_to_string (s,num,size)

s1 ⊕ s2

xor_strings(s1, s2)

string1 || string2

string1 + string2

None

a mod N

a % N

0n

"\x00" * (n/8)

1n

"\xFF" * (n/8)

R ←$ {0, 1} n

rand_string(n/8)

M ∈ D

M in D

M ∉ D

M not in D

2n

2**n

∣s∣

len(s)

AESk(m)

AES(k, m)

AES-1 k (m)

AES_I(k, m)

*s is an array of strings