unity游戏开发-C#语言基础篇(加密数字及解密数字)

 class Program
    {
        static void Main(string[] args)
        {
        chongfu:
            jiami();
            //jiemi();
            Console.ReadKey();
            goto chongfu;
        }
        public static void jiami()
        {
            Console.WriteLine("请输入4位数:");
            int num = Convert.ToInt32(Console.ReadLine());

            //if (num >= 1000 && num < 10000)
            //{
            int qianwei = num / 1000;//千位;
            int baiwei = num / 100 % 10;//百位;
            int shiwei = num / 10 % 10;//十位;
            int gewei = num % 10;//个位;

            qianwei = (qianwei + 5) % 10;
            baiwei = (baiwei + 5) % 10;
            shiwei = (shiwei + 5) % 10;
            gewei = (gewei + 5) % 10;

            string str = "";
            str = "" + gewei + shiwei + baiwei + qianwei;//前面加字符串符号“”;不能后面加,否则就运算;

            Console.WriteLine("加密数字为:{0}\n", str);

            int num1 = Convert.ToInt32(str);
            // Console.WriteLine(num1);
            qianwei = num1 / 1000;//千位;
            baiwei = num1 / 100 % 10;//百位;
            shiwei = num1 / 10 % 10;//十位;
            gewei = num1 % 10;//个位
            if (qianwei >= 5)
            {
                qianwei = (qianwei - 5);
            }
            else
            {
                qianwei = (5 + qianwei);
            }

            if (baiwei >= 5)
            {
                baiwei = (baiwei - 5);
            }
            else
            {
                baiwei = (5 + baiwei);
            }
            if (shiwei >= 5)
            {
                shiwei = (shiwei - 5);
            }
            else
            {
                shiwei = (5 + shiwei);
            }
            if (gewei >= 5)
            {
                gewei = (gewei - 5);
            }
            else
            {
                gewei = (5 + gewei);
            }

            str = "" + gewei + shiwei + baiwei + qianwei;
            Console.WriteLine("解密数字为:{0}\n", str);

        }

     
    }

你可能感兴趣的:(unity游戏开发-C#语言基础篇(加密数字及解密数字))