# man > Crypt::Mode::CTR

<think>The user wants me to transform a Perl module documentation into Open Knowledge Format (OKF) Markdown. Let me analyze the input:

1. It's a Perl module documentation for `Crypt::Mode::CTR`
2. Source: perldoc
3. Section: 3pm (Perl module)
4. I need to create YAML frontmatter, then structure the content

Let me extract:
- Name: Crypt::Mode::CTR
- Mode: perldoc
- Section: 3pm (or just 3 for Perl modules)
- Source: perldoc

The structure should be:
1. YAML frontmatter
2. Quick Reference (extract most useful examples)
3. Name
4. Synopsis
5. Options (this is a class - methods)
6. Examples
7. See Also

Let me format this properly.</think>

---
type: CommandReference
command: Crypt::Mode::CTR
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference

- `Crypt::Mode::CTR->new('AES')` — instantiate CTR mode with a block cipher
- `$m->encrypt($plaintext, $key, $iv)` — encrypt a complete message at once
- `$m->decrypt($ciphertext, $key, $iv)` — decrypt a complete message at once
- `$m->start_encrypt($key, $iv)` — begin streaming encryption
- `$m->start_decrypt($key, $iv)` — begin streaming decryption
- `$m->add($data)` — feed the next chunk into the active stream
- `new($name, $ctr_mode, $ctr_width, $cipher_rounds)` — configure endianness, counter width, and rounds

## Name

`Crypt::Mode::CTR` — 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);
## Description

Implements CTR cipher mode. Works only with ciphers from CryptX (any `Crypt::Cipher::NNNN`).

## Methods

### `new`

perl
my $m = Crypt::Mode::CTR->new($cipher_name);
# or
my $m = Crypt::Mode::CTR->new($cipher_name, $ctr_mode, $ctr_width);
# or
my $m = Crypt::Mode::CTR->new($cipher_name, $ctr_mode, $ctr_width, $cipher_rounds);
**Arguments:**

- `$cipher_name` — any name with a corresponding `Crypt::Cipher` module. Supported: `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`
- `$ctr_mode` — counter endianness / RFC3686 mode. Values:
  - `0` — little-endian counter (default)
  - `1` — big-endian counter
  - `2` — little-endian + RFC3686 incrementing
  - `3` — big-endian + RFC3686 incrementing
- `$ctr_width` — counter width in bytes (default: full block width)
- `$cipher_rounds` — optional number of rounds for the given cipher

### `encrypt`

perl
my $ciphertext = $m->encrypt($plaintext, $key, $iv);
Encrypts a complete message in one call.

### `decrypt`

perl
my $plaintext = $m->decrypt($ciphertext, $key, $iv);
Decrypts a complete message in one call.

### `start_encrypt`

perl
$m->start_encrypt($key, $iv);
Initializes a streaming encryption session.

### `start_decrypt`

perl
$m->start_decrypt($key, $iv);
Initializes a streaming decryption session.

### `add`

perl
# in encrypt mode
my $ciphertext = $m->add($plaintext);

# in decrypt mode
my $plaintext = $m->add($ciphertext);
Feeds the next data chunk into the active encryption or decryption stream started by `start_encrypt` or `start_decrypt`.

## See Also

- [CryptX](http://localhost/phpMan.php/perldoc/CryptX/markdown), [`Crypt::Cipher`](http://localhost/phpMan.php/perldoc/Crypt%3A%3ACipher/markdown)
- [`Crypt::Cipher::AES`](http://localhost/phpMan.php/perldoc/Crypt%3A%3ACipher%3A%3AAES/markdown), [`Crypt::Cipher::Blowfish`](http://localhost/phpMan.php/perldoc/Crypt%3A%3ACipher%3A%3ABlowfish/markdown), ...
- [Block cipher mode of operation - Counter (CTR)](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Counter_.28CTR.29)