playcrypt.ideal package

Submodules

playcrypt.ideal.block_cipher module

class playcrypt.ideal.block_cipher.BlockCipher(key_len, block_len)[source]

Bases: object

This class simulates a block cipher. It can emulate a block cipher with any key or message size (in bytes).

Example Usage:

from playcrypt.primitives import *
from playcrypt.ideal.block_cipher import BlockCipher

b = BlockCipher(16, 12)
key = random_string(16)
cipher_text = b.encrypt(key, "Hello World!")
decrypted_message = b.decrypt(key, cipher_text)

print decrypted_message
Hello World!
decrypt(key, cipher)[source]

This is a simulated decryption function. Use of the correct key and cipher text will result in correct decryption. The cipher and key must have correct lengths.

Parameters
  • key – Key to use for simulated decryption, this must be of length, self.key_len.

  • cipher – Cipher text to be decrypted, this must be of length self.block_len.

Returns

The correct message for the cipher text, cipher, or

None if parameters are not met.

encrypt(key, block)[source]

This is a simulated encryption function. Simply use a key and message with the proper block length.

Parameters

key – Key to use for simulated encryption, so this must be of

length

self.key_len.

Parameters

block – Message to be encrypted, so this must be of length self.block_len.

Returns

The cipher text for the block or None if the length parameters are not met.

playcrypt.ideal.digital_signature module

class playcrypt.ideal.digital_signature.DigitalSignature(key_len, tag_len)[source]

Bases: object

This class simulates a digital signature scheme. It can simulate a signature scheme with any key or tag length (in bytes).

Example Usage:

from playcrypt.ideal.digital_signature import DigitalSignature

m = "ABCDEFGH" * 16
k = "A" * 128

ds = DigitalSignature(128, 128)

pk, sk = ds.key_gen()

c = ds.sign(pk, m)

print str(ds.verify(sk, m, c))
print str(ds.verify(pk, m, c))
True
False
key_gen()[source]
Returns

Returns a random key for a DS scheme.

sign(sk, message)[source]

This is a simulated sign function.

Parameters
  • sk – Key for signing, you must use a key of length self.key_len.

  • message – Message that will be signed, must have length greater than 0.

Returns

Signature of message if parameters are met, None otherwise.

verify(pk, message, tag)[source]

This is a simulated verification function. Checks to see if the tag belongs to the passed in message.

Parameters
  • pk – Key to use for simulated verification. It must have length self.key_len.

  • message – Message to check against tag.

  • tag – Tag that is being tested to see if it belongs to message.

Returns

True if the tag is correct, false otherwise.

playcrypt.ideal.hash_function module

class playcrypt.ideal.hash_function.HashFunction(out_len=0, key_len=0, N=0)[source]

Bases: object

This class simulates a hash function. It can emulate a hash function with or without a key and with any key or output length (in bytes).

Example Usage:

from playcrypt.ideal.hash_function import HashFunction

h = HashFunction(16)

h1 = h.hash("Hello World!")
h2 = h.hash("H3110 W0r1d!")

print str(h1 != h2 and len(h1) == h.out_len and len(h1) == len(h2))
True
hash(message, key=None)[source]

This is a simulated hashing function. If a key is used then it must have the correct key length.

Parameters
  • message – Must be a string of length > 0

  • key – Key used for simulated hashing, must have length self.key_len.

Returns

Hash of message if all parameters are met, None otherwise.

hash_int(message)[source]

This is a simulated hashing function that takes an input in Z_N^* and outputs a value in Z_N^*.

Parameters

message – Must be an integer in Z_N^*

Returns

Hash of message if all parameters are met, None otherwise.

playcrypt.ideal.message_authentication_code module

class playcrypt.ideal.message_authentication_code.MAC(key_len, tag_len)[source]

Bases: object

This class simulates a message authentication code scheme. It can simulate a MAC with any key or tag length (in bytes).

Example Usage:

from playcrypt.ideal.message_authentication_code import MAC

m = "ABCDEFGH"
k = "A" * 16

mac = MAC(16, 16)

c = mac.tag(k, m)

print str(mac.verify(k, m, c))
print str(mac.verify(k, m, k))
True
False
tag(key, message)[source]

This is a simulated tagging function.

Parameters
  • key – Key for tagging. You must use a key of length self.key_len.

  • message – Message that will be tagged. It must have length greater than 0.

Returns

Tag of message if parameters are met, None otherwise.

verify(key, message, tag)[source]

This is a simulated verification function. Checks to see if the tag belongs to the passed in message.

Parameters
  • key – Key to use for simulated verification. It must have length self.key_len.

  • message – Message to check against tag.

  • tag – Tag that is being tested to see if it belongs to message.

Returns

True if the tag is correct, false otherwise.

Module contents