# Theoretical security of bit rotation for encyption

This is a theoretical question.

I have a idea, encryption by bit rotation in byte. Do not know if something like this already exists.

General concept is:

First n bytes is rotated to left or right by value between 1 and 7. Next n bytes are rotated to left or right by different value between 1 and 7. While keeping n between 1 and 10 bytes. and so on till the end of the of encrypted file.

The value of n and a list of shift values for each block make up the key.

My intent is to use this for a symmetric encryption between computers over the internet.

How breakable/hackable should something like this be?

## 2 Answers

Let's say the plaintext is English text (or some language that uses the basic latin characters), encoded in Unicode. That means each byte represents one character, and because of the quirks of Unicode, the basic latin characters and typical punctuation marks all have a zero for the most significant bit.

To attack your scheme, an attacker would look for runs of bytes which all had zeros in the same bit-position. A run of $x$ bytes all with a zero in the $y$ bit-position would suggest both a length for $n$ (something less than or equal to $x$) and also a rotation amount (the amount required to move the most significant zero bit to position $y$).

Even if the plaintext is not English text, or doesn't use Unicode, in your scheme the ciphertext still trivially leaks the parity of each byte of the plaintext (i.e. how many 1's and 0's are each byte), which is an atrocious amount of information to leak. For a cipher to be secure, the ciphertext shouldn't leak any information whatsoever about the plaintext, except for its length.

Each block of n can be decrypted using frequency analysis, similar to how Caesar ciphers are broken. In the case that n is sufficiently small enough for frequency analysis to be difficult, it can be inferred that non-printable bytes will not show up. This is enough information to mount a very practical attack.

This also has the same issue as the WWII enigma machine, in that a character will never encrypt to itself. To fix this, a shift amount of 0 should be allowed. The result will be negligibly more secure, and may still be easily cracked.

• [corrected] Nonzero rotate can take some values of an 8-bit byte to themselves; the first example that springs to my mind (given I spent too much time over past years hand-debugging serial-line protocols) is ASCII cap U (with space or even parity) = hex 55, by 2 or any multiple of 2. That said, I concur this scheme is still a weak Vigenere. – dave_thompson_085 Jan 30 '16 at 6:10