係統粉 > 電腦問答 > 其他問答

已解決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
相關問答
最新其他問答
解決方法