{"id":23204724,"url":"https://github.com/crmin/pypadding","last_synced_at":"2025-11-06T22:30:27.050Z","repository":{"id":62582372,"uuid":"148594720","full_name":"crmin/pypadding","owner":"crmin","description":"Padding functions when use encrypt using block crypto function","archived":false,"fork":false,"pushed_at":"2018-09-20T09:19:26.000Z","size":22,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-11T08:49:19.303Z","etag":null,"topics":["cryptography-tools","python3"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crmin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-13T06:50:48.000Z","updated_at":"2020-12-04T11:55:05.000Z","dependencies_parsed_at":"2022-11-03T21:22:01.660Z","dependency_job_id":null,"html_url":"https://github.com/crmin/pypadding","commit_stats":null,"previous_names":["blinglnav/pypadding"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crmin%2Fpypadding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crmin%2Fpypadding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crmin%2Fpypadding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crmin%2Fpypadding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crmin","download_url":"https://codeload.github.com/crmin/pypadding/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239513378,"owners_count":19651322,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptography-tools","python3"],"created_at":"2024-12-18T16:19:54.182Z","updated_at":"2025-11-06T22:30:26.996Z","avatar_url":"https://github.com/crmin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyPadding\n\n[![Build Status](https://travis-ci.org/blinglnav/pypadding.svg?branch=master)](https://travis-ci.org/blinglnav/pypadding)\n\nThis package implements padding methods to use block crypto function.\n\n## Dependencies\n\n* Python 3+\n\n## Usage\n\n### PKCS#5 / PKCS#7\n* pypadding.pkcs\n* Fill using number of padding number\n* e.g. When block size is 8, b'hello' need 3 bytes to multiple of block size --\u003e fill using `b'\\x03'` (`b'hello\\x03\\x03\\x03'`)\n\n```python\n\u003e\u003e\u003e from pypadding import pkcs\n\u003e\u003e\u003e encoder = pkcs.Encoder()\n\u003e\u003e\u003e encoder.encode(b'hello')\nb'hello\\x03\\x03\\x03'\n\u003e\u003e\u003e encoder.decode(b'hello\\x03\\x03\\x03')\nb'hello'\n```\n\n### ANSI x923\n* pypadding.x923\n* Fill using zero(`b'\\x00'`) and last byte set to length of padding\n* e.g. When block size is 8, b'hello' need 3 bytes to multiple of block size --\u003e fill using `b'\\x00'` and last byte set to `b'\\x03'` (`b'hello\\x00\\x00\\x03'`)\n\n```python\n\u003e\u003e\u003e from pypadding import x923\n\u003e\u003e\u003e encoder = x923.Encoder()\n\u003e\u003e\u003e encoder.encode(b'hello')\nb'hello\\x00\\x00\\x03'\n\u003e\u003e\u003e encoder.decode(b'hello\\x00\\x00\\x03')\nb'hello'\n```\n\n### ISO 10126\n* pypadding.iso10126\n* Fill using random byte and last byte set to length of padding\n* e.g. When block size is 8, b'hello' need 3 bytes to multiple of block size --\u003e fill random byte and last byte set to `b'\\x03'` (`b'hello\\x85\\xaa\\x03'`)\n\n```python\n\u003e\u003e\u003e from pypadding import iso10126\n\u003e\u003e\u003e encoder = iso10126.Encoder()\n\u003e\u003e\u003e encoder.encode(b'hello')\nb'hello\\x85\\xaa\\x03'\n\u003e\u003e\u003e encoder.decode(b'hello\\x85\\xaa\\x03')\nb'hello'\n```\n\n### ISO/IEC 7816-4\n* pypadding.iso7816_4\n* Padding starts with `b'\\x80'` and fill using zero `b'\\x00'`\n* e.g. When block size is 8, b'hello' need 3 bytes to multiple of block size --\u003e fill first byte to `b'\\x80'` then fill to `b'\\x00'` (`b'hello\\x80\\x00\\x00'`)\n\n```python\n\u003e\u003e\u003e from pypadding import iso7816_4\n\u003e\u003e\u003e encoder = iso7816_4.Encoder()\n\u003e\u003e\u003e encoder.encode(b'hello')\nb'hello\\x80\\x00\\x00'\n\u003e\u003e\u003e encoder.decode(b'hello\\x80\\x00\\x00')\nb'hello'\n```\n\n## Set Block Size\n\n```python\n\u003e\u003e\u003e from pypadding import pkcs\n\u003e\u003e\u003e encoder = pkcs.Encoder(16)\n\u003e\u003e\u003e encoder.encode(b'blackjack')\nb'blackjack\\x07\\x07\\x07\\x07\\x07\\x07\\x07'\n\u003e\u003e\u003e encoder.decode(b'blackjack\\x07\\x07\\x07\\x07\\x07\\x07\\x07')\nb'blackjack'\n```\n\nor\n\n```python\n\u003e\u003e\u003e from pypadding import pkcs\n\u003e\u003e\u003e encoder = pkcs.Encoder(block_size=16)\n\u003e\u003e\u003e encoder.encode(b'blackjack')\nb'blackjack\\x07\\x07\\x07\\x07\\x07\\x07\\x07'\n\u003e\u003e\u003e encoder.decode(b'blackjack\\x07\\x07\\x07\\x07\\x07\\x07\\x07')\nb'blackjack'\n```\n\n\n## Note\n* All encoded data has padding even though length of original data is multiple of block size\n    * e.g. block size = 8, encoding w/ pkcs, `encode('computer')` --\u003e `b'computer\\x08\\x08\\x08\\x08\\x08\\x08\\x08\\x08'`\n\n\n## Reference\n* https://en.wikipedia.org/wiki/Padding_(cryptography)\n    * This package implement reversible methods only\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrmin%2Fpypadding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrmin%2Fpypadding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrmin%2Fpypadding/lists"}