Пример #1
0
        public string Decrypt(Safer sfr, IProgress <int> progress, CancellationToken token, string iv = "12345678", int n = 8)
        {
            List <byte[]> listOfArraysOfEncryptedBytes = GetListOfArraysOfEncryptedBytesFromText(sfr.Text);
            string        decryptedText = "";

            byte[] ivBytes = Encoding.Default.GetBytes(iv);
            for (int i = 0; i < listOfArraysOfEncryptedBytes.Count; i++)
            {
                sfr.Text = System.Text.Encoding.Default.GetString(listOfArraysOfEncryptedBytes[i]);
                var tempBytes = sfr.decrypt();

                for (int j = 0; j < tempBytes.Length; j++)
                {
                    if (i == 0)
                    {
                        tempBytes[j] = XOR(ivBytes[j], tempBytes[j]);
                    }
                    else
                    {
                        tempBytes[j] = XOR(listOfArraysOfEncryptedBytes[i - 1][j], tempBytes[j]);
                    }
                }
                decryptedText += System.Text.Encoding.Default.GetString(tempBytes).Replace("\0", "");
                if (token.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                }
            }
            return(decryptedText);
        }
Пример #2
0
        public string Decrypt(Safer sfr, IProgress <int> progress, CancellationToken token, string iv = "12345678", int n = 8)
        {
            List <byte[]> listOfArraysOfEncryptedBytes = GetListOfArraysOfEncryptedBytesFromText(sfr.Text, 8);
            string        decryptedText = "";

            for (int i = 0; i < listOfArraysOfEncryptedBytes.Count; i++)
            {
                sfr.Text = System.Text.Encoding.Default.GetString(listOfArraysOfEncryptedBytes[i]);
                var tempBytes = sfr.decrypt();
                decryptedText += System.Text.Encoding.Default.GetString(tempBytes).Replace("\0", "");
                SetProgress(progress, (decimal)i / (decimal)listOfArraysOfEncryptedBytes.Count);
                if (token.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                }
            }
            return(decryptedText);
        }