using System.Collections.Generic;
public class ShipCryptography
static readonly string input = @"10010110 11110111 01010110 00000001 00010111 00100110
01010111 00000001 00010111 01110110 01010111 00110110
11110111 11010111 01010111 00000011";
public static void Main(string[] args)
var bits = TextToBitArray(input);
var decryptedText = BitArrayToText(bits);
Console.WriteLine(decryptedText);
Console.WriteLine(e.Message);
static bool[] Decode(bool[] bits)
for (int i = 0; i < bits.Length - 4; i += 8)
var lastIndex = i + 8 - 1;
bits[lastIndex] = !bits[lastIndex];
bits[lastIndex - 1] = !bits[lastIndex - 1];
for (int i = 0; i < bits.Length / 8; i++)
for (int j = 0; j < 4; j++)
bool temp = bits[index1];
bits[index1] = bits[index2];
static bool[] TextToBitArray(string text)
var bits = new List<bool>();
foreach (var character in text)
if (character != '0' && character != '1')
bits.Add(character == '1');
throw new Exception("Bit quantity must be divisible by 8");
static string BitArrayToText(bool[] bits)
string text = string.Empty;
for (int i = 0; i < bits.Length; i += 8)
for (int j = 0; j < 8; j++)
var exponencial = 8 - j - 1;
characterValue += (int)Math.Pow(2, exponencial);
text += (char)characterValue;