示例#1
0
        static void Main(string[] args)
        {
            string plain = "The quick brown fox jumped over the lazy dog." + Environment.NewLine +
                           "abcdefghijklmnopqrstuvwxyz" + Environment.NewLine +
                           "0123456789 - ' ! & $ Ю ( ) + / : = ? , .";

            bool lsbFirst = false;

            var baudot = Baudot.ToCode(plain, lsbFirst);

            int codesPrinted = 0;

            foreach (var b in baudot)
            {
                if (codesPrinted % 10 == 0)
                {
                    Console.WriteLine();
                }

                string binary = "0000" + Convert.ToString(b.Value, 2);

                Console.Write(binary.Substring(binary.Length - 5));
                Console.Write(' ');

                ++codesPrinted;
            }

            Console.WriteLine();
            Console.WriteLine();

            Console.Write(Baudot.FromCode(baudot, lsbFirst));

            Console.ReadKey();
        }
示例#2
0
        public void FromCodeMsbFirstShiftToFiguresTest()
        {
            string expected = "000";

            var baudot = new[] {
                new VBit(27), // Shift to figures
                new VBit(22),
                new VBit(31), // Shift to letters
                new VBit(27), // Shift to figures
                new VBit(22),
                new VBit(22),
                new VBit(31) // Shift to letters
            };

            var str = Baudot.FromCode(baudot, false);

            Assert.AreEqual(expected, str);
        }
示例#3
0
        public void FromCodeLsbFirstShiftToLettersTest()
        {
            string expected = "AAA";

            var baudot = new[] {
                new VBit(31), // Shift to letter
                new VBit(24),
                new VBit(27), // Shift to figures
                new VBit(31), // Shift to letter
                new VBit(24),
                new VBit(24),
                new VBit(27) // Shift to figures
            };

            var str = Baudot.FromCode(baudot, true);

            Assert.AreEqual(expected, str);
        }
示例#4
0
        public void FromCodeMsbFirstFiguresTest()
        {
            string expected = "0123456789!$&'()+,-./:=?";

            var baudotFigures = new[] {
                new VBit(27), // Shift to figures
                new VBit(22), new VBit(23),
                new VBit(19), new VBit(1),
                new VBit(10), new VBit(16),
                new VBit(21), new VBit(7),
                new VBit(6), new VBit(24),
                new VBit(13), new VBit(20),
                new VBit(26), new VBit(5),
                new VBit(15), new VBit(18),
                new VBit(17), new VBit(12),
                new VBit(3), new VBit(28),
                new VBit(29), new VBit(14),
                new VBit(30), new VBit(25)
            };

            var str = Baudot.FromCode(baudotFigures, false);

            Assert.AreEqual(expected, str);
        }
示例#5
0
        public void FromCodeMsbFirstAlphabet()
        {
            string expected = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var baudotAlphabet = new[] {
                new VBit(3), new VBit(25),
                new VBit(14), new VBit(9),
                new VBit(1), new VBit(13),
                new VBit(26), new VBit(20),
                new VBit(6), new VBit(11),
                new VBit(15), new VBit(18),
                new VBit(28), new VBit(12),
                new VBit(24), new VBit(22),
                new VBit(23), new VBit(10),
                new VBit(5), new VBit(16),
                new VBit(7), new VBit(30),
                new VBit(19), new VBit(29),
                new VBit(21), new VBit(17)
            };

            var str = Baudot.FromCode(baudotAlphabet, false);

            Assert.AreEqual(expected, str);
        }
示例#6
0
        static void Main(string[] args)
        {
            string plain = "NOW IS THE TIME FOR ALL GOOD MEN TO COME TO THE AID OF THE PARTY";

            // Lorenz uses LSB first Baudot (hence the 2nd arg).
            var baudot = Baudot.ToCode(plain, true);

            //baudot = BitConverter.FromBase64("QGEzg0oKhIiRmgmpMUJgjkj5IgS4CSyR4DQgzEKxZSDgoj8JhQmDSIU=");

            // Scramble the baudot here...
            // (generate Tunny)

            // Pin settings: https://oilulio.wordpress.com/tag/cipher/
            string p1 = "....x...xx..x..x......x.xxxx...xx.x.....xx.";
            string p2 = ".x..x.......x.xxx...xx.x..xx....xx....xxx......";
            string p3 = "....x..x.x.x..xxxx.xx...x.x...x.x.xx..xxxx.........";
            string p4 = ".xx..x.xx..x.x.x...xxxx.x..xxx.x..xx.xxx.............";
            string p5 = "..x.x....xxxx..xxxx.x.x.x..x..x.x.x.x..x.x.................";

            string m37 = ".x...................................";
            string m61 = ".....................x.......................................";

            string c1 = "...x..x.x.........xxxx...................";
            string c2 = "x..xx..x...xx..x....x.x........";
            string c3 = ".x.x.xx.x...x..x.x..x.x......";
            string c4 = "xx..xx.x.x..x...xxx.......";
            string c5 = ".x.....xx...xx.xxx...xx";

            PsiWheel1 psiWheel1 = WheelFactory.CreatePsiWheel1(p1);
            PsiWheel2 psiWheel2 = WheelFactory.CreatePsiWheel2(p2);
            PsiWheel3 psiWheel3 = WheelFactory.CreatePsiWheel3(p3);
            PsiWheel4 psiWheel4 = WheelFactory.CreatePsiWheel4(p4);
            PsiWheel5 psiWheel5 = WheelFactory.CreatePsiWheel5(p5);

            MuWheel37 muWheel37 = WheelFactory.CreateMuWheel37(m37);
            MuWheel61 muWheel61 = WheelFactory.CreateMuWheel61(m61);

            ChiWheel1 chiWheel1 = WheelFactory.CreateChiWheel1(c1);
            ChiWheel2 chiWheel2 = WheelFactory.CreateChiWheel2(c2);
            ChiWheel3 chiWheel3 = WheelFactory.CreateChiWheel3(c3);
            ChiWheel4 chiWheel4 = WheelFactory.CreateChiWheel4(c4);
            ChiWheel5 chiWheel5 = WheelFactory.CreateChiWheel5(c5);

            var wheelBay = new WheelBay(
                psiWheel1, psiWheel2, psiWheel3, psiWheel4, psiWheel5,
                muWheel37, muWheel61,
                chiWheel1, chiWheel2, chiWheel3, chiWheel4, chiWheel5
                );

            SetWheelPositions(wheelBay);

            IEnumerable <VBit> enciphered = wheelBay.Process(baudot, true).ToList();

            Console.WriteLine("Enciphered:");
            Console.Write(Baudot.FromCode(enciphered, true));

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Base64 (first byte = length):");
            Console.WriteLine(BitConverter.ToBase64(enciphered));

            Console.WriteLine();
            Console.WriteLine();

            // Reset.
            SetWheelPositions(wheelBay);

            IEnumerable <VBit> deciphered = wheelBay.Process(enciphered, false).ToList();

            Console.WriteLine("Deciphered:");
            Console.Write(Baudot.FromCode(deciphered, true));

            Console.ReadKey();
        }
示例#7
0
 public void FromCodeArgumentNullTest()
 {
     Assert.Throws <ArgumentNullException>(
         () => Baudot.FromCode(null, true).ToList());
 }