---
title: "ZipCrypto"
description: "ZipCrypto opens traditional PKWARE encrypted ZIP entries with a password or three internal keys."
canonical_url: "https://ciphers.agntn.dev/ciphers/zipcrypto"
---
# ZipCrypto

> ZipCrypto opens traditional PKWARE encrypted ZIP entries with a password or three internal keys.

<cipher-facts name="zipcrypto">



</cipher-facts>

ZipCrypto opens encrypted entries in a ZIP archive. Give it the password or the three internal keys. It checks the result before handing anything back.

```ts
const zip = create("zipcrypto");

const archive = zip.encode("ATTACK AT DAWN", {
  key: "causality",
  entry: "note.txt",
}).text;
// "504b0304...", a ZIP archive in hex that unzip opens

zip.decode(archive, { key: "causality" }).options.keys;
// "7067b779 926e6526 2b5a64b9"

zip.decode(archive, { keys: "7067b779 926e6526 2b5a64b9" }).text;
// "ATTACK AT DAWN"
```

## What is ZipCrypto?

ZipCrypto is traditional PKWARE encryption from section 6.1 of the ZIP APPNOTE. Info-ZIP writes it with `zip -e` or `zip -P`. 7-Zip uses it by default for ZIP. You can also choose it with `-mem=ZipCrypto`.

Biham and Kocher published a known plaintext attack in 1994. Their paper is *A Known Plaintext Attack on the PKZIP Stream Cipher*. ZipCrypto belongs in puzzles, not around secrets.

## What do the three keys do?

The cipher starts with three 32-bit keys:

```text
12345678 23456789 34567890
```

Each password byte moves all three. Key 0 takes a CRC-32 step with the byte. Key 1 adds key 0's low byte, multiplies by 134775813, then adds 1. Key 2 takes a CRC-32 step with key 1's top byte.

One keystream byte comes from key 2. After the password, each plaintext byte moves the keys the same way.

The password picks a starting point. From there, the three keys are the whole 96-bit state. Have those keys? The password can sit this one out.

## Why isn't the header enough?

Each encrypted entry starts with a 12-byte header. It contains 11 random bytes and one check byte.

The check byte usually comes from the top byte of the CRC-32. If flag bit 3 is set, it comes from the file's DOS modification time instead. Info-ZIP 3.0 sets that flag. 7-Zip doesn't.

A wrong password passes a one-byte check once in 256 tries. That's a pretty generous bouncer. Decode goes further: it decrypts, unpacks, and compares both CRC-32 and size with the central directory. Only then does it return plaintext.

## Password or keys?

Pass `key` as a UTF-8 password. Or pass `keys` as 24 hex digits. Spaces between the three words are fine.

[bkcrack](https://github.com/kimci86/bkcrack) can recover those keys from known plaintext. It prints three hex words like these:

```text
c4038591 d5ff449d d3b0c696
```

This library accepts the keys. It doesn't run the attack. If you pass both `key` and `keys`, they must agree.

## What does decode return?

Give decode the whole ZIP archive as hex or base64 text. Set `entry` to pick a file inside. Without it, decode picks the first encrypted entry.

Stored, deflate and bzip2 entries can be opened. Decode unpacks at most 4 MiB.

The result contains the plaintext and these options:

- `key`, when supplied, and `keys`, always.
- `entry` and `method` for the opened file.
- `iv`, the 11 random header bytes.
- `crc` and `check`, where `check` is `crc` or `time`.

The returned keys make a password useful in another form. For an entry that isn't UTF-8 text, set `bytes: "hex"` to get its plaintext as hex.

The CLI can read an archive encoded as base64:

```sh
ciphers decode zipcrypto "$(base64 -w0 secret.zip)" --key causality --entry fox.txt
```

Over MCP, the text argument holds up to 10,000 characters. Base64 fits a bigger archive than hex.

## Writing an archive

Encode writes one ZIP entry and returns the archive as hex. The default entry is `message.txt`. The default method is `deflate`, and `stored` is also available.

Set `iv` to 22 hex digits to fix the 11 random header bytes. Otherwise they're random. The date is 1 January 1980. There's no data descriptor, so the check byte comes from the CRC.

```sh
ciphers encode zipcrypto "ATTACK AT DAWN" --key causality --method stored | xxd -r -p > note.zip
```

Decode an archive that encode wrote, feed the options back, and the same bytes come out. A bzip2 entry can't make that trip, since encode only writes stored and deflate.

## Checked against

For `causality`, the keys in the opening example match Python 3.14's zipfile state.

The tests pin the bytes of two encoded archives. In a local run, both opened in unzip 6.00, 7-Zip 26.05 and Python's zipfile.

The tests also try two wrong passwords that pass the header check. `wrong84` fails the CRC check on a stored entry. `wrong109` fails to inflate a deflated entry. In a local run, Python's zipfile failed them the same way.

## Errors and analysis

Pass both `key` and `keys` with different values and you get `InvalidOptionError`. A missing or wrong password lists encrypted entries with their methods and sizes. Error messages distinguish `Wrong password:`, `Wrong keys:`, `Not supported:` and `Broken archive:`.

WinZip AES, including 7-Zip's `-mem=AES256`, isn't supported. Neither are PKWARE strong encryption, LZMA entries or split archives. ZIP64 past 65535 entries or 4 GiB isn't supported. Small archives with ZIP64 records from Info-ZIP's pipe output still open.

[`guessFamily`](https://ciphers.agntn.dev/guide/analysis) recognizes ZIP local headers in hex or base64 and names zipcrypto with high confidence. A ZIP header is a clue, not proof that an entry uses this encryption.


## Sitemap

See the full [sitemap](https://ciphers.agntn.dev/sitemap.md) for all pages.
