# perldoc > Crypt::Mode::CTR

---
type: CommandReference
command: Crypt::Mode::CTR
mode: perldoc
section:
source: perldoc
---
## Quick Reference
- `$m = Crypt::Mode::CTR->new('AES')` — create CTR object for AES
- `$ciphertext = $m->encrypt($plaintext, $key, $iv)` — encrypt data in one step
- `$plaintext = $m->decrypt($ciphertext, $key, $iv)` — decrypt data in one step
- `$m->start_encrypt($key, $iv); $ciphertext = $m->add('data'); ...` — incremental encryption
- `$m->start_decrypt($key, $iv); $plaintext = $m->add($ciphertext); ...` — incremental decryption
- `$m = Crypt::Mode::CTR->new('AES', 1, 4)` — custom counter mode (big-endian, 4-byte counter)

## Name
Block cipher mode CTR [Counter mode]

## Synopsis
perl
use Crypt::Mode::CTR;
my $m = Crypt::Mode::CTR->new('AES');

#(en|de)crypt at once
my $ciphertext = $m->encrypt($plaintext, $key, $iv);
my $plaintext = $m->decrypt($ciphertext, $key, $iv);

#encrypt more chunks
$m->start_encrypt($key, $iv);
my $ciphertext = $m->add('some data');
$ciphertext .= $m->add('more data');

#decrypt more chunks
$m->start_decrypt($key, $iv);
my $plaintext = $m->add($some_ciphertext);
$plaintext .= $m->add($more_ciphertext);
## Methods
- **`new($cipher_name, $ctr_mode?, $ctr_width?, $cipher_rounds?)`** — creates a CTR mode object
  - `$cipher_name` — any cipher name supported by Crypt::Cipher (e.g., `'AES'`, `'Blowfish'`, `'Twofish'`, ...)
  - `$ctr_mode` (optional) — counter mode:
    - `0` – little-endian (default)
    - `1` – big-endian
    - `2` – little-endian, RFC3686 incrementing
    - `3` – big-endian, RFC3686 incrementing
  - `$ctr_width` (optional) — counter width in bytes (default = full cipher block width)
  - `$cipher_rounds` (optional) — number of rounds for the cipher
- **`encrypt($plaintext, $key, $iv)`** — returns ciphertext
- **`decrypt($ciphertext, $key, $iv)`** — returns plaintext
- **`start_encrypt($key, $iv)`** — begins incremental encryption
- **`start_decrypt($key, $iv)`** — begins incremental decryption
- **`add($data)`** — processes next chunk; in encrypt mode returns ciphertext, in decrypt mode returns plaintext

## See Also
- [CryptX](https://metacpan.org/pod/CryptX)
- [Crypt::Cipher](https://metacpan.org/pod/Crypt::Cipher)
- [Crypt::Cipher::AES](https://metacpan.org/pod/Crypt::Cipher::AES)
- [Crypt::Cipher::Blowfish](https://metacpan.org/pod/Crypt::Cipher::Blowfish)
- [Wikipedia: CTR mode](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_.28CTR.29)