OJ Problem 3492 DES symmetric encryption algorithm

Title description

Refer to related literature and design a DES symmetric encryption algorithm. And write a console application to verify. The key is set to: @1234567. 
    class Program{  
        //Verify DES encryption algorithm
        static void Main(string[] args){             Console.WriteLine(Class1.ECP("absg123@&!"));         }     }     public class Class1 {         //The following ECP method function is adopted Symmetric encryption algorithm         //The principle of this algorithm, please Baidu         const string KEY_64 = "@1234567";         const string IV_64 = "@1234567";         public static string ECP(string data) {               //Write the DES symmetric encryption algorithm code here         }










enter

A string

Output

Encrypted string

Sample input

123456

Sample output

czgzz5i20Rw =
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.IO;
namespace ConsoleApplication1
{
    class Program
    {
        //验证DES加密算法
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            Console.WriteLine(Class1.ECP(input, "@1234567"));
        }
    }
    public class Class1
    {
        //下面ECP方法功能为采用对称加密算法
        //该算法原理请大家百度
        public static string ECP(string encryptString, string encryptKey)
        {
            try
            {
                byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
                byte[] rgbIV = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
                byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
                DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
                MemoryStream mStream = new MemoryStream();
                CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
                cStream.Write(inputByteArray, 0, inputByteArray.Length);
                cStream.FlushFinalBlock();
                return Convert.ToBase64String(mStream.ToArray());
            }
            catch
            {
                return encryptString;
            }
        }
    }
}

This blog reference: https://www.cnblogs.com/mjn1/p/12507850.html

I do not understand the essence of DEC symmetric encryption algorithm

Guess you like

Origin blog.csdn.net/wangws_sb/article/details/104930686