Autokey cipher is a polyalphabetic substitution cipher in which the key stream is a short starting keyword followed by the plaintext itself. Because the key does not repeat inside one message, it avoids the repeating-key weakness of the Vigenere cipher, but it is still a classical cipher and is not secure by modern standards.
Choose a primer keyword such as KILT. Write it, then append the plaintext letters to build a key as long as the message. Each plaintext letter is shifted by the matching key letter, exactly as in Vigenere: ciphertext = (plain + key) mod 26 with A=0 to Z=25.
The run below encrypts and decrypts the KILT example, and shows a second key and message.
import string
A = string.ascii_uppercase
def auto(p, key, d=1):
out = []; ks = key
for i, c in enumerate(p):
o = A[(A.index(c) + d * A.index(ks[i])) % 26]
out.append(o)
ks += c if d == 1 else o
return ''.join(out)
e = auto("MEETATTHEFOUNTAIN", "KILT")
print(e)
print(auto(e, "KILT", -1))
print(auto("ATTACKATDAWN", "LEMON"))
WMPMMXXAEYHBRYOCA
MEETATTHEFOUNTAIN
LXFOPKTMDCGN
Notice that LEMON with ATTACKATDAWN starts like the Vigenere result (LXFOP) and then diverges at the sixth letter, where Vigenere repeats the key and Autokey uses the message.
Autokey is slightly stronger than Vigenere because the key does not repeat, so the Kasiski examination and key-length tests no longer apply directly. It can still be broken. An attacker guesses a likely word in the plaintext, and every correct guess reveals more key letters, which in turn reveal more plaintext. The primer is also short and can be found by trying common words.