This came to mind the other day and I'm wanting to know if there is a name for the following algorithm (I'm not sure if "cipher" is the right word for it):

  1. Take two consecutive letters at a time (not just one).
  2. Perform the A1Z26 cipher on each letter to get their position in the alphabet as numbers.
  3. Take the difference between those numbers obtained in the previous step.
  4. Convert the difference back into a letter through A1Z26 in reverse. If the difference is positive, use a capital letter. If the difference is negative, use a lowercase letter. If you encounter two of the same letter in a row (difference is 0), convert them to the letter Z, since there is no "0th" letter of the alphabet, and Z would otherwise go unused since we're taking differences (the maximum difference possible would be Z - A -> 26 - 1 = 25 -> Y). Z is always capitalized.
  5. Repeat until you reach the last letter, in which case you "wrap" back around from the last letter to the first.

"Hello world", for example, becomes "CgZcG HcFHs"

  • H, e -> 8 - 5 = 3 -> C
  • e, l -> 5 - 12 = -7 -> g
  • l, l -> 12 - 12 = 0 -> Z
  • l, o -> 12 - 15 = -3 -> c
  • o, H -> 15 - 8 = 7 -> G
  • w, o -> 23 - 15 = 8 -> H
  • o, r -> 15 - 18 = -3 -> c
  • r, l -> 18 - 12 = 6 -> F
  • l, d -> 12 - 4 = 8 -> H
  • d, W -> 4 - 23 = -19 -> s

Is there a name for this method, or a similar algorithm? What are other examples of algorithms working on not the individual letters themselves, but mathematical operations between 2+ letters?

  • 3
    $\begingroup$ Unkeyed CBC over $\mathbb{Z}_{26}$? $\endgroup$ – DannyNiu Jan 12 at 6:07
  • 2
    $\begingroup$ You have labeled it with "encryption". But encryption supposes that there is a way to decrypt it. Where as for this algorithm there is no way to restore the original message for sure. Many messages will produce the same result. For instance, ABCDE -> aaaaD. BCDEF -> aaaaD, CDEFG -> aaaaD. If you have "aaaaD", how will you know what was the original message? $\endgroup$ – mentallurg Jan 12 at 17:48

What you describe is very similar to the autokey cipher, first described in 1586 by Blaise de Vigenère. The differences between your scheme and a standard autokey cipher with a single-letter key are that:

  1. You're using subtraction to encrypt and addition to decrypt the message, whereas most autokey variants do the opposite. (That said, "inverted" autokey variants that work like your cipher aren't uncommon either.)

  2. In effect, you're using the last letter of the plaintext as the key letter (and moving the first ciphertext letter to the end of the ciphertext).

Now, moving the first ciphertext letter doesn't really make any significant difference to the encryption scheme, since it's an easily reversible operation, and switching the encryption and decryption operations doesn't make much difference to this particular cipher, either.

However, as Mike Ounsworth notes, using the last letter of the plaintext as the key letter introduces an ambiguity to your encryption scheme, such that the ciphertext cannot be unambiguously decrypted unless one already knows at least one letter of the plaintext. This can be interpreted in two ways:

  • either your scheme is an ambiguous keyless cipher, with each ciphertext corresponding to 26 possible plaintexts;
  • or it has a one-letter secret key that is chosen based on the plaintext, and thus needs to be somehow communicated to the recipient alongside the encrypted message to allow unambiguous decryption.

Of course, in practice, this ambiguity makes little difference to the security of your cipher. As long as the encryption method is known (as one should assume, per Kerckhoff's principle), your scheme is as easy to break as normal single-letter autokey simply by trying all 26 possible keys and seeing which one produces the most plausible-looking plaintext.

Also, even if one didn't know the encryption method and only had a piece of ciphertext, single-letter autokey and its variants are certainly something a moderately skilled cryptanalyst should try — at least after ruling out simple Caesar substitution and plain transposition ciphers based on frequency analysis, and after an index-of-coincidence or other similar test fails to reveal any periodicity that would suggest a longer key. Thus, while your scheme could make a moderately interesting cipher puzzle, even as such a puzzle it's really no harder to break than any other basic single-letter autokey variant.


This answer is expanding on @mentallurg's comment.

One of the important properties of a cipher is that you can decrypt. More precisely that there is an algorithm that takes in the cipher text and the private key and produces the correct plaintext. (Your scheme does not have a key, which is a separate problem with calling it a cipher).

So let's take your ciphertext "CgZcG HcFHs" and try decrypting it.

C = 3
g = -7
Z = 0
c = -3
G = 7
H = 8
c = -3
F = 6
H = 8
s = -19

So I know the distance between the fist and second letter is 3, but I don't know what the first letter actually is. If I knew the first letter then the rest would be uniquely determined. If your alphabet is [a-zA-Z] then there are 52 different plaintexts that would have produced this ciphertext, and the decryption algorithm has no way to know which of the 52 was the intended plaintext.


Note: almost nothing in modern cryptography has any concept of "letters". Bits, bitstrings (sequences of bits), bytes (8 bits), bytestrings (sequences of bytes), integers, and polynomials are the most common things to operate on. "ω" is a letter. "א" is a letter. "👨‍👩‍👧‍👦" is an extended grapheme cluster, which is Unicode's name for anything humans consider a single character, aka a letter. "!" is not a letter, but it is an English chaaacter. None of those is an English letter.

As DannyNiu mentioned scheme is an unkeyed function operating in CBC mode on the Integers modulo 26. It has no key, so I wouldn't call it a cipher, it's just an encoding.

The interesting part of your question is the last bit: "What are other examples of algorithms working on not the individual letters themselves, but mathematical operations between 2+ letters?"

Block ciphers operate on a fixed-size block of data, usually a bitstring or bytestring. For example the popular AES block cipher operates on blocks of 128 bits at a time. If those blocks happen to contain Unicode-encoded English letters, then it operates on 16 letters at a time, since each letter takes 8 bits.

Many hash functions have some internal block size or capacity that they operate on, taking in data in chunks ≤ that size (and extending them to equal that size if lower).

Some popular stream ciphers operate on a fixed-size data block larger than one byte internally, though their output stream still gets used a single bit at a time. Eg ChaCha has a 512-bit internal block.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.