Ciphers

Stream ciphers

Rabbit, RC4, XOR, Salsa20, ChaCha20 and ZipCrypto. A short key grows a long keystream, and the keystream is XORed into the text. UTF-8 bytes in and hex out.

No blocks, no padding, no modes. A stream cipher turns the key into a long run of bytes that look random. Some take an IV too. That run is the keystream, and it gets XORed into the text byte by byte. Decrypting is the same XOR again. So the ciphertext is exactly as long as the text, and the whole cipher is really one question: how do you grow good keystream out of a short key?

AES-CTR, OFB and CFB answer it with a block cipher inside. The ciphers here answer it on their own, without a block cipher anywhere in sight.

ciphers ciphers --category stream9 ciphers · registry order
OptionsKeyspace
RabbitrabbitARXkey, iv?, endian?, bytes?2^128
RC4rc4Permutationkey, bytes?up to 2^2048
XORxorPolyalphabetickey, bytes?256^n keys for an n-byte key
Salsa20salsa20ARXkey, nonce, counter?, bytes?2^128 or 2^256
XSalsa20xsalsa20ARXkey, nonce, counter?, bytes?2^256
ChaCha20chacha20ARXkey, nonce, counter?, bytes?2^256
XChaCha20xchacha20ARXkey, nonce, counter?, bytes?2^256
ChaCha20-Poly1305chacha20-poly1305ARXkey, nonce, aad?, bytes?2^256
ZipCryptozipcryptoCRC and LCGkey?, keys?, entry?, method?, iv?, bytes?2^96 internal keys, whatever the password
read from the registry in your browser / no networka name with ? is optional

Conventions they share

  • The key is hex, and so are the IV and the nonce. Lengths are checked before the first byte. ZipCrypto takes a password instead, or its three keys in hex.
  • Text goes in as UTF-8 and comes out as lowercase hex. decode wants hex back, any whole number of bytes. With bytes: "hex" the text side is hex too, for plaintext that was never text.
  • Nothing checks integrity. A flipped ciphertext bit flips the same plaintext bit and nobody notices. Except ChaCha20-Poly1305. It has a tag. ZipCrypto checks a CRC-32, which catches a wrong password and not an attacker.
  • One key and one IV give one keystream. Encrypt two texts with both the same and the XOR of the ciphertexts is the XOR of the texts, no key needed. RC4 takes no IV, so there one key is one keystream. The only way out is a new key. Salsa20 and ChaCha20 also take a counter. It starts further down the stream.
  • preserveCase and stripNonAlpha don't apply. Bytes, not letters.

Families

ARX mixes 32-bit words with addition, rotation and XOR, and nothing else that needs a table. Rabbit adds one more thing to the mix, a squaring, and gets by without a single S-box. Salsa20 and ChaCha20 don't even need that. Their X variants stretch the nonce to 24 bytes. Random nonces are fine there.

Permutation keeps the whole state as one shuffled table, every byte value from 0 to 255 exactly once. RC4 is the one here. The key does the first shuffle, and every keystream byte after that is two entries swapping places and a third one read out. A deck of 256 cards and a dealer who never stops shuffling.

Polyalphabetic is a classical family, and XOR is the one stream cipher in it. No keystream to grow. The key itself repeats under the text, so it's Vigenère on bytes. Know what breaks Vigenère? Same thing here.

CRC and LCG has one member, ZipCrypto. CRC-32 steps and a linear congruential step move its three keys. The whole cipher runs on 96 bits of state. Once you have those keys, the password is out of the picture.