密码破解,N位随机序列数的生成
2016-03-06 12:56
405 查看
可生成N位随机但不重复的序列数,可用于密码的随机碰撞破解
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace wpcCreater
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// 生成随机序列数
private void button1_Click(object sender, EventArgs e)
{
try
{
int N = Int32.Parse(textBox1.Text.Trim()); // 序列数的位数
string[] serial = getSerial(10, -1, N); // 获取0-9之间的N位序列数
textBox2.Text = getSerialN(N);
}
catch (Exception ex) { MessageBox.Show("序列数的位数最小为1"); }
}
// 文本全选
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.A && e.Control)
{
textBox2.SelectAll();
}
}
// N位0-9之间的序列数生成算法,生成的序列数可用于密码的随机不重复破解
public static string getSerialN(int N)
{
string[] serial = getSerial(10, -1, N); // 获取0-9之间的N位序列数
string tmp = "";
foreach (string s in serial)
tmp += s + "\r\n";
return tmp;
}
/** 序列数生成算法,生成【1+offset,n+offset】之间的随机序列数组,每个数值出现且仅出现一次 */
public static int[] getSerial(int n, int offset)
{
Random Rnd = new Random();
int[] tmp = new int
;
int[] num1 = new int
;
for (int i0 = 1; i0 <= n; i0++)
num1[i0 - 1] = i0 + offset;
for (int i = num1.Length; i > 0; i--)
{
int index = Rnd.Next(i);
// 随机选中一个数
tmp[i - 1] = num1[index];
// 剔除选中的数值
int[] num2 = new int[i - 1];
for (int j = 0; j < i; j++)
if (j < index)
num2[j] = num1[j];
else if (j > index) num2[j - 1] = num1[j];
num1 = num2;
}
return tmp;
}
/** 序列数生成算法,生成由序列数组成的N位数, 一位序列数范围【1+offset,n+offset】*/
public static string[] getSerial(int n, int offset, int N)
{
string[] S = new string[] { "" };
for (int i = 0; i < N; i++)
{
int[] serial = getSerial(10, -1);// 生成0到9随机序列数
S = addSerial(S, serial);
}
return S;
}
// 向已有的序列数组sBase中添加一位序列数
public static string[] addSerial(string[] sBase, int[] serial)
{
string[] serials = new string[sBase.Length * serial.Length];
int i = 0;
foreach (string s1 in sBase)
foreach (int s2 in serial)
serials[i++] = s1 + s2;
return serials;
}
}
}
namespace wpcCreater { partial class Form1 { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.textBox1 = new System.Windows.Forms.TextBox(); this.textBox2 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(142, 10); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = "生成"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(60, 12); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(62, 21); this.textBox1.TabIndex = 1; this.textBox1.Text = "3"; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(10, 42); this.textBox2.Multiline = true; this.textBox2.Name = "textBox2"; this.textBox2.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.textBox2.Size = new System.Drawing.Size(217, 340); this.textBox2.TabIndex = 2; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(13, 15); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(41, 12); this.label1.TabIndex = 3; this.label1.Text = "位数:"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(237, 386); this.Controls.Add(this.label1); this.Controls.Add(this.textBox2); this.Controls.Add(this.textBox1); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "序列数生成器"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button button1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Label label1; } }
相关文章推荐
- 进入dos的一个密码破解方法
- Python脚本暴力破解栅栏密码
- Excel—“撤销工作表保护密码”的破解并获取原始密码
- 无线网络密码破解方法
- 华为交换机S9303密码破解
- 如何获取某个wifi的密码[Aircrack-ng篇]
- 解密WPA/WPA2加密高速破解的真相
- Cisco2960交换机密码破解方法
- 常用电脑密码破解实用技巧
- 常见计算机密码破解实用手册!
- 计算机十二种常用密码破解法
- linux的一点基本知识
- Linux密码破解
- VBA 密码破解
- 30 recover pass
- 计算机12种常用密码破解法
- linux下如何进入单人维护模式,忘记密码的解决方法
- linux密码破解
- BackTrack5 (BT5)无线wep密码破解教程之minidwep-gtk破解法
- Linux下root用户密码修改