Skip to main content

Redacting classified documents

Project description

redacted-py

Redacting classified documents

GitHub tag (latest by date) GitHub last commit GitHub issues GitHub license PyPI - Version

This repository holds the code base for my redacted-py library in Python.
It is mainly based off my Feistel cipher for Format-Preserving Encryption to which I added a few tools to handle document, database and file manipulation to ease out the operation.

Motivation

In some fields (like healthcare for instance), protecting the privacy of data whilst being able to conduct in-depth studies is both vital and mandatory. Redacting documents and databases is therefore the obligatory passage. With redacted-py, I provide a simple yet secure tool to help redacting documents based on either a dictionary, a record layout or a tag to decide which parts should actually be redacted.

Usage

You can use either a dictionary or a tag (or both) to identify the words you want to redact in a document. The tag should be placed before any word that should be redacted. The default tag is the tilde character (~).

For example, the following sentence will only see the word tagged redacted: "This is a ~tagged sentence".

$ pip install redacted-py
from redacted import DefaultRedactor, Dictionary
from feistel import FPECipher, SHA_256

source = "Some text ~tagged or using words in a dictionary"

cipher = FPECipher(SHA_256, key, 10)
redactor = DefaultRedactor(cipher)
redacted = redactor.redact(source)

expanded = redactor.expand(redacted)
assert expanded == source, "Original data should equal ciphered then deciphered data"

cleansed = redactor.clean(expanded)
assert cleansed == "Some text tagged or using words in a dictionary", "Cleaning should remove any tag mark"

You may also use it in the console with the following command line instructions:

usage: python3 -m redacted [-h] [-b | --both | --no-both] [-d DICTIONARY] [-H HASH] [-i INPUT] [-k KEY] [-o OUTPUT] [-r ROUNDS] [-t TAG] [-x | --expand | --no-expand]

options:
  -h, --help            show this help message and exit
  -b, --both, --no-both
                        Add to use both dictionary and tag
  -d DICTIONARY, --dictionary DICTIONARY
                        The optional path to the dictionary of words to redact
  -H HASH, --hash HASH  The hash engine for the round function [default sha-256]
  -i INPUT, --input INPUT
                        The path to the document to be redacted
  -k KEY, --key KEY     The optional key for the FPE scheme (leave it empty to use default)
  -o OUTPUT, --output OUTPUT
                        The name of the output file
  -r ROUNDS, --rounds ROUNDS
                        The number of rounds for the Feistel cipher [default 10]
  -t TAG, --tag TAG     The optional tag that prefixes words to redact [default ~]
  -x, --expand, --no-expand
                        Add to expand a redacted document

Tests

$ git clone https://github.com/cyrildever/redacted.git
$ cd redacted/py/
$ pip install -e .
$ python3 -m unittest discover

License

The use of the redacted libraries and executables are subject to fees for commercial purpose and to the respect of the BSD-2-Clause-Patent license.
Please contact me to get further information.

NB: It is still under development so use in production at your own risk for now.


© 2024-2026 Cyril Dever. All rights reserved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redacted_py-1.0.11.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redacted_py-1.0.11-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file redacted_py-1.0.11.tar.gz.

File metadata

  • Download URL: redacted_py-1.0.11.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.2

File hashes

Hashes for redacted_py-1.0.11.tar.gz
Algorithm Hash digest
SHA256 08c17a943a07a7274510b8c3ac42b1361c781a55768252d9dab2353f27d6b953
MD5 16ebb401f1bc5eec9f2d8a51af2b11f4
BLAKE2b-256 c13007747f85822991951306e8f7097ebae78e3751439637ec52752f3d2618e5

See more details on using hashes here.

File details

Details for the file redacted_py-1.0.11-py3-none-any.whl.

File metadata

  • Download URL: redacted_py-1.0.11-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.2

File hashes

Hashes for redacted_py-1.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 95f6af0e364c5d4e475cfb0667dc5785767172d7bb25379141c0ae30d85232ba
MD5 10274cefe2e3370ac7ad99b4cd4eb90d
BLAKE2b-256 8c7a0ef5c36a86f0b7af31f47d33908e83a5923dd05a134db47c656b5f4ac6d1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page