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; seeDigest::SHA1orDigest::MD5. And heads up:Crypt::CBCruns 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 AND LICENSE π
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
- ubuntu stonking: libcrypt-cast5-perl 0.05-3build6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms