VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > c#编程 >
  • 利用c#对数字进行加密

今天我们来讲一下如何进行加密的实例,首衔这里声明了一个名为My303类,接下来在控制台接收用户输入的数字, 即 Console.WriteLine("请输入四位整数:"); int i=int.Parse(Console.ReadLine()); 接下来 int first = i/1000; int second = (i/100)%10; int third = (i/10)%10; int forth = i%10; 用以上方式,将数字i进行运算,重新赋值给first、second、third和forth等四个变量 Console.WriteLine(first+" "+second+" "+third+" "+forth); 以上代码用于将四个运算后的结果输出 first = (first+7)%10; second =(second+7)%10; third = (third+7)%10; forth = (forth+7)%10; 用于二次加密 int temp=third; third=first ; first = temp; 用于将third和first对换值 temp= forth; forth= second; second = temp; 用于将forth和second对换值 int pass = first1000+second100+third*10 +forth; 再次利用first、second、third和forth进行运算,将结果输出

using System;
using System.Threading;

class My303
{
    static void Main()
    {
        Console.WriteLine("请输入四位整数:");
        int i=int.Parse(Console.ReadLine());

        int first = i/1000;
        int second = (i/100)%10;
        int third = (i/10)%10;
        int forth = i%10;

        Console.WriteLine(first+" "+second+" "+third+" "+forth);

        first = (first+7)%10;
        second =(second+7)%10;
        third = (third+7)%10;
        forth = (forth+7)%10;

        int temp=third;
        third=first ;
        first = temp;

        temp= forth;
        forth= second;
        second = temp;

        int pass = first*1000+second*100+third*10    +forth;

        Console.WriteLine("Now is "+pass);

        Thread.Sleep(5000);
    }
}


相关教程