pyDes

Pure python implementation of DES and TRIPLE DES encryption algorithm
Download

pyDes Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Public Domain
  • Price:
  • FREE
  • Publisher Name:
  • Todd Whiteman
  • Publisher web site:
  • http://twhiteman.netfirms.com

pyDes Tags


pyDes Description

Pure python implementation of DES and TRIPLE DES encryption algorithm pyDes is a pure Python implementation of the DES encryption algorithm. It is in pure python to avoid portability issues, since most DES implementations are programmed in C (for performance reasons).Triple DES class is also implemented, utilising the DES base. Triple DES is either DES-EDE3 with a 24 byte key, or DES-EDE2 with a 16 byte key. See the "About triple DES" section below more info on this algorithm.The code below is not written for speed or performance, so not for those needing a fast des implementation, but rather a handy portable solution ideal for small usage. It takes my AMD2000+ machine 1 second per 2.5 kilobyte to encrypt or decrypt using the DES method. Thats very SLOW!!pyDes Usage:Class initialization:pyDes.des(key, , , , )pyDes.triple_des(key, , , , )key -> Bytes containing the encryption key. 8 bytes for DES, 16 or 24 bytes for Triple DESmode -> Optional argument for encryption type, can be either pyDes.ECB (Electronic Code Book) or pyDes.CBC (Cypher Block Chaining)IV -> Optional Initial Value bytes, must be supplied if using CBC mode. Length must be 8 bytes.pad -> Optional argument, set the pad character (PAD_NORMAL) to use during all encrypt/decrpt operations done with this instance.padmode -> Optional argument, set the padding mode (PAD_NORMAL or PAD_PKCS5) to use during all encrypt/decrpt operations done with this instance.I recommend to use PAD_PKCS5 padding, as then you never need to worry about anypadding issues, as the padding can be removed unambiguously upon decryptingdata that was encrypted using PAD_PKCS5 padmode.Common methods:encrypt(data, , )decrypt(data, , )data -> Bytes to be encrypted/decryptedpad -> Optional argument. Only when using padmode of PAD_NORMAL. For encryption, adds this characters to the end of the data block when data is not a multiple of 8 bytes. For decryption, will remove the trailing characters that match this pad character from the last 8 bytes of the unencrypted data block.padmode -> Optional argument, set the padding mode, must be one of PAD_NORMAL or PAD_PKCS5). Defaults to PAD_NORMAL.Example:from pyDes import *# For Python3, you'll need to use bytes, i.e.:# data = b"Please encrypt my data"# k = des(b"DESCRYPT", CBC, b"", pad=None, padmode=PAD_PKCS5)data = "Please encrypt my data"k = des("DESCRYPT", CBC, "", pad=None, padmode=PAD_PKCS5)d = k.encrypt(data)print "Encrypted: %r" % dprint "Decrypted: %r" % k.decrypt(d)assert k.decrypt(d, padmode=PAD_PKCS5) == dataSee the module source (pyDes.py) for more examples of use.You can slo run the pyDes.py file without and arguments to see a simple test.Note: This code was not written for high-end systems needing a fast implementation, but rather a handy portable solution with small usage. Requirements: · Python


pyDes Related Software