Autokey cipher
Encrypt or decrypt with the Autokey cipher, where a short primer is followed by the message itself: with primer KEY, Hello, World! becomes Rijss, Hzfhr! because the running key reads KEYHELLOWO. Spaces and punctuation stay put. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Text
- Hello, World!
- Key
- KEY
- Calculation mode
- Encrypt
- Result
- Rijss, Hzfhr!
- Key letters
- KEY
- Key length
- 3
- Running key letters
- KEYHELLOWO
The Autokey cipher is a classical polyalphabetic cipher in the Vigenère family where the short primer keyword is extended by the message itself instead of repeating forever. You paste text, a primer key that contains at least one Latin letter, and a mode of encrypt or decrypt; letters A through Z and a through z move under modular addition or subtraction while digits, spaces, punctuation, and other characters stay put so readable structure survives. On encrypt the running key is the primer followed by successive plaintext letters; on decrypt the same primer is followed by letters recovered so far, which is how the receiver rebuilds the stream without storing the whole plaintext in advance.
How the Autokey cipher builds a running key from the message
Autokey improves on a simple repeating-keyword Vigenère by chaining the message into the key stream after a short primer. Map each Latin letter in the primer and in the message to indices zero through twenty-five. For encryption, the first letters of the running key are the primer letters; once those are spent, each next key letter is the previous plaintext letter that was just encrypted.
Ciphertext for each alphabetic character is the plaintext index plus the key index, taken modulo twenty-six, written back in the same case so uppercase stays uppercase and lowercase stays lowercase. Characters outside A through Z and a through z—including spaces, commas, digits, emoji, and accented letters outside the basic Latin block—are copied unchanged and do not advance the key pointer, matching textbook tables where only the alphabetic skeleton of a sentence is scrambled.
Decryption reverses the addition: each ciphertext letter minus the current key letter modulo twenty-six yields a plaintext letter, and that recovered letter is appended to the running key for the next alphabetic step. Mathematically every step is integer modular arithmetic with a fixed twenty-six-letter alphabet; there is no floating-point rounding of the key, no network call, no random seed, and no wall-clock timestamp.
Where Autokey cipher tools show up in real work
Introductory cryptography courses introduce Autokey after Caesar and repeating-keyword Vigenère so students see how a short primer can seed a long non-repeating key stream without inventing modern block ciphers. Capture-the-flag warm-ups and puzzle hunts still hide Autokey or Autokey-variant messages, and solvers want a fast, predictable primer-plus-message transform rather than a general cryptanalysis suite. Support and content teams sometimes lightly obfuscate spoilers, quiz answers, or internal labels with a classical primer cipher and need the reverse path without installing a language-specific crypto library.
If you need a fixed single-letter Caesar shift, a reciprocal Beaufort keyword map, strong authenticated encryption, Base32 or Base64 encoding, or automatic frequency-analysis key recovery, treat those as separate search intents and landings rather than overloading this classical Autokey page.
What you can do with it
Classroom Autokey demos
Encrypt and decrypt sample sentences with a known primer so intro-crypto lessons show primer-plus-plaintext key streams without writing one-off scripts.
Puzzle and CTF Autokey challenges
Apply or reverse an Autokey primer on challenge strings for homework checkers and CTF warm-ups that expect classical polyalphabetic behavior.
FAQ
What is the Autokey cipher?
A classical polyalphabetic cipher that uses a short primer keyword extended by the message itself. Encrypt uses C = (P + K) mod 26; decrypt uses P = (C - K) mod 26 with the recovered plaintext extending the key.
How do I decrypt Autokey ciphertext?
Call the same capability with mode decrypt, the ciphertext as text, and the original primer as key. The running key is rebuilt from the primer plus each recovered plaintext letter.
What happens if the key is empty?
The primer keyword must contain at least one Latin letter A–Z or a–z; empty or letter-free keys are rejected and not charged.
Are spaces and punctuation encrypted?
No. Only A–Z and a–z are transformed. Spaces, digits, punctuation, and other characters pass through and do not advance the running key.
What does it cost?
The browser tool is free and runs locally.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/enc/autokey \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"Hello, World!","key":"KEY"}'const res = await fetch("https://api.kit.forhosting.com/enc/autokey", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"text": "Hello, World!",
"key": "KEY"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/enc/autokey",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"text": "Hello, World!",
"key": "KEY"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/enc/autokey", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"text":"Hello, World!","key":"KEY"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"text":"Hello, World!","key":"KEY"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/enc/autokey", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"text": "Hello, World!",
"key": "KEY"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "enc.autokey",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
An empty key or a key with no alphabetic characters is rejected immediately with invalid_input, so homework checkers and scripts never silently fall back to a default keyword.
How the Autokey cipher builds a running key from the message
The primer must contain at least one Latin letter; empty, whitespace-only, or digit-only keys fail with invalid_input rather than behaving as an identity transform. Identical text, key, and mode always produce identical JSON. This page implements classical Autokey only—not a fixed single-shift Caesar cipher, not Beaufort subtraction, not AES, and not an automatic key-recovery cracker. Those are separate tools and separate search intents with their own landings.
What you send and what you get back
Send a required string field named text, a required string field named key, and an optional mode string that defaults to encrypt when omitted. Classic checks include encrypting Hello, World! with primer KEY, decrypting the ciphertext with the same key back to the original phrase, and confirming that an empty key is rejected rather than treated as a no-op. Accepted mode values are encrypt and decrypt, plus common aliases such as enc, dec, encode, and decode. The text may be empty if you only want a trivial identity check, but the key must not be empty after the alphabetic filter: whitespace-only strings and keys that contain only digits or symbols fail with invalid_input and a clear English message that mentions the empty key requirement. On success the response echoes mode, the original text and key, key_letters as the uppercase A-Z primer stream actually used, key_length as how many alphabetic positions that primer has, running_key_letters as the full uppercase key stream consumed for this message, the transformed result string, length of that result, letters_transformed as a count of how many alphabetic characters moved, plus alphabet and cipher labels and a formula string so clients can assert the profile they hit. Missing text, missing key, non-string objects for either field, an unknown mode, and strings longer than the documented maximum fail with invalid_input. Validation failures do not consume prepaid balance.
Where Autokey cipher tools show up in real work
Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance.
Integration use cases
Lightweight spoiler and label obfuscation
Scramble quiz answers or internal labels with a classical primer and restore them later with the same contract in browser or API.