예제 #1
0
파일: gray.py 프로젝트: LightBit/substitute
def binary_code(num, m):
    bits = core._I2B(num, fixed_length=8, reverse=True)
    # print(bits)
    bits = np.array(bits, ndmin=2)
    # print(bits.T)
    product = (m * bits.T) % 2
    # print(product.T.tolist()[0])
    return core._B2I(product.T.tolist()[0])
예제 #2
0
def non_linearity(sbox):
    """ Non Linearity of a SBox. """

    # Create a bit matrix of all the entries in the box
    #
    # Columns of this matrix represents the eight boolean
    # functions that constitute this sbox.
    bit_matrix = []
    for num in sbox:
        bit_matrix.append(_I2B(num, fixed_length=8))

    nonlin = []
    for i in range(8):
        # Take the ith column of the matrix
        column = [row[i] for row in bit_matrix]
        nonlin.append(_nl(column))

    # Todo: Is it min or max?
    return min(nonlin)
예제 #3
0
"""
An Improved AES S-box And Its Performance Analysis
by Jie Cui et. al.

http://www.ijicic.org/ijicic-10-01041.pdf
"""

from functools import partial
from os.path import abspath, dirname

# Because the core is present in parent directory.
from sys import path
path.insert(1, dirname(dirname(abspath(__file__))))

import core
import analysis

reduced = core._B2I(core._I2B(0x11B)[1:])

affine = partial(core.affine, u=0x5B, v=0x5D)
power = partial(core.inverse, r=reduced)

sbox = []

for i in range(256):
    sbox.append(affine(power(affine(i))))

print(core.pretty(sbox))
analysis.report(sbox)
예제 #4
0
import analysis

# A list of irreducible polynomials and constants
# http://www.sciencedirect.com/science/article/pii/S2212017313006051
irreducibles = [
    0x11B, 0x11D, 0x12B, 0x12D, 0x139, 0x13F, 0x14D, 0x15F, 0x163, 0x165,
    0x169, 0x171, 0x177, 0x17B, 0x187, 0x18B, 0x18D, 0x19F, 0x1A3, 0x1A9,
    0x1B1, 0x1BD, 0x1C3, 0x1CF, 0x1D7, 0x1DD, 0x1E7, 0x1F3, 0x1F5, 0x1F9
]

constants = [
    0x0A, 0x0F, 0x15, 0x2A, 0x2B, 0x31, 0x32, 0x35, 0x38, 0x40, 0x4A, 0x4E,
    0x54, 0x5E, 0x62, 0x6E, 0x74, 0x7E, 0xF5, 0xF0, 0xEA, 0xD5, 0xD4, 0xCE,
    0xCD, 0xCA, 0xC7, 0xBF, 0xB5, 0xB1, 0xAB, 0xA1, 0x9D, 0x91, 0x2B, 0x81
]

for p in irreducibles:
    reduced = core._B2I(core._I2B(p)[1:])

    for c in constants:

        sbox = []

        for elem in range(256):
            sbox.append(
                core.affine(core.inverse(elem, reduced), u=0x1F, v=0x63))

        val = analysis.values(sbox)
        out = "Polynomial: %02x, Constant: %02x, NL: %d, DP: %d"
        print(out % (p, c, val[0], val[1]))
예제 #5
0
파일: gray.py 프로젝트: LightBit/substitute
def binary_code(num, m):
    bits = core._I2B(num, fixed_length=8, reverse=True)
    # print(bits)
    bits = np.array(bits, ndmin=2)
    # print(bits.T)
    product = (m * bits.T) % 2
    # print(product.T.tolist()[0])
    return core._B2I(product.T.tolist()[0])


# Standard parameters
irreducible_polynomial = 0x11B
constant = 0x63

reduced = core._B2I(core._I2B(irreducible_polynomial)[1:])

# Binary hadmard matrix of size 8
hmatrix = [[1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 1, 0, 1, 0, 1, 0],
           [1, 1, 0, 0, 1, 1, 0, 0], [1, 0, 0, 1, 1, 0, 0, 1],
           [1, 1, 1, 1, 0, 0, 0, 0], [1, 0, 1, 0, 0, 1, 0, 1],
           [1, 1, 0, 0, 0, 0, 1, 1], [1, 0, 0, 1, 0, 1, 1, 0]]

gmatrix = [[1, 1, 0, 0, 0, 0, 0, 0], [0, 1, 1, 0, 0, 0, 0, 0],
           [0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0],
           [0, 0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 1, 1, 0],
           [0, 0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 1]]

# Partials are fun!
affine = partial(core.affine, c=constant)
power = partial(core.inverse, r=irreducible_polynomial)