Rotation of bits: a classical and quantum perspective

Introduction Circular bit rotation is an operation where bits are moved in a circular fashion such that bits change their positional values and do not fall off, but rather are placed back to the other end [1, 2]. A left rotation operation is where bits that fall off at the left end are placed back at the right end [1, 2]. In a right rotation operation, bits that fall off at the right end are placed back at the left end [1, 2]. A shift operation that is circular seeks to rearrange the entries present in a data structure by moving the bit to the next position whiles the last bit is moved to the position of the first bit [1, 2]. Elimination of bits is not done by the rotate instructions. For a left rotate (rol), as shown in Fig. 1, bits shifted off the left end of a data word fill the vacated positions on the right. Likewise, for a right rotate (ror), bits “falling off” the right end appear in the vacated positions at left [1, 2]. The bit sequence 00010111 rotated circularly to the left by one bit position produces the bit sequence 00101110 in Fig. 1 above. No bits are lost after the rotational operation or process [1, 2]. With reference to Fig. 2, if the bit sequence 00010111 were subjected to a circular shift of one bit position to the right would yield: 10001011 [1, 2]. Abstract

The concept of circular bit rotation is made clearer by the example below. Assuming we have an 8 bit sequence, say 11100101, moving the bits by 3 places to the left produces 00101111 bit sequence. This implies that the first 3 bits are placed back at the end of the bit sequence. Moving the bits in the original bit sequence by 3 places to the right produces 10111100 bit sequence. This implies that the last 3 bits are placed back at the beginning of the bit sequence. If we have a 16 bit sequence, say 0000000001110010, moving the bits by 3 places to the left produces 0000001110010000 bit sequence. Moving the bits in the original bit sequence by 3 places to the right produces 0100000000001110 bit sequence [1,2].
A number of cryptographic researchers used the logical XOR gate (digital logical gate which performs a logical operation on one or more logic inputs and produces a single logic output) or operation in their encryption protocols [3,4].
Rotators and shifter move bits and multiply or divide by powers of 2. A shifter shifts a number in base 2 left or right by some specified number of positions. Some commonly used shifter kinds include; Logical shifter, Arithmetic shifter and Rotator [5,6]. Logical shifter shifts the number to the left (LSL) or right (LSR) and fills empty spots or positions with zeros. Ex: 11001 LSL 2 = 00100, 11001 LSR 2 = 00110. The arithmetic shifter operates just like the logical shifter but with some slight operation difference [5,6]. On the right shift, it fills the most significant bit (msb) with a copy of the old significant bit, which is vital or key for dividing and multiplying signed numbers. Arithmetic shift left works the same as the logical shift left. Ex: 11001 ROR 2 = 01110; 11001 ROL 2 = 00111. Rotators rotate the bit string in a circle such that empty spots are filled with bits shifted off the other end. Ex: 11001 ROR 2 = 01110; 11001 ROL 2 = 00111 [5,6].
A shifter that perform left shifts, logical and arithmetic right shifts, or no shift is shown in Fig. 3 below from a classical perspective [7].
In 2008, Renesas Electronics Corporation demonstrated a method for decreasing the time taken by a H8 CPU in performing an 8 bit rotate from LSB first to  MSB first. This approach has two methods for completing an 8 bit rotate. The first method employs a look up table; the second rotates physically the data from MSB first to LSB first [8].
The OR, AND, NOT and XOR are simple bit-parallel operations supported in word-oriented processors. They are logical operations that are typically implemented with integer arithmetic operations in computer system, specifically the arithmetic and logic unit, which is the most basic functional unit in a processor. In bit rotations, shifter and mix operations can be used [9].
The standard set of bitwise operations, including OR, AND, XOR, LEFT/RIGHT SHIFT, NOT, is incorporated or available in the C and C++ programming languages. However, circular shift is excluded in the language [10]. When a computer integer is rotated, any bit that falls off one end of the register is moved to the other end as if they are connected end-to-end in a conceptual manner. Circular rotation has some applications in cryptography, for the purposes of encryption and decryption [10].
Bennett disclosed the secret of saving energy by maintaining a unique mapping between input and output vectors called logical reversibility of computation [11]. A reversible circuit is composed of reversible gates only whereas a reversible gate has the property of maintaining one-to-one mapping between input and output vectors. Among the conventional logic gates, NOT operation is the only one which itself is reversible. However, the other conventional logic operations have their reversible counterpart, which is known as n × n dimensional reversible gate. In designing reversible circuits, there exist 2 × 2 and several 3 × 3 gates [12][13][14]. A typical example of the 2 × 2 gate is the Feynman gate [12]. Fredkin gate [14] and Feynman double gate [13] are examples of 3 × 3 gates.
Muwafi et al. also proposed a circuit for rotating, left shifting, or right shifting bit where a circuit for rotating bits of an input word during a single cycle, by duplicating the input word to form an extended word, shifting bits of the extended word, and selecting a subset of the shifted bits of the extended word [15].

Application
Bit rotation is employed in barrel shifters (a logic circuits extensively used in embedded digital signal processors as well as in general purpose processors to manipulate the data as rotating and shifting information is required in few fields including bitindexing, arithmetic tasks and variable-length coding) [16,17]. Bharathesh et al. proposed a low power mux based on dynamic barrel shifter using footed diode domino logic [16,17]. There are bidirectional barrel shifters that can perform six unique tasks: shift right arithmetic (SRA), shift right logical (SRL), rotate left (RL), shift left logical (SLL), shift left arithmetic (SLA), and rotate right (RR) [16,17]. Shah et al. designed a fully custom 8 bit barrel shifter using 8 × 1 multiplexer with the help of GDI technique. The barrel shifter is simply a bit-rotating shift register [18]. A robust architecture of logarithmic barrel shifter that performs bidirectional arithmetic and logical shifting, including rotate operation [19]. Aarthi et al. conducted an image encryption using binary bit plane and rotation method for an image security. Yeng et al. also used the concept of bit rotation to design an encryption algorithm [2,20]. A new universal hash function, circulant hash based on bit rotation was proposed and is a variant of the classical random matrix-based hash of Carter and Wegman, called H 3 , and Toeplitz hash by Krawczyk [21]. An encryption approach for Images using Bits Rotation Reversal and Extended Hill Cipher Technique was also devised [22] as well as an Adaptive Bit Rotation and Inversion Scoring, a novel approach to LSB Image Steganography [23].

Quantum perspective
In quantum computing, unit of data is called qubit and the value of qubit is the superposition of |0> and |1> . Every quantum operation is reversible if it is represented by a unitary matrix which is used to multiply the state of qubit(s) that produces output [24]. Quantum computers process data by applying a universal set of quantum gates that can emulate any rotation of the quantum state vector [25]. The comparative quantum realization of any reversible circuit is used to verify the operability of that circuit [19].
A quantum circuit called quantum shift register in which shift and rotation operations on qubits are performed by swap gates and controlled swap gates. For quantum computers to perform arithmetic operations that are elementary (bitwise comparison of qubits and multiplication), these operations are of essence [26].
Rotation operators are defined as R x , R y and R z and are shown in Fig. 4 below. When the Pauli matrices are exponentiated, rotation operators are generated according to exp (iAx) = cos(x) I + I sin(x) A, where A is one of the three Pauli Matrices [27,28].

Problem, objective and contribution
The current or existing circular bit rotation techniques never ends because it is in a cycle and is continuous. Unlike a logical shift, the vacant bit positions are not filled in with zeros but are filled in with the bits that are shifted out of the sequence [29]. Repetition of bit strings tend to show up at some point when the bit string is rotated circularly using shifts progressively and this poses as a weakness and danger, even to computing and cryptography [2]. For the quantum-classical perspective also, no work has been done with circular bit rotation. The objectives of this paper include; 1. Address the problem of repetitions in emergent/resulting bit strings when the incident/original bit string is rotated circularly. 2. Add or contribute to existing knowledge using a novel concept. 3. Provide a quantum perspective to bit rotation using the quantum swap gate. 4. Provide a performance analysis based on execution times of classical implementation and quantum implementation codes on the binary bit strings.

Method
In the development of the algorithm, the traditional system development life cycle (SDLC) was adopted. Concepts and models which are proven were used in the design process, hence can guarantee an effective and efficient algorithm. In this paper, secondary data were used basically from journals, literature and websites. Primarily, the concepts of circular bit rotation, bit dispersal, bit recombination/extraction and bit prism were used in the design phase of the classical algorithm. There was a strict adherence to the code of ethics for writing manuscripts by ensuring that no plagiarism was made. This work poses no ethical issues or challenges and follows high compliance to ethical standards. The concept of bit prism is derived from the principle of passing light through a glass prism where the incident light ray comes out as emergent light rays, more like a color spectrum [30,31] A bit prism is an abstract object or concept which entails the principles of circular bit rotation, dispersal and recombination. An operation where bits that fall off at the left end is put back at the right end and bits that fall off at the right end is put back at the left end.
The concept of bit swapping was used to rotate quantum bit strings made possible by a quantum swap gate using jsqubits runner (an online quantum computer simulator). Classical perspective (CRotate) In a bit prism, the incident word or classical string is not parallel to emergent word. When a word is passed through the bit prism it gets deviated a number of times (n − 1), where n is the number of bits in a word or classical string. An incident word can be split into multiple emergent words by means of circular bit rotation and dispersal. These multiple words are referred to as the spectrum of incident word. The emergent multiple words each have different deviation or rotational values, starting with lower deviations, then to higher ones. A spectrum of incident word consisting of emergent word(s) can be recombined to form back the incident word. This can be done by picking of the emergent words and rotating it back by the same deviation value used to rotate it. Another approach is to pick the last bit of each emergent word and the first bit of the last emergent word in a systematic fashion, starting from the word with the least deviation and progressing downwards to the word with the most deviation and concatenating them. At this point, a word or classical string is produced and this corresponds to the incident word.   Left (or anticlockwise) rotation In Fig. 5 above as an example, the incident bit string 101, splits into 2 emergent bit strings 011 and 110 by avenue of rotation. These 2 emergent bit strings recombine again to form back 101 using the principle stated in the "classical perspective section. " The recombination is achieved by concatenating the last bit of each emergent bit strings plus the first bit of the last emergent bit string. This approach is for left or anticlockwise rotation.

Right (or clockwise) rotation
In Fig. 9 above as an example, the incident bit string 101, splits into 2 emergent bit strings 110 and 011 by avenue of rotation. These 2 emergent bit strings recombines again to form back 101 using the principle stated in the "classical perspective section. " The recombination is achieved by concatenating the first bit of the first emergent bit string plus the last bit of each emergent bit string. This approach is for right or clockwise rotation.

Quantum-classical perspective
In the quantum-classical perspective, qbits (quantum bits) must be represented in multiple cbits (classical bits) by means of applying tensor product to produce the product state. The product state can be factored back into the individual state representation. The product state of n bits is a vector of size 2 n . For example, the quantum bit strings |101>, |1011>, and |01110> in Dirac notation give corresponding classical bits (in the form of a vector or product state) after the tensor product has been applied to all the quantum bits in vector form.  The quantum string |101> results in a classical string 00000010.  The quantum string |1011> results in a classical string 0000000000000010 The quantum string |01110> results in a classical string 0000000000000100000000000 0000000. The classical bit strings obtained from the quantum bit strings become the incident binary strings which is passed through the conceptual bit prism, just like what was done for the examples in the classical perspective. This produces a number of emergent classical strings (n − 1) by means of circular rotation, where n is the number of bits in the vector/classical bit string (product state). Bit(s) are subsequently extracted from the emergent classical strings to form back the incident classical bit string or vector. This resulting incident string or vector can be factored back into the individual state representation, and then subsequently back to the quantum bit representation.

Quantum perspective (QRotate)
From a quantum perspective, bit rotation is made possible by avenue of a swap gate, control bit, and data. The algorithm that is proposed can perform shift left, shift right, rotation left and rotation right on an n-qubit string. This algorithm is demonstrated at the Results section of this paper, however, the method or approach is explained below. The following five principles are employed in the quantum bit rotation process; control bit selection, bit swapping, and bit truncation. Below is the steps for the quantum bit string rotation.

A quantum bit string is chosen. 2.
A control bit is selected and could be either |0> or |1>. 3. The control bit is placed or concatenated to the beginning or the end of the quantum bit string resulting in a new quantum bit string. 4. The swapping process begins from the position where the control bit is placed and successive bits in a progressive order is swapped till (n − 1) position is reached. 5. At this stage n − 1, quantum bit strings is obtained. 6. The last quantum bit string is the string obtained after the rotational swap is done.
However, any repeated quantum string during the rotational swap is discarded or excluded otherwise it is included in the set of quantum bit stings. 7. To decode and get back the original quantum bit string, the last but one and the last bit are swapped if the control bit was placed at the beginning of the quantum bit string. If the control bit was placed at the end of the quantum bit string, then the first and second bits are swapped. Swapping of bits is done using the swap gate. 8. If the control bit was placed at the beginning of the quantum bit string, the last bit is truncated otherwise the first bit is truncated. Alternatively, the rotated bit string obtained in step 6 can be rotated by means of swapping in a reverse order till the position where the control bit was concatenated to get back the original quantum bit string. 9. At this stage, the original quantum bit string is obtained.

Alternative approach
From a quantum perspective, bit rotation is made possible by avenue of use of a swap gate only. Here, bits are swapped from position 0 of the quantum string to position n. To Let's consider the quantum bit strings |101>, |1011>, |01110> and |1101010> using the alternative approach. The following results is obtained.

|101>
Original quantum string: |101> Bit swapping using swap gate from position 0 to n. The results above is shown from Figs. 21, 22, 23 and 24 in the "Quantum Implementation using jsqubits" section.  Various models for circular bit rotation using bits and qubits have been presented using bit strings or words. These models have been implemented in the C++ programming language, that is for the classical, and jsqubits for the quantum. They are both functional and effective. The execution time (seconds) of 101, 1011, 01110, 1101010 for both left and right circular rotation using the classical and quantum algorithms increases as the bit string becomes longer. However, from Figs. 25, 26 and 27 below, it is realized that the execution time for the quantum code is far smaller than the classical code for all the bit strings. This seems to suggest that the quantum algorithm is faster in terms of execution time as compared to the classical algorithm.
Below is the execution times shown in Figs. 25, 26 and 27.

Performance analysis of bit rotation algorithms and techniques
The running times, operation and support of some bit rotation algorithms or techniques including CRotate and QRotate (classical and quantum approach proposed in this paper) are summarized in Table 1 below.

Discussion
The classical implementation or algorithm in the results section, accepts a binary input or string, rotates the bit string circularly using bit rotation and the conceptual bit prism and emergent strings come out as the output. These emergent strings are recombined (by means of extracting bit(s) from each of the strings) to form back the original or incident string. The quantum snippets of code accepts a quantum bit string, swaps the bits

Conclusion
Based on the galloping rate of the development and implementation of classical and quantum models, this paper also seeks to propose a model for circular bit rotation using a conceptual bit prism drawn from the inspiration of white light going through a glass prism. Existing techniques in circular bit rotation have some challenge with respect to the fact that it does not have an end and keeps going on in cycles or in a circle and also produces some form of repeating bit strings at some point in the rotational process. This necessitated the need to use the bit prism concept in this work to help address this challenge and from the method and results above, it has been addressed incorporating a high level of strictness in the rotational process especially for the classical aspect. The quantum bit rotation in this paper, however, uses a bit swapping technique by avenue of a quantum swap gate made available in jsqubits. Future works will be to use this concept for cryptographic purposes.