public static void RotateLeft(byte[] bytes)
bool carryFlag = ShiftLeft(bytes);
bytes[bytes.Length - 1] = (byte)(bytes[bytes.Length - 1] | 0x01);
public static void RotateRight(byte[] bytes)
bool carryFlag = ShiftRight(bytes);
bytes[0] = (byte)(bytes[0] | 0x80);
public static bool ShiftLeft(byte[] bytes)
bool leftMostCarryFlag = false;
for (int index = 0; index < bytes.Length; index++)
bool carryFlag = (bytes[index] & 0x80) > 0;
bytes[index - 1] = (byte)(bytes[index - 1] | 0x01);
leftMostCarryFlag = carryFlag;
bytes[index] = (byte)(bytes[index] << 1);
return leftMostCarryFlag;
public static bool ShiftRight(byte[] bytes)
bool rightMostCarryFlag = false;
int rightEnd = bytes.Length - 1;
for (int index = rightEnd; index >= 0; index--)
bool carryFlag = (bytes[index] & 0x01) > 0;
bytes[index + 1] = (byte)(bytes[index + 1] | 0x80);
rightMostCarryFlag = carryFlag;
bytes[index] = (byte)(bytes[index] >> 1);
return rightMostCarryFlag;
public static void Test(byte[] bytes) {
var builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++) {
builder.Append(bytes[i].ToString("x2"));
var carry = ShiftLeft(bytes);
bytes[bytes.Length-1] |= 1;
Console.WriteLine(Encoding.UTF8.GetString(bytes, 0, bytes.Length));
builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++) {
builder.Append(bytes[i].ToString("x2"));
public static void Main()
byte[] rg = {0xfb, 0x4e, 0x56, 0x86, 0x23, 0xb5, 0xf8, 0xcf, 0x7e, 0x93, 0x2e, 0x6b, 0xa7, 0xed, 0xdc, 0x0d, 0xb9, 0xf4, 0x2a, 0x71, 0x27, 0x18, 0xf4, 0x88, 0xbd, 0xc0, 0xbf, 0x88, 0x0d, 0xd3 };
Console.WriteLine(Encoding.UTF8.GetString(rg, 0, rg.Length));
for (int i = 0; i< (rg.Length*8); i++) {
Console.WriteLine("Siuan you beaut!");