# Symbolically evaluate abstract cryptographic operations

I would like to use simple variable substitution to show some basic properties of cryptographic constructions using Sage. For example, I want to define an encrpytion and decryption function E and D, so that for a given message m and key k

D(E(m, k), k) = m

I.e., the decrypted encrypted message is the message.

Furthermore, I want to specify that all those variables, (m, k in the above example) are vectors in GF(2) of length 128. This would allow me to use XOR so that

m + m = vector(GF(2), 128)

I.e., a block XOR itself is zero.

I cannot find a way to do this properly (i.e., that XOR terms that cancel each other out are simplified away and that I can use symbolic "encryption" function blocks). Is this possible somehow?

edit retag close merge delete

Sort by » oldest newest most voted

If I got it correctly, you want to define vectors of variables over GF(2). This can be done like this

X.<mbit,kbit> = InfinitePolynomialRing(GF(2))
m = vector( [mbit[i] for i in range(128)] )
k = vector( [kbit[i] for i in range(128)] )


Then you can do operations like m+k (XOR) or accessing individual bits via m[i] etc.

more