Exemple #1
0
        public static string Encrypt(string text, PublicKey key)
        {
            var generator = new BbsGenerator(key.N);

            var result = new StringBuilder();

            foreach (var c in text)
            {
                var b = generator.GetNext();
                var t = c;
                result.Append((char)(t ^ b));
            }
            generator.GetNext();
            result.Append($"#{generator.X}");
            return(result.ToString());
        }
Exemple #2
0
        public static string Decrypt(string encryptedText, Key key, int length)
        {
            var seed = GetLastSeed(encryptedText);
            var x0   = RestoreX0(key, length, seed);

            Console.WriteLine($"Restored x0={x0}");

            var generator = new BbsGenerator(key.PublicKey.N, x0);
            var result    = new StringBuilder();

            for (var i = 0; i < length; i++)
            {
                var b = generator.GetNext();
                var t = encryptedText[i];
                result.Append((char)(t ^ b));
            }
            return(result.ToString());
        }