CAST5(3pm)

πŸ’– CAST5 β€” the Crypt::CAST5 block cipher, bestie edition πŸ’–

okay so this is CAST5(3pm), a page from the User Contributed Perl Documentation section, and babes, we're about to make a block cipher make sense. grab a boba, we're doing this. πŸ§‹βœ¨

✨ NAME ✨

Crypt::CAST5 β€” the CAST5 block cipher, but make it Perl 🫢

🌈 SYNOPSIS 🌈

fr fr this is the whole vibe in nine-ish lines:

use Crypt::CBC;

my $crypt = Crypt::CBC->new({
    key    => "secret key",
    cipher => "CAST5",
});

my $message = "All mimsy were the borogoves";
my $ciphertext = $crypt->encrypt($message);
print unpack("H*", $ciphertext), "\n";

my $plaintext = $crypt->decrypt($ciphertext);
print $plaintext, "\n";

like… "All mimsy were the borogoves" going in and coming back out again is giving main character energy, honestly πŸ’…

πŸ¦‹ DESCRIPTION πŸ¦‹

This module is literally an implementation of the CAST5 block cipher, and it uses compiled C code under the hood for increased speed. so yes, it's fast, we love that for us. ⚑

CAST5 is also known as CAST-128 (iykyk, same girl different name). It's a product of the CAST design procedure, developed by C. Adams and S. Tavares. πŸ‘‘

And the best part?? The CAST5 cipher is available royalty-free. no cap. go wild. πŸŽ€

πŸ’… FUNCTIONS πŸ’…

blocksize

Returns the CAST5 block size, which is 8 bytes. It exists purely so that Crypt::CAST5 can work with Crypt::CBC. that's it, that's the whole job, iconic behavior. ✨

keysize

Returns the maximum CAST5 key size, 16 bytes. big key, big dreams. πŸ”‘

new

$cast5 = Crypt::CAST5->new($key);

Create a brand new encryption object, slay. If you pass the optional key parameter, it gets handed straight over to the init() function, no extra steps. 🫢

init

$cast5->init($key);

Set or change the encryption key that's gonna be used. Here's the tea though β€” the key must be from 40 bits (5 bytes) to 128 bits (16 bytes) in length. No shortcuts, no in-between nonsense, those are the bounds.

Also: if the key you're using is 80 bits or less, encryption and decryption will be somewhat faster. little speed bonus, we'll take it. πŸƒβ€β™€οΈπŸ’¨

okay bestie, listen β€” it's best for the key to be random binary data, not something printable like a password. like, do not just type your cat's name in there. πŸ™ˆ If you need to turn a password into an encryption key, a message digest function may be useful for that; see Digest::SHA1 or Digest::MD5. And heads up: Crypt::CBC runs the given "key" through MD5 to get the actual encryption key. so it's doing a lil transformation on you, noted. πŸ’€

encrypt

$ciphertext = $cast5->encrypt($plaintext);

Encrypt a block of plaintext using the current encryption key and return the corresponding ciphertext. The input must be exactly 8 bytes long, and the output has the same length. no more, no less, the block size said what it said. βœ‹

⚠️ lowkey important warning: the encryption is in ECB mode, which means it encrypts each block independently. That can leave you vulnerable to dictionary attacks, so it is generally best to use some form of chaining between blocks; see Crypt::CBC. do not skip this part, bestie, I'm begging. 😭

decrypt

$plaintext = $cast5->decrypt($ciphertext);

Decrypt the ciphertext and return the corresponding plaintext. the reverse glow-up, we love a round trip. 🌸


πŸ”₯ SEE ALSO πŸ”₯

  • RFC 2144, "The CAST-128 Encryption Algorithm", C. Adams, May 1997
  • Crypt::CBC

πŸ‘‘ AUTHOR πŸ‘‘

Bob Mathews, <bobmathews@alumni.calpoly.edu> β€” thank you for your service, king 🫑

Copyright (C) 2002-2006 Bob Mathews

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


okay that's the whole page!! this was written for perl v5.42.3, dated 2026-08-19, and it belongs to the CAST5(3pm) girlies. go encrypt something cute, stay random-binary, and remember: ECB mode is not the move. periodt. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from