编写一个简单的加密程序:输入四位整数,按照以下加密算法处理后,生成加密后的四位整数输出。 
加密算法:(每一位的数字+8)mod 10,处理后的数字中第1位和第四位交换,第2位和第3位交换。运行示例:输入四位整数: 7523加密后的四位整数是: 1035这是一个朋友的作业题,我30分帮他找找高手发到[email protected] 就可以

解决方案 »

  1.   

    /*
    编写一个简单的加密程序:输入四位整数,按照以下加密算法处理后,生成加密后的四位整数输出。 
    加密算法:(每一位的数字+8)mod 10,处理后的数字中第1位和第四位交换,第2位和第3位交换。 
    */
    using System;class Program
    {
      static void Main()
      {
        int x = int.Parse(Console.ReadLine());
        int y = (x % 10 + 8) % 10 * 1000
              + (x / 10 % 10 + 8) % 10 * 100
              + (x / 100 % 10 + 8) % 10 * 10
              + (x / 1000 % 10 + 8) % 10;
        Console.WriteLine("输入:{0},输出:{1}", x, y);
      }
    }
      

  2.   


            static int Encrypt(int input)
            {
                int a = (input / 1000 + 8) % 10;
                input %= 1000;
                int b = (input / 100 + 8) % 10;
                input %= 100;
                int c = (input / 10 + 8) % 10;
                input %= 10;
                int d = (input + 8) % 10;
                return d * 1000 + c * 100 + b * 10 + a;
            }
    是否害人自己权衡吧