Giter Site home page Giter Site logo

ctk's Introduction

ctk

CRC Tool Kit - Python tools for working with CRCs.

The main functionality is a brute-force search (the search space is pruned as soon as possible), that, when given a specification of data sequences and the CRC values they should evaluate to, will try to find the CRC parameters.

CRC Solver

For the case when it is not exactly known over which sequences the CRC is calculated it is possible to symbolically specify multiple alternate possibilities using an embedded domain specific language based on Python operator overloading.

Usage example:

from ctk import *

s = Solver()
s += Data("41 8B 35 10") + TargetCRC("9e")
s.solve()

In general one example will not be enough to uniquely restrict the parameter space. Two examples will usually fix the polynom and inverse parameters. If both are of the same length, the initial value and post XOR value will still be free, since it's possible to give one for an arbitrary value of the other. To circumvent that you may limit the search space if you know or suspect a parameter (e.g. fix post XOR to 0):

s = Solver()
s += Data("41 8B 35 10") + TargetCRC("9e")
s += Data("57 81 82 da") + TargetCRC("6d")
s.search_post = [0]
s.solve()

Data variations

To specify potential variations a set of combining operators is provided that allow examples to be built up from expressions and combinations of expressions (Data() itself is an expression):

  • Concat() (Operator + )
  • Optional() (Operator ~ )
  • Repeat() (Operator * integer or * (integer, integer) )
  • Permute()
  • Combine()

Concat(a, b, …)

simply concatenates the variations of the source expressions. If applicable, the Cartesian product is generated.

Optional(a)

will either include a or not (yielding two variations)

Repeat(a, min, max=1)

repeats a for a fixed or variable number of repetitions. Repeat(a, 2) is equivalent to Concat(a, a). Note that if a yields multiple variations the Cartesian product is generated (same as with Concat()).

Permute(a, b, …, min=?, max=?)

generates all permutations of the given elements. If min and/or max are specified it can additionally generate permutations that include only the given number of elements.

Combine(a, b, …, min=?, max=?)

generates combinations, similar to Permute() but only with elements in the given order. Combine(a, b, c) is equivalent to Concat(a, b, c). Note that Combine(a, b, min=1, max=1) is equivalent to the alternation operator in regular expressions.

Example:

s = Solver()
s += Data("41 8B 35 10") + TargetCRC("9e")
s += Data("57 81 82 da") + TargetCRC("6d")
s += ~Data("57 81 82 da") + Data("20 40 00 00") + TargetCRC("7a")
s.solve()

ctk's People

Contributors

henryk avatar

Stargazers

Minh-Triet Pham Tran avatar Steve Maresca avatar

Watchers

Minh-Triet Pham Tran avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.