利用排列函數,解密碼
aaaa
static void Main()
{
Stopwatch l_cc_stopWatch = new Stopwatch();
l_cc_stopWatch.Start();
string l_str_password = "icde";
/*
排列:从n个不同元素中,任取m(m≤n)个元素,按照一定的顺序排成一列,叫做从n个不同元素中取出m个元素的一个排列.
從排列的公式中可以看出,從1,2,3中取出2位,結果為:123,132,213,231,321,312,然而用戶填寫的密碼可能是11,22,33
故:本破解密碼程序只能破解不包含相同元素的密碼。
*/
Dictionary<int, string> l_cc_dictionary = new Dictionary<int, string>();
l_cc_dictionary.Add(1, "1");
l_cc_dictionary.Add(2, "2");
l_cc_dictionary.Add(3, "3");
l_cc_dictionary.Add(4, "4");
l_cc_dictionary.Add(5, "5");
l_cc_dictionary.Add(6, "6");
l_cc_dictionary.Add(7, "7");
l_cc_dictionary.Add(8, "8");
l_cc_dictionary.Add(9, "9");
l_cc_dictionary.Add(10, "a"); //用10代表字符串"a"
l_cc_dictionary.Add(11, "b"); //
l_cc_dictionary.Add(12, "c");
l_cc_dictionary.Add(13, "d");
l_cc_dictionary.Add(14, "e");
l_cc_dictionary.Add(15, "f");
l_cc_dictionary.Add(16, "g");
l_cc_dictionary.Add(17, "h");
l_cc_dictionary.Add(18, "i");
l_cc_dictionary.Add(19, "j");
l_cc_dictionary.Add(20, "k");
l_cc_dictionary.Add(21, "l");
l_cc_dictionary.Add(22, "m");
l_cc_dictionary.Add(23, "n");
l_cc_dictionary.Add(24, "o");
l_cc_dictionary.Add(25, "p");
l_cc_dictionary.Add(26, "q");
l_cc_dictionary.Add(27, "r");
l_cc_dictionary.Add(28, "s");
l_cc_dictionary.Add(29, "t");
l_cc_dictionary.Add(30, "u");
l_cc_dictionary.Add(31, "v");
l_cc_dictionary.Add(32, "w");
l_cc_dictionary.Add(33, "z");
l_cc_dictionary.Add(34, "y");
l_cc_dictionary.Add(35, "z");
//可以繼續往下加判斷的字符,如大寫字母A,B,C,!,@,^
int l_int_length = l_cc_dictionary.Count;
for (int i = 1; i <= l_int_length; i++)
{
bool l_bool_IsRegex = false;
int[,] source=Combinatorics.Arrange(i, l_int_length);
int b1 = source.GetUpperBound(0), b2 = source.GetUpperBound(1);
for (int a = 0; a <= b2; a++) //对各返回排列循环
{
string l_str_getPassword = null;
for (int b = 0; b <= b1; b++)
{
l_str_getPassword += l_cc_dictionary[(int)source[b, a]]; //用序数指针获取原元素的值
}
Console.WriteLine(l_str_getPassword);
if (l_str_getPassword == l_str_password)
{
l_bool_IsRegex = true;
break;
}
}
if (l_bool_IsRegex)
{
break;
}
}
l_cc_stopWatch.Stop();
Console.WriteLine("{0}:seconds", l_cc_stopWatch.Elapsed.TotalSeconds);
}
static void Main()
{
Stopwatch l_cc_stopWatch = new Stopwatch();
l_cc_stopWatch.Start();
string l_str_password = "icde";
/*
排列:从n个不同元素中,任取m(m≤n)个元素,按照一定的顺序排成一列,叫做从n个不同元素中取出m个元素的一个排列.
從排列的公式中可以看出,從1,2,3中取出2位,結果為:123,132,213,231,321,312,然而用戶填寫的密碼可能是11,22,33
故:本破解密碼程序只能破解不包含相同元素的密碼。
*/
Dictionary<int, string> l_cc_dictionary = new Dictionary<int, string>();
l_cc_dictionary.Add(1, "1");
l_cc_dictionary.Add(2, "2");
l_cc_dictionary.Add(3, "3");
l_cc_dictionary.Add(4, "4");
l_cc_dictionary.Add(5, "5");
l_cc_dictionary.Add(6, "6");
l_cc_dictionary.Add(7, "7");
l_cc_dictionary.Add(8, "8");
l_cc_dictionary.Add(9, "9");
l_cc_dictionary.Add(10, "a"); //用10代表字符串"a"
l_cc_dictionary.Add(11, "b"); //
l_cc_dictionary.Add(12, "c");
l_cc_dictionary.Add(13, "d");
l_cc_dictionary.Add(14, "e");
l_cc_dictionary.Add(15, "f");
l_cc_dictionary.Add(16, "g");
l_cc_dictionary.Add(17, "h");
l_cc_dictionary.Add(18, "i");
l_cc_dictionary.Add(19, "j");
l_cc_dictionary.Add(20, "k");
l_cc_dictionary.Add(21, "l");
l_cc_dictionary.Add(22, "m");
l_cc_dictionary.Add(23, "n");
l_cc_dictionary.Add(24, "o");
l_cc_dictionary.Add(25, "p");
l_cc_dictionary.Add(26, "q");
l_cc_dictionary.Add(27, "r");
l_cc_dictionary.Add(28, "s");
l_cc_dictionary.Add(29, "t");
l_cc_dictionary.Add(30, "u");
l_cc_dictionary.Add(31, "v");
l_cc_dictionary.Add(32, "w");
l_cc_dictionary.Add(33, "z");
l_cc_dictionary.Add(34, "y");
l_cc_dictionary.Add(35, "z");
//可以繼續往下加判斷的字符,如大寫字母A,B,C,!,@,^
int l_int_length = l_cc_dictionary.Count;
for (int i = 1; i <= l_int_length; i++)
{
bool l_bool_IsRegex = false;
int[,] source=Combinatorics.Arrange(i, l_int_length);
int b1 = source.GetUpperBound(0), b2 = source.GetUpperBound(1);
for (int a = 0; a <= b2; a++) //对各返回排列循环
{
string l_str_getPassword = null;
for (int b = 0; b <= b1; b++)
{
l_str_getPassword += l_cc_dictionary[(int)source[b, a]]; //用序数指针获取原元素的值
}
Console.WriteLine(l_str_getPassword);
if (l_str_getPassword == l_str_password)
{
l_bool_IsRegex = true;
break;
}
}
if (l_bool_IsRegex)
{
break;
}
}
l_cc_stopWatch.Stop();
Console.WriteLine("{0}:seconds", l_cc_stopWatch.Elapsed.TotalSeconds);
}
using System;
using System.Collections;
using System.Data;
/// <summary>
/// 组合数学函数集
/// </summary>
public class Combinatorics
{
公共函数
内部核心
}
using System.Collections;
using System.Data;
/// <summary>
/// 组合数学函数集
/// </summary>
public class Combinatorics
{
公共函数
内部核心
}