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

本课我们来讲一下,如何利用C#进行加密,在类中的main方法中, 首先输出提示即“请输入四位整数”,接下来我们将输入的数字 存入到变量i中,再将变量i进行转换,即分别进行运算,运算后 存储到变量first、seconc、third、forth等四个变量中,然后在 控制台上输出,所有变量的值的组合连接,即

        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);

全部代码如下:

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);
    }
}


相关教程