Previous section To contents Next section

14.14.2 Block ciphers

The block ciphers included in the current version are DES, IDEA and CAST128 (note that IDEA is patented, see
Ascom Tech for details). All block ciphers have a common set of methods.

METHOD
crypt_block

SYNTAX
string o->crypt_block(string blocks);

DESCRIPTION
Encrypts or decrypts an even number of block, using the current key. If more than one block is given, they are encrypted/decrypted independently, i.e. in Electronic Code Book (ECB) mode.

METHOD
query_block_size

SYNTAX
int o->query_block_size();

DESCRIPTION
Returns the block size of the cipher, in octets. A typical block size is 8 octets. A string passed to crypt_block() must have a length that is a multiple of the block size.

METHOD
query_key_length

SYNTAX
int o->query_key_length();

DESCRIPTION
Returns the key size of the cipher, in octets. Note that some block ciphers, e.g. CAST128, have a variable key size. In this case, query_key_length returns the recommended key size, although keys of other lengths are accepted by the set_encrypt_key and set_decrypt_key methods. For DES, the real key length is seven octets (56 bits), but the DES standard mandates the use of parity bits. The query_key_length method lies about DES, and says that the key_size is eight octets (64 bits). See also des_parity.

METHOD
set_encrypt_key

SYNTAX
object o->set_encrypt_key(string key);

DESCRIPTION
Installs a key, and configures the object for doing encryption. For convenience, this method returns the object itself.

METHOD
set_decrypt_key

SYNTAX
object o->set_decrypt_key(string key);

DESCRIPTION
Installs a key, and configures the object for doing decryption. For convenience, this method returns the object itself.
The classes are

CLASS
Crypto.des Crypto.des

CLASS
Crypto.idea Crypto.idea
and

CLASS
Crypto.cast Crypto.cast
. To encrypt the block "Pike des" using the DES-key '0123456789abcdef' (in hex), use
Crypto.des()->set_encrypt_key(Crypto.hex_to_string("0123456789abcdef"))
                        ->crypt_block("Pike DES")
although most applications will not use the Crypto.des class directly.
Previous section To contents Next section