[Pymoul-svn] SF.net SVN: pymoul: [218] pymoul/trunk
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-02-28 12:14:00
|
Revision: 218
http://pymoul.svn.sourceforge.net/pymoul/?rev=218&view=rev
Author: tiran
Date: 2007-02-28 04:13:59 -0800 (Wed, 28 Feb 2007)
Log Message:
-----------
Moved code to external packages included with svn:externals
Modified Paths:
--------------
pymoul/trunk/INSTALL.txt
pymoul/trunk/src/moul/__init__.py
pymoul/trunk/src/moul/crypt/binary.py
pymoul/trunk/src/moul/crypt/tests/test_wdys.py
pymoul/trunk/src/moul/crypt/whatdoyousee.py
Added Paths:
-----------
pymoul/trunk/src/EXTERNALS.txt
Removed Paths:
-------------
pymoul/trunk/src/moul/crypt/binaryrecord.py
pymoul/trunk/src/moul/crypt/tests/test_binary.py
pymoul/trunk/src/moul/crypt/tests/test_binaryrecord.py
pymoul/trunk/src/moul/crypt/xtea.py
pymoul/trunk/src/moul/osdependent/tests/test_processinfo.py
Property Changed:
----------------
pymoul/trunk/src/
Modified: pymoul/trunk/INSTALL.txt
===================================================================
--- pymoul/trunk/INSTALL.txt 2007-02-28 12:10:44 UTC (rev 217)
+++ pymoul/trunk/INSTALL.txt 2007-02-28 12:13:59 UTC (rev 218)
@@ -6,10 +6,14 @@
* easy_install http://peak.telecommunity.com/DevCenter/EasyInstall
* setuptools (via easy_install)
* pytz (via $ easy_install-2.5 -Z pytz)
- * enumprocess (via $ easy_install-2.5 -Z enumprocess)
* Qt4 GPL 4.2+ http://www.trolltech.com/developer/downloads/qt/
* PyQt4 4.1.1+ http://www.riverbankcomputing.co.uk/pyqt/
+ These external modules were created for pyMoul and are bundled with the tool.
+ * binaryfile
+ * enumprocess
+ * xtea
+
Windows
-------
Property changes on: pymoul/trunk/src
___________________________________________________________________
Name: svn:externals
+ xtea https://pymoul.svn.sourceforge.net/svnroot/pymoul/xtea/trunk/src/xtea
enumprocess https://pymoul.svn.sourceforge.net/svnroot/pymoul/enumprocess/trunk/src/enumprocess
binaryfile https://pymoul.svn.sourceforge.net/svnroot/pymoul/binaryfile/trunk/src/binaryfile
Added: pymoul/trunk/src/EXTERNALS.txt
===================================================================
--- pymoul/trunk/src/EXTERNALS.txt (rev 0)
+++ pymoul/trunk/src/EXTERNALS.txt 2007-02-28 12:13:59 UTC (rev 218)
@@ -0,0 +1,3 @@
+xtea https://pymoul.svn.sourceforge.net/svnroot/pymoul/xtea/trunk/src/xtea
+enumprocess https://pymoul.svn.sourceforge.net/svnroot/pymoul/enumprocess/trunk/src/enumprocess
+binaryfile https://pymoul.svn.sourceforge.net/svnroot/pymoul/binaryfile/trunk/src/binaryfile
Property changes on: pymoul/trunk/src/EXTERNALS.txt
___________________________________________________________________
Name: svn:keywords
+ 'Id Revision'
Name: svn:eol-style
+ native
Modified: pymoul/trunk/src/moul/__init__.py
===================================================================
--- pymoul/trunk/src/moul/__init__.py 2007-02-28 12:10:44 UTC (rev 217)
+++ pymoul/trunk/src/moul/__init__.py 2007-02-28 12:13:59 UTC (rev 218)
@@ -12,3 +12,4 @@
except ImportError:
for p in __path__:
modulefinder.AddPackagePath(__name__, p)
+
Modified: pymoul/trunk/src/moul/crypt/binary.py
===================================================================
--- pymoul/trunk/src/moul/crypt/binary.py 2007-02-28 12:10:44 UTC (rev 217)
+++ pymoul/trunk/src/moul/crypt/binary.py 2007-02-28 12:13:59 UTC (rev 218)
@@ -21,241 +21,30 @@
__version__ = "$Id"
__revision__ = "$Revision"
+from binaryfile import BinaryFile as BaseBinaryFile
+from binaryfile.binary import AbstractString
from struct import calcsize
from struct import pack
from struct import unpack
-from moul.crypt.binaryrecord import parseRecord
-from moul.crypt.binaryrecord import registerRecord
-class BinaryFile(file):
- """Binary file
-
- A file based class with additional methods to read and write binary data.
-
- The class supports reading and writing:
- - char: readChar / writeChar
- - byte: readByte / writeByte
- - bool: readBool / writeBool
- - signed int8: read8 / write8
- - unsigned int8: read8s / write8s
- - unsigned int 16: read16 / write16
- - signed int 16: read16s / write16s
- - unsigned int 32: read32 / write32
- - signed int 32: read32s / write32s
- - unsigned int 64: read64 / write64
- - signed int 64: read64s / write64s
- - float: readFloat / writeFloat
- - double: readDouble / writeDouble
- - packed data: readPacked(fmt) / writePacked(fmt, data)
- - quad (two int16): readQuad / writeQuad)
- - NULL: read0 / write0
- - null string: readString0 / writeString0 (size is string + NULL)
- - uru string: readUruString(version), writeUruString
- - string w/ 16bit size header: readString16(null terminated) / writeString16
- - string w/ 32bit size header: readString32(null terminated) / writeString32
+class BinaryFile(BaseBinaryFile):
+ """Binary file with suport for Uru String
- For conveniance the class has a size() method
-
- The class is using some optimization tricks like binding functions to the
- local namespace of a method.
+ - uru string: readUruString(version), writeUruString
"""
- def __new__(cls, fname, mode='rb'):
- assert 'b' in mode
- self = file.__new__(cls, fname, mode)
- self.NULL = '\x00'
- return self
-
- def size(self):
- pos = self.tell()
- try:
- self.seek(0, 2)
- return self.tell()
- finally:
- self.seek(pos)
-
- def readChar(self, _unpack=unpack):
- return _unpack('<c', self.read(1))[0]
-
- def readByte(self, _unpack=unpack):
- return _unpack('<B',self.read(1))[0]
-
- def readBool(self, _unpack=unpack):
- return bool(_unpack('<B', self.read(1))[0])
-
- def read8(self, _unpack=unpack):
- return _unpack('<B', self.read(1))[0]
-
- def read8s(self, _unpack=unpack):
- return _unpack('<b', self.read(1))[0]
-
- def read16(self, _unpack=unpack):
- return _unpack('<H', self.read(2))[0]
-
- def read16s(self, _unpack=unpack):
- return _unpack('<h', self.read(2))[0]
-
- def read32(self, _unpack=unpack):
- return _unpack('<I', self.read(4))[0]
-
- def read32s(self, _unpack=unpack):
- return _unpack('<i', self.read(4))[0]
-
- def read64(self, _unpack=unpack):
- return _unpack('<Q', self.read(8))[0]
-
- def read64s(self, _unpack=unpack):
- return _unpack('<q',self.read(8))[0]
-
- def readQuad(self, _unpack=unpack):
- return _unpack('<2I', self.read(8))
-
- def readFloat(self, _unpack=unpack):
- return _unpack('<f', self.read(4))[0]
-
- def readDouble(self, _unpack=unpack):
- return _unpack('<d', self.read(8))[0]
-
- def readPacked(self, fmt, _unpack=unpack):
- return unpack(fmt, self.read(calcsize(fmt)))
-
- def read0(self):
- null = self.read(1)
- if null != self.NULL:
- raise ValueError("%s != NULL at %i" % (null, self.tell()-1))
- return null
-
def readUruString(self, version=5):
return UruString('', version=version).readfd(self)
- def readString0(self, size):
- s = self.read(size-1)
- self.read0()
- return s
-
- def readString16(self, terminate=False):
- return String16('', terminate=terminate).readfd(self)
-
- def readString32(self, terminate=False):
- return String32('', terminate=terminate).readfd(self)
-
- def readRecord(self, name):
- return parseRecord(name, self)
-
- @staticmethod
- def registerRecord(name, fmt):
- return registerRecord(name, fmt)
-
- #write
- def writeChar(self, data, _pack=pack):
- self.write(_pack('<c', data))
-
- def writeByte(self, data, _pack=pack):
- self.write(_pack('<B', data))
-
- def writeBool(self, data, _pack=pack):
- self.write(_pack('<B', bool(data)))
-
- def write8(self, data, _pack=pack):
- self.write(_pack('<B', data))
-
- def write8s(self, data, _pack=pack):
- self.write(_pack('<b', data))
-
- def write16(self, data, _pack=pack):
- self.write(_pack('<H', data))
-
- def write16s(self, data, _pack=pack):
- self.write(_pack('<h', data))
-
- def write32(self, data, _pack=pack):
- self.write(_pack('<I', data))
-
- def write32s(self, data, _pack=pack):
- self.write(_pack('<i', data))
-
- def write64(self, data, _pack=pack):
- self.write(_pack('<Q', data))
-
- def write64s(self, data, _pack=pack):
- self.write(_pack('<q', data))
-
- def writeQuad(self, tupl, _pack=pack):
- self.write(_pack('<2I', *tupl))
-
- def writeFloat(self, data, _pack=pack):
- self.write(_pack('<f', data))
-
- def writeDouble(self, data, _pack=pack):
- self.write(_pack('<d', data))
-
- def write0(self):
- self.write(self.NULL)
-
- def writeString0(self, s):
- self.write(s)
- self.write0()
-
- def writePacked(self, data, fmt):
- self.write(pack(fmt, data))
-
def writeUruString(self, data, version=5):
UruString(data, version=version).writefd(self)
- def writeString16(self, data, terminate=False):
- String16(data, terminate=terminate).writefd(self)
-
- def writeString32(self, data, terminate=False):
- String32(data, terminate=terminate).writefd(self)
-
- def writeRecord(self, rec):
- self.write(rec.read())
-
-class AbstractString(object):
- """Abstract string class
- """
- def __init__(self, s=''):
- self._data = s
-
- def readfd(self, fd):
- raise NotImplementedError
-
- def writefd(self, fd):
- raise NotImplementedError
-
- def clear(self):
- """Clear data
- """
- self._data = ''
-
- def set(self, urustr):
- """Replace current data with urustr
- """
- self._data = urustr
-
- def __repr__(self):
- """repr(self)
- """
- return ("<%s at %x (%i)" % (self.__class__.__name__, id(self),
- len(self)))
-
- def __len__(self):
- """len(self)
- """
- return len(self._data)
-
- def __cmp__(self, other):
- if isinstance(other, AbstractString):
- return cmp(self._data, other._data)
- else:
- return cmp(self._data, other)
-
class UruString(AbstractString):
"""Uru Safe String
-
+
The algorithm is based on Alcug's Ustr. This version is optimized to
copy and convert as less data as possible.
-
+
version 0 - normal str
version 1 - auto (normal/inverted)
version 5 - inverted
@@ -329,51 +118,3 @@
result = fd.read(size)
self._data = result
return result
-
-class String32(AbstractString):
- """String with 32 bit size header
- """
- def __init__(self, s='', terminate=False):
- AbstractString.__init__(self, s)
- self._terminate = bool(terminate)
-
- def readfd(self, fd):
- size = fd.read32()
- if self._terminate:
- self._data = fd.readString0(size)
- else:
- self._data = fd.read(size)
- return self._data
-
- def writefd(self, fd):
- size = len(self)
- if self._terminate:
- fd.write32(size+1)
- fd.writeString0(self._data)
- else:
- fd.write32(size)
- fd.write(self._data)
-
-class String16(AbstractString):
- """String with 16 bit size header
- """
- def __init__(self, s='', terminate=False):
- AbstractString.__init__(self, s)
- self._terminate = bool(terminate)
-
- def readfd(self, fd):
- size = fd.read16()
- if self._terminate:
- self._data = fd.readString0(size)
- else:
- self._data = fd.read(size)
- return self._data
-
- def writefd(self, fd):
- size = len(self)
- if self._terminate:
- fd.write16(size+1)
- fd.writeString0(self._data)
- else:
- fd.write16(size)
- fd.write(self._data)
Deleted: pymoul/trunk/src/moul/crypt/binaryrecord.py
===================================================================
--- pymoul/trunk/src/moul/crypt/binaryrecord.py 2007-02-28 12:10:44 UTC (rev 217)
+++ pymoul/trunk/src/moul/crypt/binaryrecord.py 2007-02-28 12:13:59 UTC (rev 218)
@@ -1,170 +0,0 @@
-# pyMoul - Python interface to Myst Online URU Live
-# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de>
-
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
-# option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc., 59
-# Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-"""Binary file helper: Records
-
-This module is roughly based on Maciej Obarski's recipe "parse and create
-fixed size binary data" from
-http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/465219
-"""
-__author__ = "Christian Heimes"
-__version__ = "$Id"
-__revision__ = "$Revision"
-
-from struct import calcsize
-from struct import pack
-from struct import unpack
-
-_marker = object()
-
-class RecordRegistry(dict):
- """Registry for record definitions
- """
- __slots__ = ()
- def register(self, name, fmt):
- """Register a format by name
-
- @param name: name of the format
- @type name: str
- @param fmt: a record format
- @type fmt: str
-
- Example:
- >>> reg = RecordRegistry()
- >>> registerRecord = reg.register
- >>> parseRecord = reg.parse
- >>> obj = registerRecord("connection", "4B.ip >H.port >I.session_id")
- >>> isinstance(obj, RecordDefinition)
- True
- >>> data = "\\xc0\\xa8\\x00\\x01" + "\\x00P" + "\\xFE\\xDC\\xBA\\x98"
-
- >>> rec = parseRecord("connection", data)
- >>> rec.ip
- (192, 168, 0, 1)
- >>> rec.port
- 80
- >>> rec.session_id
- 4275878552L
- >>> rec.read() == data or rec.read()
- True
- """
- if name in self:
- raise NameError("%s already registered!" % name)
- self[name] = RecordDefinition(name, fmt)
- return self[name]
-
- def parse(self, name, fd_data):
- """Parse data using the RecordDefinition 'name'
-
- @param name: name of the format
- @type name: str
- @param fd_data: data to parse: either a string or an open file
- @type fd_data: str or file
- """
- return self[name](fd_data)
-
-class RecordDefinition(object):
- """A record definition
- """
- __slots__ = ('_fields', '_recordsize', '_name')
-
- def __init__(self, name, recordfmt):
- self._name = name
- self._fields = []
- pos = 0
- for field in recordfmt.split():
- if field.startswith('#'):
- continue
- fmt, name = field.split('.')
- if '#' in name:
- name = name.split('#')[0]
- name = name.strip()
- size = calcsize(fmt)
- self._fields.append((name, fmt, pos, pos+size))
- pos += size
-
- self._recordsize = pos
-
- @property
- def name(self):
- return self._name
-
- @property
- def size(self):
- return self._recordsize
-
- def __call__(self, fd_data):
- """Parse data using the format string
-
- @param fd_data: data to parse: either a string or an open file
- @type fd_data: str or file
- """
- if isinstance(fd_data, basestring):
- # handle string
- data = fd_data
- elif hasattr(fd_data, 'read'):
- data = fd_data.read(self._recordsize)
- else:
- raise TypeError(type(fd_data))
- if len(data) != self._recordsize:
- raise ValueError("Data has wrong size: %i, required: %i" %
- (len(data), self._recordsize))
- return Record(self._fields, data)
-
-class Record(object):
- __slots__ = ('_fields', '_data')
-
- def __init__(self, fields, data=None):
- self._fields = fields
- self._data = {}
- if data is not None:
- self.write(data)
-
- def write(self, data):
- """Write data
-
- Creates the instance attributes defined in fmt
- """
- for name, fmt, start, stop in self._fields:
- value = unpack(fmt, data[start:stop])
- if len(value) == 1:
- value = value[0]
- self._data[name] = value
-
- def read(self):
- """Convert data to binary string
- """
- result = []
- for name, fmt, start, stop in self._fields:
- value = self._data[name]
- if not isinstance(value, (tuple, list)):
- value = (value,)
- result.append(pack(fmt, *value))
- return ''.join(result)
-
- def __getattr__(self, name, default=_marker):
- value = self._data.get(name, default)
- if value is _marker:
- raise AttributeError(name)
- return value
-
- def __str__(self):
- return self.read()
-
-_recordRegistry = RecordRegistry()
-registerRecord = _recordRegistry.register
-parseRecord = _recordRegistry.parse
Deleted: pymoul/trunk/src/moul/crypt/tests/test_binary.py
===================================================================
--- pymoul/trunk/src/moul/crypt/tests/test_binary.py 2007-02-28 12:10:44 UTC (rev 217)
+++ pymoul/trunk/src/moul/crypt/tests/test_binary.py 2007-02-28 12:13:59 UTC (rev 218)
@@ -1,148 +0,0 @@
-# pyMoul - Python interface to Myst Online URU Live
-# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de>
-
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
-# option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc., 59
-# Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-"""moul.crypt.binary unit tests
-"""
-__author__ = "Christian Heimes"
-__version__ = "$Id$"
-__revision__ = "$Revision$"
-
-import os
-import unittest
-from doctest import DocTestSuite
-from tempfile import mkstemp
-
-from moul.crypt.binary import BinaryFile
-
-class BinaryFileTest(unittest.TestCase):
- def setUp(self):
- self.tmpname = mkstemp()[1]
- self.b = BinaryFile(self.tmpname, 'wb+')
-
- def tearDown(self):
- self.b.close()
- os.unlink(self.tmpname)
-
- def _testrw(self, name, data):
- #import pdb; pdb.set_trace()
- read = getattr(self.b, 'read%s' % name)
- write = getattr(self.b, 'write%s' % name)
- write(data)
- self.b.seek(0)
- fdata = read()
- self.failUnlessEqual(data, fdata)
-
- def test_char(self):
- self._testrw('Char', 'a')
-
- def test_byte(self):
- self._testrw('Byte', 127)
-
- def test_bool(self):
- self._testrw('Bool', True)
-
- def test_8(self):
- self._testrw('8', 42)
-
- def test_8s(self):
- self._testrw('8s', -42)
-
- def test_16(self):
- self._testrw('16', 2**15)
-
- def test_16s(self):
- self._testrw('16s', -2**15)
-
- def test_32(self):
- self._testrw('32', 2*31)
-
- def test_32s(self):
- self._testrw('32s', -2*31)
-
- def test_64(self):
- self._testrw('64', 2*63)
-
- def test_64s(self):
- self._testrw('64s', -2*63)
-
- def test_float(self):
- data = -0.07
- self.b.writeFloat(data)
- self.b.seek(0)
- self.failUnlessAlmostEqual(data, self.b.readFloat())
-
- def test_double(self):
- self._testrw('Double', -23*10e200)
-
- def test_quad(self):
- data = (23, 42)
- self.b.writeQuad(data)
- self.b.seek(0)
- self.failUnlessEqual(data, self.b.readQuad())
-
- def test_urustring(self):
- # XXX: no test data
- pass
-
- def test_string0(self):
- s = "a test string"
- l = len(s)
- self.b.writeString0(s)
- self.b.seek(0)
- self.failUnlessEqual(self.b.size(), l+1)
- self.failUnlessEqual(self.b.readString0(l+1), s)
- self.b.seek(0)
- self.failUnlessEqual(self.b.read(), s+'\x00')
-
- def test_string16(self):
- s = "a test string"
- l = len(s)
- self.b.writeString16(s, terminate=False)
- self.b.seek(0)
- self.failUnlessEqual(self.b.size(), l+2)
- self.failUnlessEqual(self.b.readString16(terminate=False), s)
-
- self.b.seek(0)
- self.b.truncate(0)
- self.b.writeString16(s, terminate=True)
- self.b.seek(0)
- self.failUnlessEqual(self.b.size(), l+3)
- self.failUnlessEqual(self.b.readString16(terminate=True), s)
-
- def test_string32(self):
- s = "a test string"
- l = len(s)
- self.b.writeString32(s, terminate=False)
- self.b.seek(0)
- self.failUnlessEqual(self.b.size(), l+4)
- self.failUnlessEqual(self.b.readString32(terminate=False), s)
-
- self.b.seek(0)
- self.b.truncate(0)
- self.b.writeString32(s, terminate=True)
- self.b.seek(0)
- self.failUnlessEqual(self.b.size(), l+5)
- self.failUnlessEqual(self.b.readString32(terminate=True), s)
-
-
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(BinaryFileTest),
- ))
-
-if __name__ == '__main__':
- unittest.main(defaultTest="test_suite")
Deleted: pymoul/trunk/src/moul/crypt/tests/test_binaryrecord.py
===================================================================
--- pymoul/trunk/src/moul/crypt/tests/test_binaryrecord.py 2007-02-28 12:10:44 UTC (rev 217)
+++ pymoul/trunk/src/moul/crypt/tests/test_binaryrecord.py 2007-02-28 12:13:59 UTC (rev 218)
@@ -1,38 +0,0 @@
-# pyMoul - Python interface to Myst Online URU Live
-# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de>
-
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
-# option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc., 59
-# Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-"""moul.crypt.binaryrecord unit tests
-"""
-__author__ = "Christian Heimes"
-__version__ = "$Id$"
-__revision__ = "$Revision$"
-
-import os
-import unittest
-from doctest import DocTestSuite
-
-import moul.crypt.binaryrecord
-
-def test_suite():
- return unittest.TestSuite((
- DocTestSuite('moul.crypt.binaryrecord'),
- ))
-
-if __name__ == '__main__':
- unittest.main(defaultTest="test_suite")
-
-
Modified: pymoul/trunk/src/moul/crypt/tests/test_wdys.py
===================================================================
--- pymoul/trunk/src/moul/crypt/tests/test_wdys.py 2007-02-28 12:10:44 UTC (rev 217)
+++ pymoul/trunk/src/moul/crypt/tests/test_wdys.py 2007-02-28 12:13:59 UTC (rev 218)
@@ -64,7 +64,6 @@
return unittest.TestSuite((
unittest.makeSuite(WDYSTest),
DocTestSuite('moul.crypt.whatdoyousee'),
- DocTestSuite('moul.crypt.xtea'),
))
if __name__ == '__main__':
Modified: pymoul/trunk/src/moul/crypt/whatdoyousee.py
===================================================================
--- pymoul/trunk/src/moul/crypt/whatdoyousee.py 2007-02-28 12:10:44 UTC (rev 217)
+++ pymoul/trunk/src/moul/crypt/whatdoyousee.py 2007-02-28 12:13:59 UTC (rev 218)
@@ -32,8 +32,8 @@
from logging import getLogger
from moul.crypt.binary import BinaryFile
-from moul.crypt.xtea import xtea_decrypt
-from moul.crypt.xtea import xtea_encrypt
+from xtea import xtea_decrypt
+from xtea import xtea_encrypt
HEADER = "whatdoyousee"
@@ -87,7 +87,7 @@
instr = instr.replace("\n", "\r\n")
fout.seek(0)
fout.write(HEADER)
-
+
flen = len(instr)
length = struct.pack(ENDIAN+"L", flen)
fout.write(length)
Deleted: pymoul/trunk/src/moul/crypt/xtea.py
===================================================================
--- pymoul/trunk/src/moul/crypt/xtea.py 2007-02-28 12:10:44 UTC (rev 217)
+++ pymoul/trunk/src/moul/crypt/xtea.py 2007-02-28 12:13:59 UTC (rev 218)
@@ -1,104 +0,0 @@
-"""XTEA Block Encryption Algorithm
-
-Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com)
-License: Public Domain
-
-Modified by Christian Heimes to add an endian switch.
-
-This module provides a Python implementation of the XTEA block encryption
-algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf).
-
-The module implements the basic XTEA block encryption algortithm
-(`xtea_encrypt`/`xtea_decrypt`) and also provides a higher level `crypt`
-function which symmetrically encrypts/decrypts a variable length string using
-XTEA in OFB mode as a key generator. The `crypt` function does not use
-`xtea_decrypt` which is provided for completeness only (but can be used
-to support other stream modes - eg CBC/CFB).
-
-This module is intended to provide a simple 'privacy-grade' Python encryption
-algorithm with no external dependencies. The implementation is relatively slow
-and is best suited to small volumes of data. Note that the XTEA algorithm has
-not been subjected to extensive analysis (though is believed to be relatively
-secure - see http://en.wikipedia.org/wiki/XTEA). For applications requiring
-'real' security please use a known and well tested algorithm/implementation.
-
-The security of the algorithm is entirely based on quality (entropy) and
-secrecy of the key. You should generate the key from a known random source and
-exchange using a trusted mechanism. In addition, you should always use a random
-IV to seed the key generator (the IV is not sensitive and does not need to be
-exchanged securely)
-
- >>> import os
- >>> iv = 'ABCDEFGH'
- >>> z = crypt('0123456789012345','Hello There',iv)
- >>> z.encode('hex')
- 'fe196d0a40d6c222b9eff3'
- >>> crypt('0123456789012345',z,iv)
- 'Hello There'
-
-"""
-import struct
-
-
-def crypt(key,data,iv='\00\00\00\00\00\00\00\00',n=32,endian="!"):
- """
- Encrypt/decrypt variable length string using XTEA cypher as
- key generator (OFB mode)
- * key = 128 bit (16 char) / iv = 64 bit (8 char)
- * data = string (any length)
-
- >>> import os
- >>> key = os.urandom(16)
- >>> iv = os.urandom(8)
- >>> data = os.urandom(10000)
- >>> z = crypt(key,data,iv)
- >>> crypt(key,z,iv) == data
- True
-
- """
- def keygen(key,iv,n):
- while True:
- iv = xtea_encrypt(key,iv,n,endian)
- for k in iv:
- yield ord(k)
- xor = [ chr(x^y) for (x,y) in zip(map(ord,data),keygen(key,iv,n)) ]
- return "".join(xor)
-
-def xtea_encrypt(key,block,n=32, endian="!"):
- """
- Encrypt 64 bit data block using XTEA block cypher
- * key = 128 bit (16 char) / block = 64 bit (8 char)
-
- >>> xtea_encrypt('0123456789012345','ABCDEFGH').encode('hex')
- 'b67c01662ff6964a'
- """
- v0,v1 = struct.unpack(endian+"2L",block)
- k = struct.unpack(endian+"4L",key)
- sum,delta,mask = 0L,0x9e3779b9L,0xffffffffL
- for round in range(n):
- v0 = (v0 + (((v1<<4 ^ v1>>5) + v1) ^ (sum + k[sum & 3]))) & mask
- sum = (sum + delta) & mask
- v1 = (v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + k[sum>>11 & 3]))) & mask
- return struct.pack(endian+"2L",v0,v1)
-
-def xtea_decrypt(key,block,n=32, endian="!"):
- """
- Decrypt 64 bit data block using XTEA block cypher
- * key = 128 bit (16 char) / block = 64 bit (8 char)
-
- >>> xtea_decrypt('0123456789012345','b67c01662ff6964a'.decode('hex'))
- 'ABCDEFGH'
- """
- v0,v1 = struct.unpack(endian+"2L",block)
- k = struct.unpack(endian+"4L",key)
- delta,mask = 0x9e3779b9L,0xffffffffL
- sum = (delta * n) & mask
- for round in range(n):
- v1 = (v1 - (((v0<<4 ^ v0>>5) + v0) ^ (sum + k[sum>>11 & 3]))) & mask
- sum = (sum - delta) & mask
- v0 = (v0 - (((v1<<4 ^ v1>>5) + v1) ^ (sum + k[sum & 3]))) & mask
- return struct.pack(endian+"2L",v0,v1)
-
-if __name__ == "__main__":
- import doctest
- doctest.testmod()
\ No newline at end of file
Deleted: pymoul/trunk/src/moul/osdependent/tests/test_processinfo.py
===================================================================
--- pymoul/trunk/src/moul/osdependent/tests/test_processinfo.py 2007-02-28 12:10:44 UTC (rev 217)
+++ pymoul/trunk/src/moul/osdependent/tests/test_processinfo.py 2007-02-28 12:13:59 UTC (rev 218)
@@ -1,37 +0,0 @@
-# pyMoul - Python interface to Myst Online URU Live
-# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de>
-
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by the
-# Free Software Foundation; either version 2 of the License, or (at your
-# option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc., 59
-# Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-"""moul.osdependent.processinfo
-"""
-__author__ = "Christian Heimes"
-__version__ = "$Id$"
-__revision__ = "$Revision$"
-
-import unittest
-from doctest import DocTestSuite
-
-import moul.osdependent.processinfo
-
-
-def test_suite():
- return unittest.TestSuite((
- DocTestSuite('moul.osdependent.processinfo'),
- ))
-
-if __name__ == '__main__':
- unittest.main(defaultTest="test_suite")
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|