Skip to main content

Elegant xor encryption in Python

Project description

# xor_string

![PyPI downloads](https://img.shields.io/pypi/dm/xor_string.svg) ![PyPI version](https://img.shields.io/pypi/v/xor_string.svg) ![PyPI python version](https://img.shields.io/pypi/pyversions/xor_string.svg)

Python doesn't support (natively) XOR on everything else than int, and this is annoying.

```
>>> 'hello' ^ 'world'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for ^: 'str' and 'str'
```

Fortunately, Python has the (amazing) itertools module.

## unit tests
* `nosetests -v`

## Explanations

For those who are not familiar with python:

* cycle(key) returns an iterator that produces an infinite concatenation of key's content
* izip(a, b) returns an iterator that aggregates elements from each of the iterables. It stops on the shortest input sequence (here, our message, since cycle(key) is infinite
* ord(a) and chr(57) return (respectively) the integer representing the given char and the char represented by the given integer.
* ''.join() (roughly) concatenate every items of the list passed in argument in a string

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

xor_string-0.2.2.tar.gz (3.1 kB view details)

Uploaded Source

File details

Details for the file xor_string-0.2.2.tar.gz.

File metadata

  • Download URL: xor_string-0.2.2.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for xor_string-0.2.2.tar.gz
Algorithm Hash digest
SHA256 b07f67e6754551e74150b3923d5f1fc96a4ce49079c6195faabc7ed882969ab2
MD5 76f07d5135e074fb80ee17f46cde2e17
BLAKE2b-256 784842c48b03a3b046b5e5677d337376f23a6e4b276db8907507e9110086b8b6

See more details on using hashes here.

Supported by

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