using System;
using System.Threading;
class 加密
{
static void Main()
{
Console.WriteLine("请输入要加密的四位整数:");
int i=int.Parse(Console.ReadLine());
// 假设4395 /为除法,%求余!
int first = i/1000; // 整除得4 ,第一位4
int second = (i/100)%10; //43%10余3,第二位3
int third = (i/10)%10; //439%10余9,第3位9
int forth = i%10; //4395除10余5,第4位5
Console.WriteLine(first+" "+second+" "+third+" "+forth);
first = (first+7)%10; //加上7然后再%10求余
second =(second+7)%10;
third = (third+7)%10;
forth = (forth+7)%10;
int temp=third; //将第3位和第1位换位
third=first ;
first = temp;
temp= forth; //将第2位和第4位换位
forth= second;
second = temp;
int pass = first*1000+second*100+third*10+forth;
Console.WriteLine("加密后数变成:"+pass); //得到的结果是6210
Thread.Sleep(5000);
}
}
using System;
using System.Threading;
class 破解
{
static void Main()
{
Console.WriteLine("请输入你加密过的四个数:");//输入上次加密后的结果6210
int i=int.Parse(Console.ReadLine());
int first = i/1000; // 整除得6 ,第一位6
int second = (i/100)%10;//62%10余2,第二位2
int third = (i/10)%10; //621%10余1,第3位1
int forth = i%10; //6210除10余0,第4位0
Console.WriteLine(first+" "+second+" "+third+" "+forth);
int temp=third; //将第3位和第1位换位
third=first ;
first = temp;
temp= forth; //将第2位和第4位换位
forth= second;
second = temp;
first = (first+10)-7; //此处不能直接加3,因为有可能会超过10!
second =(second+10)-7;
third = (third+10)-7;
forth = (forth+10)-7;
int pass = first*1000+second*100+third*10+forth;
Console.WriteLine("破解成功了!原数为:"+pass);//得到原来的数4395
Thread.Sleep(5000);
}
}