Circularly Rotate Text to the Right
Circularly rotate text characters to the right by any number of positions. Visualize each rotation step with instant results and copy output.
About
Circular right rotation shifts every character in a string by k positions toward the end. Characters that overflow past the last index wrap back to the beginning. This is the string equivalent of a bitwise rotate-right (ROR) instruction used in CPU architectures and cryptographic primitives like SHA-256. Getting the rotation count wrong by even one position produces entirely different ciphertext or garbled protocol headers. This tool computes s′ = s[n − k mod n :] + s[: n − k mod n] where n is the string length. It handles edge cases: zero-length input, rotation counts exceeding string length via modulo arithmetic, and negative values converted to their positive right-rotation equivalent.
Circular rotation is distinct from a linear shift. A linear shift discards overflow characters and pads with nulls. A circular rotation preserves all characters. The operation is periodic with period n: rotating by n returns the original string. This tool visualizes each intermediate step so you can trace the permutation sequence. Useful for debugging data-link framing, testing string algorithms, or preparing competitive programming inputs.
Formulas
The circular right rotation of a string s of length n by k positions is defined as the concatenation:
where the effective rotation count is computed via modular arithmetic:
This double-modulo formulation handles negative values of k correctly. A negative k converts to its equivalent right-rotation offset. The operation forms a cyclic group of order n under composition: applying the rotation n times returns the original string. Formally, Rn(s) = s ∀ s ∈ S.
Where s = input string, n = length of s (Unicode-aware, using Array.from), k = requested rotation positions (integer, may be negative), k′ = effective rotation after modulo normalization, s′ = resulting rotated string.
Reference Data
| Original | Rotation (k) | Result | Note |
|---|---|---|---|
| ABCDEF | 1 | FABCDE | Last char wraps to front |
| ABCDEF | 2 | EFABCD | Last 2 chars wrap |
| ABCDEF | 6 | ABCDEF | k = n, full cycle |
| ABCDEF | 7 | FABCDE | k mod n = 1 |
| ABCDEF | 0 | ABCDEF | Identity operation |
| Hello World | 3 | rldHello Wo | Spaces rotate too |
| 12345 | 2 | 45123 | Digits treated as chars |
| A | 99 | A | Single char is invariant |
| ∅ (empty) | 5 | ∅ (empty) | Empty string returns empty |
| 🔥🌊⚡ | 1 | ⚡🔥🌊 | Works with Unicode/emoji |
| ABCDEF | −2 | CDEFAB | Negative → left rotation |
| 10110011 | 3 | 01110110 | Binary string ROR |
| AABBAABB | 4 | AABBAABB | Period divides n |
| Caesar | 3 | sarCae | Positional rotation, not alphabetical |
| OpenAI | 12 | OpenAI | 12 mod 6 = 0 |