Crypt::Mode::ECB(3)
π Crypt::Mode::ECB β the manual, but make it make sense
okay so bestie, you're reading the Crypt::Mode::ECB(3) page from the User Contributed Perl Documentation section, and honestly? you're in the right place. let's get into it π
β¨ NAME β¨
Crypt::Mode::ECB β it's the Block cipher mode ECB a.k.a. [Electronic codebook]. yes the square brackets are part of the vibe. no we don't know why either. π¦
πΈ SYNOPSIS πΈ
here's the whole thing in one go, copy-paste ready, no cap:
use Crypt::Mode::ECB;
my $m = Crypt::Mode::ECB->new('AES');
my $key = '1234567890123456';
my $plaintext = 'example plaintext';
my $chunk1 = 'example ';
my $chunk2 = 'plaintext';
# encrypt or decrypt in one call
my $single_ciphertext = $m->encrypt($plaintext, $key);
my $single_plaintext = $m->decrypt($single_ciphertext, $key);
# encrypt more chunks
$m->start_encrypt($key);
my $chunked_ciphertext = '';
$chunked_ciphertext .= $m->add($chunk1);
$chunked_ciphertext .= $m->add($chunk2);
$chunked_ciphertext .= $m->finish;
# decrypt more chunks
$m->start_decrypt($key);
my $chunked_plaintext = '';
$chunked_plaintext .= $m->add($chunked_ciphertext);
$chunked_plaintext .= $m->finish;
likeβ¦ it literally does the whole thing. one-shot call or chunked stream, your choice, both are iconic π
π DESCRIPTION π
so this module implements ECB cipher mode. that's the whole job. β¨
quick note though: it only works with ciphers that come from CryptX (Crypt::Cipher::NNNN). no random ciphers, it's not gonna happen.
β οΈ BEWARE, bestie, for real: ECB is insecure by design. that's not me being dramatic, that's just the truth of it. if you're not 100% sure what you're doing, go for Crypt::Mode::CBC instead. please π i'm begging you. π
π₯ METHODS π₯
unless the docs say otherwise, just assume $m is a mode object you already made with "new", like this:
my $m = Crypt::Mode::ECB->new('AES');
π§ new
my $m = Crypt::Mode::ECB->new($name);
#or
my $m = Crypt::Mode::ECB->new($name, $padding);
#or
my $m = Crypt::Mode::ECB->new($name, $padding, $cipher_rounds);
# $name ....... [string] one of 'AES', 'Anubis', 'Blowfish', 'CAST5', 'Camellia', 'DES', 'DES_EDE',
# 'KASUMI', 'Khazad', 'MULTI2', 'Noekeon', 'RC2', 'RC5', 'RC6',
# 'SAFERP', 'SAFER_K128', 'SAFER_K64', 'SAFER_SK128', 'SAFER_SK64',
# 'SEED', 'Skipjack', 'Twofish', 'XTEA', 'IDEA', 'Serpent'
# or any <NAME> for which there is a Crypt::Cipher::<NAME> module
# $padding .... [integer] 0 no padding (plaintext size has to be multiple of block length)
# 1 PKCS5 padding, Crypt::CBC's "standard" - DEFAULT
# 2 Crypt::CBC's "oneandzeroes"
# 3 ANSI X.923 padding
# 4 zero padding
# 5 zero padding (+a block of zeros if the output length is divisible by the blocksize)
# $cipher_rounds ... [integer] optional, number of rounds for given cipher
let me break down the tea β:
$nameβ a[string], and it's one of'AES','Anubis','Blowfish','CAST5','Camellia','DES','DES_EDE','KASUMI','Khazad','MULTI2','Noekeon','RC2','RC5','RC6','SAFERP','SAFER_K128','SAFER_K64','SAFER_SK128','SAFER_SK64','SEED','Skipjack','Twofish','XTEA','IDEA','Serpent'β or literally any<NAME>that has aCrypt::Cipher::<NAME>module out there. pick your fighter π$paddingβ an[integer], and it's giving choices:0β no padding (heads up: plaintext size has to be multiple of block length, no exceptions)1β PKCS5 padding, Crypt::CBC's"standard"β this one's the DEFAULT π2β Crypt::CBC's"oneandzeroes"3β ANSI X.923 padding4β zero padding5β zero padding (+a block of zeros if the output length is divisible by the blocksize)
$cipher_roundsβ an[integer], optional, number of rounds for the given cipher. fancy β¨
π¦ encrypt
encrypts the plaintext in a single call. returns the ciphertext as a binary string. simple, clean, slay.
the plaintext scalar gets converted to bytes using Perl's usual scalar stringification. defined scalars are accepted β including numbers and string-overloaded objects, no judgment here. "undef" is treated as an empty string and may emit Perl's usual "uninitialized value" warning. so likeβ¦ define your vars, bestie π
my $ciphertext = $m->encrypt($plaintext, $key);
π decrypt
decrypts the ciphertext in a single call. returns the plaintext as a binary string. the reverse of the above, obviously.
the ciphertext scalar gets converted to bytes using Perl's usual scalar stringification. defined scalars are accepted β numbers and string-overloaded objects included. "undef" is treated as an empty string and may emit Perl's usual "uninitialized value" warning.
my $plaintext = $m->decrypt($ciphertext, $key);
π start_encrypt
initializes encryption mode. returns the object itself (so you can chain, iykyk).
$m->start_encrypt($key);
β start_decrypt
initializes decryption mode. returns the object itself. twin of the one above π«Ά
$m->start_decrypt($key);
π add
feeds data to the encryption or decryption stream. returns a binary string. this is the "chunk by chunk" girlie π
each argument gets converted to bytes using Perl's usual scalar stringification. defined scalars are accepted, including numbers and string-overloaded objects. "undef" is treated as an empty string and may emit Perl's usual "uninitialized value" warning.
# in encrypt mode
my $ciphertext = $m->add($plaintext);
# in decrypt mode
my $plaintext = $m->add($ciphertext);
π finish
finalizes the stream. in encryption mode it pads and encrypts the final block; in decryption mode it decrypts and removes padding from the final block. returns the result as a binary string β and yes, it may be empty if there's no data to flush. that's not a bug, that's just an empty vibe π
# encrypt more chunks
$m->start_encrypt($key);
my $chunk1 = 'example ';
my $chunk2 = 'plaintext';
my $ciphertext = '';
$ciphertext .= $m->add($chunk1);
$ciphertext .= $m->add($chunk2);
$ciphertext .= $m->finish;
# decrypt more chunks
$m->start_decrypt($key);
my $plaintext = '';
$plaintext .= $m->add($ciphertext);
$plaintext .= $m->finish;
π SEE ALSO π
go read these, they're literally so good:
CryptX,Crypt::CipherCrypt::Cipher::AES,Crypt::Cipher::Blowfish,...- <https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_codebook_.28ECB.29>
okay that's the whole page, you ate that π
β¨ this little masterpiece is perl v5.42.0, dated 2026-05-11, and it lives under Crypt::Mode::ECB(3) β go forth and maybe use CBC instead, ily π«Άπ
π¦ where this page comes from
- opensuse-leap 16.0: perl-CryptX 0.89.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-CryptX 0.89.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-CryptX 0.89.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-CryptX 0.89.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms