コード例 #1
0
    def __init__(self, n, k, log2FieldSize=-1, systematic=1, shouldUseLUT=-1):
        """
        Function:   __init__(n,k,log2FieldSize,systematic,shouldUseLUT)
        Purpose:    Create a Reed-Solomon coder for an (n,k) code.
        Notes:      The last parameters, log2FieldSize, systematic
                    and shouldUseLUT are optional.

                    The log2FieldSize parameter
                    represents the base 2 logarithm of the field size.
                    If it is omitted, the field GF(2^p) is used where
                    p is the smalles integer where 2^p >= n.

                    If systematic is true then a systematic encoder
                    is created (i.e. one where the first k symbols
                    of the encoded result always match the data).

                    If shouldUseLUT = 1 then a lookup table is used for
                    computing finite field multiplies and divides.
                    If shouldUseLUT = 0 then no lookup table is used.
                    If shouldUseLUT = -1 (the default), then the code
                    decides when a lookup table should be used.
        """
        if (log2FieldSize < 0):
            log2FieldSize = int(math.ceil(math.log(n) / math.log(2)))
        self.field = ffield.FField(log2FieldSize, useLUT=shouldUseLUT)
        self.n = n
        self.k = k
        self.fieldSize = 1 << log2FieldSize
        self.CreateEncoderMatrix()
        if (systematic):
            self.encoderMatrix.Transpose()
            self.encoderMatrix.LowerGaussianElim()
            self.encoderMatrix.UpperInverse()
            self.encoderMatrix.Transpose()
コード例 #2
0
ファイル: tests.py プロジェクト: icoz/Sbox-Analyzer
def DegField1():
    print "DegField1:",
    F = ffield.FField(2)
    f = [1, 3, 0, 2]  #t*x^2 + 1
    answer = 2
    pol = FPolynom(F, [])
    pol.FromPermutation(f)
    Test(pol.Deg(), answer)
コード例 #3
0
ファイル: tests.py プロジェクト: icoz/Sbox-Analyzer
def FuncPolynom3():
    print "FuncPolynom3:",
    F = ffield.FField(2)
    f = [1, 1, 1, 1]
    answer = f
    pol = FPolynom(F, [])
    pol.FromPermutation(f)
    Test(pol.Values(False), answer)
コード例 #4
0
ファイル: tests.py プロジェクト: icoz/Sbox-Analyzer
def FuncPolynom2():
    print "FuncPolynom2:",
    F = ffield.FField(2)
    f = [1, 2, 2, 0]  #x^3 + x^2 + x(t + 1) + 1
    answer = FPolynom(F, [1, 3, 1, 1])
    pol = FPolynom(F, [])
    pol.FromPermutation(f)
    Test(pol, answer)
コード例 #5
0
ファイル: tests.py プロジェクト: icoz/Sbox-Analyzer
def FuncPolynom1():
    print "FuncPolynom1:",
    F = ffield.FField(2)
    f = [1, 3, 0, 2]  #t*x^2 + 1
    answer = FPolynom(
        F, [FElement(F, 1),
            FElement(F, 0),
            FElement(F, 2),
            FElement(F, 0)], True)
    pol = FPolynom(F, [])
    pol.FromPermutation(f)
    Test(pol, answer)
コード例 #6
0
ファイル: qrcode.py プロジェクト: tavooca/pyqr
 def get_ecc(self, codewords):
     "as described in BBC whitepaper..."
     generator = table_generator[self.codewords - self.datawords]
     F = ffield.FField(8)
     acc = [0] * (len(codewords) + len(generator))
     p = 0
     for c in codewords:
         acc[p] = F.Add(acc[p], c)
         q = 1
         for g in generator:
             acc[p + q] = F.Add(acc[p + q], F.Multiply(acc[p], g))
             q += 1
         p += 1
     return acc[len(codewords):]
コード例 #7
0
ファイル: sbox.py プロジェクト: icoz/Sbox-Analyzer
sys.path.append("../FFIeldFunc")
sys.path.append("../FieldPolynom")
sys.path.append("../Cryptonalysis")
from DifferentialCryptanalisys import *
from LineCryptoanalisys import *
import ffield
from ffield import FElement
from  boolean import *
from field_func import *
import itertools
from permutation import *
from field_polynom import *


n = 4
F = ffield.FField(n)


sbox = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 12, 15, 14]






print "S-box:"
print sbox
print


print "Differential table:"
コード例 #8
0
ファイル: 6857_ps1_2c.py プロジェクト: izzygomez/MIT
50 2f b4 ed 6e 3d 63 9e 7a 1c a4 71 f9 f0 52 ce 0f 35 e5 02 2c 18 93 f7 f3 9c a7 7d b5 97 4d 00 7a 55 d9 d4 18 41 82 c6
11 70 f6 85 38 02 17 e1 06 6f 3b f6 7a 0b 93 5e 0f a8 2f 61 69 18 ee a2 57 3d 73 4b df c7 55 7c 27 3e a5 e5 8d a6 4f 37
50 63 f6 84 fa 7c 63 77 5e 6f 8b c8 26 f7 46 b1 1f bb 9a 61 7e 18 8a e8 d5 53 a7 d3 1f 4c 55 ae 7a b8 3e e5 cd 41 84 e5"""

# format cipher texts. all_ciphs is a list of all 8 ciphers,
# each one represented as a list of it's 40 message bytes
all_ciphs = string.split(eight_ciphs, "\n")
for i in xrange(len(all_ciphs)):
    all_ciphs[i] = string.split(all_ciphs[i], " ")

# create pad hex bytes
hexdigits = string.hexdigits[:-6]
possible_pad_bytes = [i + j for i in hexdigits for j in hexdigits]

# Initialize finite field GF(8)
F = ffield.FField(8)


# Helper functions for computations
def hex2dec(hex_string):
    '''converts hex value to dec'''
    return int(hex_string, 16)


def dec2hex(dec):
    '''converts int to hex string W/OUT '0x' in front'''
    return hex(dec)[2:]


def resolve_mi(ci_hex, pi_hex, qi_hex):
    '''given hex-valued values ci, pi, and qi, return mi,
コード例 #9
0
import sys
sys.path.append("../Boolean")
sys.path.append("../Permutation")
sys.path.append("../FField")
sys.path.append("../FFieldFunc")
sys.path.append("../FieldPolynom")

import ffield
from ffield import FElement
from  boolean import *
from field_func import *
import itertools
from permutation import *
from field_polynom import *

F = ffield.FField(2)
p = []
for i in range(2**F.n):
	p.append(i)
perms =  list(itertools.permutations(p))

c = FPolynom(F, []);
for j in range(len(perms)):
	perm = perms[j]
	fieldFunc = list(perm)
	eq = FieldFuncToBooleanFunc(fieldFunc, F.n)
	degs = ""
	for q in eq:
		degs = degs + str(Deg(q)) + ", "
	degs = "[" + degs[0:-2] + "]"
	c.FromPermutation(fieldFunc)
コード例 #10
0
import sys
import os
import random
from os import path
import binascii

# Defining some constants for GF
mask1 = 128
mask2 = 127
polyred = 7
exp = [[] for i in range(128)]
io_dict = dict()
num_plain_texts = 0
# First we'll break the diagonal elements
import ffield
F = ffield.FField(7)

def addGF(p1,p2):
	# Assume both a and b are integers
	return p1^p2

def multGF(p1, p2):
	return F.Multiply(p1,p2)

def convertHex(list_p1):
	text = ""
	for p1 in list_p1:
		text += format(p1,'08b')
	temp1 = ""
	for i in range(0,len(text)//4):
		temp1 = temp1 + chr(ord('f')+int(8*int(text[i*4])+4*int(text[i*4+1])+2*int(text[i*4+2])+int(text[i*4+3])))