系统粉 > 电脑问答 > 其他问答

已解决c#控制台程序 解疑

提问者:三振王  |  浏览次  |  提问时间:2017-03-15  |  回答数量:1

c#控制台程序 解疑 做一个模拟暴力破解密码的程序,代码如下:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{class Program{static void Main(string[] args){ Console.WriteLine(\"请输入一个四位数的密码(只能是数字):\");string str = Console.ReadLine();for (int a = 0; a <= 9; a++){for (int b = 0; b <= 9; b++){for (int c = 0; c <= 9; c++){for (int d = 0; d <= 9; d++){if (((a.ToString()) + (b.ToString()) + (c.ToString()) + (d.ToString())) == str){Console.WriteLine(((a.ToString())

已有1条答案
寒寒的韩

寒寒的韩

回答数:104  |  被采纳数:71

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
int num = Convert.ToInt32(textBox1.Text.Trim());
string str = textBox1.Text.Trim();
int lend = str.Length;
switch (lend)
{
case 1:
a();
break;
case 2:
b();
break;
case 3:
c();
break;
case 4:
d();
break;
case 5:
f();
break;
}
}
catch
{
MessageBox.Show("密码只能是数字!","错误!");
textBox1.Text = "";
}
}

private void a()
{
for (int a = 0; a <= 9; a++)
{
if (a.ToString() == textBox1.Text.Trim())
{
textBox2.Text = a.ToString();
}
}
}

private void b()
{
for (int a = 0; a <= 9; a++)
{
for (int b = 0; b <= 9; b++)
{
if (a.ToString()+b.ToString() == textBox1.Text.Trim())
{
textBox2.Text = a.ToString()+b.ToString();
}
}
}
}

private void c()
{
for (int a = 0; a <= 9; a++)
{
for (int b = 0; b <= 9; b++)
{
for (int c = 0; c <= 9; c++)
{
if (a.ToString() + b.ToString() + c.ToString() == textBox1.Text.Trim())
{
textBox2.Text=((a.ToString()) + (b.ToString()) + (c.ToString()) );
}
}
}
}
}

private void d()
{
for (int a = 0; a <= 9; a++)
{
for (int b = 0; b <= 9; b++)
{
for (int c = 0; c <= 9; c++)
{
for (int d = 0; d <= 9; d++)
{
if (((a.ToString()) + (b.ToString()) + (c.ToString()) + (d.ToString())) == textBox1.Text.Trim())
{
textBox2.Text=((a.ToString()) + (b.ToString()) + (c.ToString()) + (d.ToString()));
}

}
}
}
}
}

private void f()
{
for (int a = 0; a <= 9; a++)
{
for (int b = 0; b <= 9; b++)
{
for (int c = 0; c <= 9; c++)
{
for (int d = 0; d <= 9; d++)
{
for (int e = 0; e <= 9; e++)
{
if (((a.ToString()) + (b.ToString()) + (c.ToString()) + (d.ToString())+(e.ToString())) == textBox1.Text.Trim())
{
textBox2.Text=((a.ToString()) + (b.ToString()) + (c.ToString()) + (d.ToString()) + (e.ToString()));
}
}
}
}
}
}
}
}
}
2017-03-15 07:19:53
赞 10
相关问答
最新其他问答
解决方法