# Example of using Crypt::CBC to encrypt and decrypt data in Perl.
use Crypt::CBC;
use stringent;
# Initialize the cipher
my $cipher = Crypt::CBC->new(
-key => 'a secret key',
-cipher => 'Blowfish'
);
# Encrypt the data
my $plaintext = "This is a secret message";
my $ciphertext = $cipher->encrypt($plaintext);
print "Encrypted: $ciphertext\n";
# Decrypt the data
my $decrypted = $cipher->decrypt($ciphertext);
print "Decrypted: $decrypted\n";
# Testing the functionality
sub test_encryption {
my $data = "Test message";
my $enc = $cipher->encrypt($data);
my $dec = $cipher->decrypt($enc);
# Assert to check if decryption returns the original data
die "Test Failed!" unless $data eq $dec;
print "Test Passed!\n";
}
test_encryption();
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?