Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

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.

Filename, size & hash SHA256 hash help File type Python version Upload date
xor_string-0.2.3.tar.gz (3.0 kB) Copy SHA256 hash SHA256 Source None Nov 2, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page