{"id":8476,"library":"pydes","title":"pyDes","description":"pyDes is a pure Python implementation of the DES and Triple-DES encryption algorithms. It is designed for portability across Python versions rather than performance, making it suitable for simple, small-scale encryption tasks. The current version, 2.0.1, was released on April 28, 2010, and the project is no longer actively maintained.","status":"abandoned","version":"2.0.1","language":"python","source_language":"en","source_url":"https://github.com/twhiteman/pyDes","tags":["encryption","DES","cryptography","security"],"install":[{"cmd":"pip install pyDes","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"wrong":"import pyDes","symbol":"des","correct":"from pyDes import des"},{"wrong":"import pyDes","symbol":"triple_des","correct":"from pyDes import triple_des"},{"wrong":"import pyDes","symbol":"CBC","correct":"from pyDes import CBC"}],"quickstart":{"code":"import pyDes\n\n# For Python 3, all strings must be converted to bytes\n# For DES, key must be exactly 8 bytes\n# For Triple DES, key must be 16 or 24 bytes\n# IV (Initialization Vector) must be 8 bytes for CBC mode\n\nkey_des = b\"DESCRYPT\"\nkey_3des_2key = b\"0123456789ABCDEF\"\nkey_3des_3key = b\"0123456789ABCDEFabcdefgh\"\n\ndata = b\"Please encrypt my data. It needs to be padded.\"\n\n# --- Single DES Example (CBC mode, PKCS5 padding) ---\ntry:\n    # DES encryption object\n    k_des = pyDes.des(key_des, pyDes.CBC, b\"\\0\\0\\0\\0\\0\\0\\0\\0\", pad=None, padmode=pyDes.PAD_PKCS5)\n    encrypted_des = k_des.encrypt(data)\n    print(f\"Encrypted DES: {encrypted_des!r}\")\n    decrypted_des = k_des.decrypt(encrypted_des)\n    print(f\"Decrypted DES: {decrypted_des!r}\")\n    assert decrypted_des == data\nexcept ValueError as e:\n    print(f\"DES Error: {e}\")\n\n# --- Triple DES Example (2-Key, CBC mode, PKCS5 padding) ---\ntry:\n    # Triple DES encryption object (2-key)\n    k_3des_2key = pyDes.triple_des(key_3des_2key, pyDes.CBC, b\"\\0\\0\\0\\0\\0\\0\\0\\0\", pad=None, padmode=pyDes.PAD_PKCS5)\n    encrypted_3des_2key = k_3des_2key.encrypt(data)\n    print(f\"Encrypted 3DES (2-key): {encrypted_3des_2key!r}\")\n    decrypted_3des_2key = k_3des_2key.decrypt(encrypted_3des_2key)\n    print(f\"Decrypted 3DES (2-key): {decrypted_3des_2key!r}\")\n    assert decrypted_3des_2key == data\nexcept ValueError as e:\n    print(f\"3DES (2-key) Error: {e}\")\n\n# --- Triple DES Example (3-Key, ECB mode, PKCS5 padding) ---\ntry:\n    # Triple DES encryption object (3-key)\n    k_3des_3key = pyDes.triple_des(key_3des_3key, pyDes.ECB, pad=None, padmode=pyDes.PAD_PKCS5)\n    encrypted_3des_3key = k_3des_3key.encrypt(data)\n    print(f\"Encrypted 3DES (3-key): {encrypted_3des_3key!r}\")\n    decrypted_3des_3key = k_3des_3key.decrypt(encrypted_3des_3key)\n    print(f\"Decrypted 3DES (3-key): {decrypted_3des_3key!r}\")\n    assert decrypted_3des_3key == data\nexcept ValueError as e:\n    print(f\"3DES (3-key) Error: {e}\")","lang":"python","description":"This quickstart demonstrates basic DES and Triple DES encryption and decryption using pyDes. It highlights the necessity of using byte strings for keys, IVs, and data in Python 3, and the recommended practice of using PKCS5 padding. Separate examples are provided for DES and different Triple DES key lengths."},"warnings":[{"fix":"Ensure all `key`, `IV`, and `data` arguments are byte strings (e.g., `b\"mydata\"`). Encode regular strings using `.encode('utf-8')` and decode results with `.decode('utf-8')` if text is required.","message":"Python 2 vs. Python 3 string handling: pyDes expects bytes for all key, IV, and data arguments. In Python 2, `str` was implicitly bytes, but in Python 3, explicit byte strings (`b\"...\"`) must be used. Passing regular Python 3 strings will lead to `TypeError` or `ValueError`.","severity":"breaking","affected_versions":"All versions when migrating from Python 2 to Python 3"},{"fix":"Always ensure the provided key has the exact required length in bytes for the chosen DES or Triple DES algorithm.","message":"Key length requirements: DES requires an 8-byte key. Triple DES requires either a 16-byte key (DES-EDE2) or a 24-byte key (DES-EDE3). Providing an incorrect key length will raise a `ValueError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `padmode=pyDes.PAD_PKCS5` when initializing `des` or `triple_des` instances. If not using PKCS5, ensure data length is a multiple of 8 or manually apply a consistent padding scheme.","message":"Data padding is crucial: Encryption/decryption operates on 8-byte blocks. If input data is not a multiple of 8 bytes, it must be padded. Failure to pad, or incorrect padding, leads to `ValueError: Data must be a multiple of 8 bytes in length.` The recommended padding mode is `pyDes.PAD_PKCS5` as it is unambiguously reversible.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Avoid using DES or Triple DES for new applications. Consider modern encryption algorithms like AES (e.g., via `cryptography` library) with appropriate modes (e.g., GCM or CBC with a strong IV). If you must use pyDes, always prefer `pyDes.CBC` mode with a unique, random IV for each encryption.","message":"Security vulnerability: DES and Triple DES (3DES) are cryptographically weak and considered obsolete for modern security requirements due to short key lengths and susceptibility to various attacks. The default ECB mode is particularly insecure as it leaks patterns in the plaintext.","severity":"deprecated","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'2.0.1':41 '2010':47 '28':46 'across':22 'activ':54 'algorithm':16 'april':45 'cryptographi':58 'current':39 'des':10,14,57 'design':19 'encrypt':15,36,56 'implement':7 'longer':53 'maintain':55 'make':28 'perform':27 'portabl':21 'project':50 'pure':5 'pyde':1,2 'python':6,23 'rather':25 'releas':43 'scale':35 'secur':59 'simpl':32 'small':34 'small-scal':33 'suitabl':30 'task':37 'tripl':13 'triple-d':12 'version':24,40","created_at":"2026-04-16T17:02:23.575589+00:00","updated_at":"2026-04-16T17:02:23.575589+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.0.1","cli_name":"","cli_version":null,"type":"library","homepage":"http://twhiteman.netfirms.com/des.html","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/pydes/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["auth-security","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-06-30","next_check":"2026-07-30","install_tag":null}}