Skip to content

Documentation

Varbin edited this page Jul 11, 2014 · 33 revisions

XTEA documentation

This is the documentation for xtea in python.


|Content |

Functions

New in 0.3.0: Added CFB-mode

function new(key, **kwargs):

Constructor for an "XTEACipher" object
  • key - a string, must have a length of 8 (128-bits)

  • Optional parameters:

  • MODE - int or long, must be one of the following (default 1):

    • 1 (ECB)
    • 2 (CBC)
    • 3 (CFB)
    • 5 (OFB)
    • 6 (CTR) - Buggy

    Number 4 is the OpenPGP format, it is not used (see more at PEP 272

  • IV - string, must have a length of one block (8), needed with CBC and CFB, optional with OFB, if not given in CBC/CFB, raises a value error

  • counter - callable function/object, the counter function for CTR, must return a number (int or long

    Warning: In future versions, the counter can return a string or a number

  • endian - on of the strings "@", "=", "<", ">" or "!", look in the struct documentation for details, (default "!" or ">" (network/big endian)).

  • rounds - int or long, rounds for the cipher; more rounds = more security = more slowness; 2 rounds = 1 cycle

The XTEACipher object

class XTEACipher(object):

The cipher object
  • block_size = 8

function init(self, key, **kwargs):

Alternative constructor, same as new


function encrypt(self, data):

Encrpyts data. Modes with initialisation vector will reset, if you recall the function!

  • text - string, the text to encrypt. It must have a fixed size (e.g. a multiple of 8 in length)

function decrypt(self, data):

Decrypts data. Modes with initialisation vector will reset, if you recall the function!

  • text - string, the text to decrypt. It must have a fixed size (e.g. a multiple of 8 in length)

Helper functions

function xor_strings(s, t):

Xor to strings together.

  • s, t - strings with same length

function stringToLong(s):

Convert a string(with more then an char) into a long.

  • s - strings

function longToString(n):

Convert a long into a string.

  • n - int or long, not every number works

Constants

New in 0.3.0: Added PGP-constant
MODE_ECB = 1
MODE_CBC = 2
MODE_CFB = 3
MODE_PGP = 4
MODE_OFB = 5
MODE_CTR = 6

block_size = 64
key_size = 128
Clone this wiki locally