Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Password management
Message
De
28/05/2013 09:32:56
 
 
À
28/05/2013 07:20:01
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01574811
Message ID:
01574925
Vues:
46
>>Haven't figured out the total number of permutations yet
>>
>>Say, 6 chars with at least one digit
>>
>>I can put the digit in the first position, second, third, ... sixth
>>
>>So that would be 6 * 52^5 * 10 which is 52^5 * 60 and this is greater than 52^6
>
>Couldn't resist a quick play:
       private static void Main(string[] args)
>        {
>            Stopwatch watch = new Stopwatch();
>            watch.Start();
>            foreach (string s in GetValidPasswordList())
>            {
>                Console.WriteLine(s);
>            }
>            Console.WriteLine(watch.Elapsed);
>            Console.ReadLine();
>        }
>
>        public static IEnumerable<string> GetValidPasswordList()
>        {
>            int total = 0;
>            for (int x = 1; x<63; x++)
>            {
>                for (int y = 1; y<63; y++)
>                {
>                    for (int z = 0; z < ((y < 53 && x < 53) ? 63 : 11); z++) //24 seconds
>                    //for (int z = 0; z < 63; z++ ) // 31 seconds
>                    {
>                        yield return string.Format("{0}.{1}.{2}  (Total:{3})", x, y, z, total++);
>                    }
>                }
>            }
>        }
>Couldn't be bothered with real chars but the principle's the same. 24 seconds v 31


(1) Done the same - added two methods ( Possibilities() and ListPossibilities())
GetValidPasswordList() yields 182,192 possibilities

The others yield 97,720 possibilities

(2) And to answer the question:
How many possibilties are there for a password of 6 upper/lower case chars where at least one upper and at least one lower

See method Password6()

The answer is 19,152,778,112

this is 96.88% of 52^6


But I haven't been able to find a formula
delegate IEnumerable<string> TheMethod();
	public static class AClass
	{

		static long Total = 0L;
		static string AlphaDigit = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
		static string Alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

		public static void Main()
		{

			string s = null;

			TheMethod[] list = { GetValidPasswordList, Possibilities, ListPossibilities };

			foreach (TheMethod method in list)
			{
				foreach (string x in method())
				{
					s = x;
				}

				Console.WriteLine("Method {0}   {1}", method.GetInvocationList()[0].Method.Name, s);
			}

			Console.WriteLine("password 6 with at least one upper and at least one lower {0}", Password6());
			Console.ReadLine();
		}
		static IEnumerable<string> Possibilities()
		{
			Total = 0;
			// 1- 10 is digit
			// 11 - 62 is a-zA-Z

			for (int i = 1; i < 63; i++)
				for (int j = 1; j < 63; j++)
					for (int k = 1; k < 63; k++)
						if (i > 10 && j > 10 && k > 10)
							continue;
						else
							yield return String.Format("{0} {1} {2}  Total {3}", i, j, k, ++Total);
		}

		static IEnumerable<string> ListPossibilities()
		{
			Total = 0;
			int len = AlphaDigit.Length ;
			Debug.Assert(AlphaDigit.Length == 62);
			
			char a, b, c ;
			for( int i = 0; i < len; i++ )
			{
				a = AlphaDigit[i];
				for( int j = 0; j < len; j++ )
				{
					b = AlphaDigit[j];
					for (int k = 0; k < len; k++)
					{
						c = AlphaDigit[k];
						if (!Char.IsDigit(a) && !Char.IsDigit(b) && !Char.IsDigit(c))
							continue;
						else
							yield return String.Format("{0} {1} {2}  Total {3}", a, b, c, ++Total);
					}
				}
			}

		}
		public static IEnumerable<string> GetValidPasswordList()
		{
			Total = 0;
			for (int x = 1; x < 63; x++)
			{
				for (int y = 1; y < 63; y++)
				{
					for (int z = 0; z < ((y < 53 && x < 53) ? 63 : 11); z++) //24 seconds
					//for (int z = 0; z < 63; z++ ) // 31 seconds
					{
						yield return string.Format("{0}.{1}.{2}  (Total:{3})", x, y, z, ++Total);
					}
				}
			}
		}

		static double Password6()
		{
			decimal total = 0m;
			int len = Alpha.Length;
			for (int l1 = len; --l1 >= 0; )
			{
				char c1 = Alpha[l1];
				Console.WriteLine(l1);
				for (int l2 = len; --l2 >= 0; )
				{
					char c2 = Alpha[l2];

					for (int l3 = len; --l3 >= 0; )
					{
						char c3 = Alpha[l3];

						for (int l4 = len; --l4 >= 0; )
						{
							char c4 = Alpha[l4];

							for (int l5 = len; --l5 >= 0; )
							{
								char c5 = Alpha[l5];

								for (int l6 = len; --l6 >= 0; )
								{
									char c6 = Alpha[l6];

									if (!Char.IsLower(c1)
										&& !Char.IsLower(c2)
										&& !Char.IsLower(c3)
										&& !Char.IsLower(c4)
										&& !Char.IsLower(c5)
										&& !Char.IsLower(c6)
									)
										continue;

									if (!Char.IsUpper(c1)
										&& !Char.IsUpper(c2)
										&& !Char.IsUpper(c3)
										&& !Char.IsUpper(c4)
										&& !Char.IsUpper(c5)
										&& !Char.IsUpper(c6)
									)
										continue;

									total++;
								}

							}
						}
					}

				}

			}
			return (double)total;

		}
	}
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform