# Path: crysp/utils/operators.py
# def ror(x,n):
#     return (x>>n | x<<(x.size-n))
# 
# def rol(x,n):
#     return (x<<n | x>>(x.size-n))
# 
# def concat(L,bigend=False):
#     if len(L)==1: return L[0]
#     if bigend: L = reversed(L)
#     return reduce(lambda x,y: x//y, L)


from crysp.bits import *
from crysp.utils.operators import ror,rol,concat
    return keys

def _L(X):
    assert X.size==128
    X = X.split(32)
    X[0] = rol(X[0],13)
    X[2] = rol(X[2],3)
    X[1] = X[1]^X[0]^X[2]
    X[3] = X[3]^X[2]^(X[0]<<3)
    X[1] = rol(X[1],1)
    X[3] = rol(X[3],7)
    X[0] = X[0]^X[1]^X[3]
    X[2] = X[2]^X[3]^(X[1]<<7)
    X[0] = rol(X[0],5)
    X[2] = rol(X[2],22)
    return concat(X)

def _Linv(X):
    assert X.size==128
    X = X.split(32)
    X[2] = ror(X[2],22)
    X[0] = ror(X[0],5)
    X[2] = X[2]^X[3]^(X[1]<<7)
    X[0] = X[0]^X[1]^X[3]
    X[3] = ror(X[3],7)
    X[1] = ror(X[1],1)
    X[3] = X[3]^X[2]^(X[0]<<3)
    X[1] = X[1]^X[0]^X[2]
    X[2] = ror(X[2],3)
    X[0] = ror(X[0],13)

# Path: crysp/utils/operators.py
# def ror(x,n):
#     return (x>>n | x<<(x.size-n))
# 
# def rol(x,n):
#     return (x<<n | x>>(x.size-n))
# 
# def concat(L,bigend=False):
#     if len(L)==1: return L[0]
#     if bigend: L = reversed(L)
#     return reduce(lambda x,y: x//y, L)


# Path: crysp/serpent.py
from crysp.bits import *
from crysp.utils.operators import ror,rol,concat

    return keys

def _L(X):
    assert X.size==128
    X = X.split(32)
    X[0] = rol(X[0],13)
    X[2] = rol(X[2],3)
    X[1] = X[1]^X[0]^X[2]
    X[3] = X[3]^X[2]^(X[0]<<3)
    X[1] = rol(X[1],1)
    X[3] = rol(X[3],7)
    X[0] = X[0]^X[1]^X[3]
    X[2] = X[2]^X[3]^(X[1]<<7)
    X[0] = rol(X[0],5)
    X[2] = rol(X[2],22)
    return concat(X)

def _Linv(X):
    assert X.size==128
    X = X.split(32)
    X[2] = ror(X[2],22)
    X[0] = ror(X[0],5)
    X[2] = X[2]^X[3]^(X[1]<<7)
    X[0] = X[0]^X[1]^X[3]
    X[3] = ror(X[3],7)
    X[1] = ror(X[1],1)
    X[3] = X[3]^X[2]^(X[0]<<3)
    X[1] = X[1]^X[0]^X[2]
    X[2] = ror(X[2],3)
    X[0] = ror(X[0],13)

    return concat(X)