PHP 8.0.30
Preview: XOR.py Size: 2.67 KB
/opt/alt/python37/lib64/python3.7/site-packages/Crypto/Cipher/XOR.py

# -*- coding: utf-8 -*-
#
#  Cipher/XOR.py : XOR
#
# ===================================================================
# The contents of this file are dedicated to the public domain.  To
# the extent that dedication to the public domain is not available,
# everyone is granted a worldwide, perpetual, royalty-free,
# non-exclusive license to exercise all rights associated with the
# contents of this file for any purpose whatsoever.
# No rights are reserved.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# ===================================================================
"""XOR toy cipher

XOR is one the simplest stream ciphers. Encryption and decryption are
performed by XOR-ing data with a keystream made by contatenating
the key.

Do not use it for real applications!

:undocumented: __revision__, __package__
"""

__revision__ = "$Id$"

from Crypto.Cipher import _XOR

class XORCipher:
    """XOR cipher object"""

    def __init__(self, key, *args, **kwargs):
        """Initialize a XOR cipher object
        
        See also `new()` at the module level."""
        self._cipher = _XOR.new(key, *args, **kwargs)
        self.block_size = self._cipher.block_size
        self.key_size = self._cipher.key_size

    def encrypt(self, plaintext):
        """Encrypt a piece of data.

        :Parameters:
          plaintext : byte string
            The piece of data to encrypt. It can be of any size.
        :Return: the encrypted data (byte string, as long as the
          plaintext).
        """
        return self._cipher.encrypt(plaintext)

    def decrypt(self, ciphertext):
        """Decrypt a piece of data.

        :Parameters:
          ciphertext : byte string
            The piece of data to decrypt. It can be of any size.
        :Return: the decrypted data (byte string, as long as the
          ciphertext).
        """
        return self._cipher.decrypt(ciphertext)

def new(key, *args, **kwargs):
    """Create a new XOR cipher

    :Parameters:
      key : byte string
        The secret key to use in the symmetric cipher.
        Its length may vary from 1 to 32 bytes.

    :Return: an `XORCipher` object
    """
    return XORCipher(key, *args, **kwargs)

#: Size of a data block (in bytes)
block_size = 1
#: Size of a key (in bytes)
key_size = range(1,32+1)

Directory Contents

Dirs: 1 × Files: 20

Name Size Perms Modified Actions
- drwxr-xr-x 2021-10-11 07:57:08
Edit Download
4.12 KB lrw-r--r-- 2013-10-14 21:38:10
Edit Download
4.80 KB lrw-r--r-- 2020-05-26 02:26:55
Edit Download
4.17 KB lrw-r--r-- 2020-05-26 02:26:55
Edit Download
12.30 KB lrw-r--r-- 2013-10-14 21:38:10
Edit Download
4.35 KB lrw-r--r-- 2020-05-26 02:26:55
Edit Download
4.39 KB lrw-r--r-- 2020-05-26 02:26:55
Edit Download
4.30 KB lrw-r--r-- 2013-10-14 21:38:10
Edit Download
5.01 KB lrw-r--r-- 2013-10-14 21:38:10
Edit Download
9.12 KB lrw-r--r-- 2020-05-26 02:26:55
Edit Download
8.90 KB lrw-r--r-- 2020-05-26 02:26:55
Edit Download
2.67 KB lrw-r--r-- 2020-05-26 02:26:55
Edit Download
34.78 KB lrwxr-xr-x 2020-05-26 02:27:06
Edit Download
22.71 KB lrwxr-xr-x 2020-05-26 02:27:06
Edit Download
14.45 KB lrwxr-xr-x 2020-05-26 02:27:06
Edit Download
26.73 KB lrwxr-xr-x 2020-05-26 02:27:06
Edit Download
34.78 KB lrwxr-xr-x 2020-05-26 02:27:06
Edit Download
59.00 KB lrwxr-xr-x 2020-05-26 02:27:06
Edit Download
59.01 KB lrwxr-xr-x 2020-05-26 02:27:06
Edit Download
14.45 KB lrwxr-xr-x 2020-05-26 02:27:06
Edit Download
3.36 KB lrw-r--r-- 2012-05-24 12:55:30
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).