自製暴力破解字典檔3位數英文
這篇示範英文大寫字母AAA-ZZZ的字典檔怎麼產生
利用迴圈去設定陣列 ASCII 65~90
再用三個迴圈把字母串起來,變成三位數
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Dict
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();//隱藏
int[] x = new int[26];//26個英文字母
int Num = 64;
//當成陣列的值,每次加一
for (int j = 0; j < 26; j++)
{
Num += 1;
x[j] = Num;
}
//取得執行目錄
string path = Directory.GetCurrentDirectory();
DateTime time_start = DateTime.Now;//取得目前時間
for (int i = 0; i < 26; i++)
{
for (int j = 0; j < 26; j++)
{
for (int k = 0; k < 26; k++)
{//寫入方法 參考http://msdn.microsoft.com/zh-tw/library/8bh11f1k.aspx
using (System.IO.StreamWriter file = new System.IO.StreamWriter(path+@"\"+"test.txt", true))
{
file.WriteLine(Chr(x[i]).ToString() + Chr(x[j]).ToString() + Chr(x[k]).ToString());
}
}
}
}
DateTime time_end = DateTime.Now;//計時結束 取得目前時間
string result2 = ((TimeSpan)(time_end - time_start)).TotalMilliseconds.ToString();
MessageBox.Show("寫入完成,花費時間" +result2+ "毫秒");
this.Close();//關閉程式
}
/// <summary>
/// ASCII碼轉字元
/// 參考 http://www.dotblogs.com.tw/dotnetfactory/archive/2008/04/10/2776.aspx
/// </summary>
/// <param name="Num"></param>
/// <returns></returns>
public static char Chr(int Num)
{
char C = Convert.ToChar(Num);
return C;
}
}
}
如有錯誤 歡迎指正