Ejemplo n.º 1
0
        public string Unlock(IDigitalLock digitalLock)
        {
            string _lock = String.Empty;

            int  characterCount = 0;
            char temp           = digitalLock.Read(0);

            digitalLock.Turn(TurnDirection.Forward, 0, 1);
            characterCount++;
            while (temp != digitalLock.Read(0))
            {
                digitalLock.Turn(TurnDirection.Forward, 0, 1);
                characterCount++;
            }
            for (int i = 0; i < Math.Pow(characterCount, digitalLock.GetCipherLength()); i++)
            {
                string tryValue = Complete(i, digitalLock.GetCipherLength());
                digitalLock.Reset();
                for (int j = digitalLock.GetCipherLength() - 1; j >= 0; j--)
                {
                    digitalLock.Turn(TurnDirection.Forward, j, tryValue[j] - '0');
                }
                if (!digitalLock.IsLocked())
                {
                    _lock = digitalLock.ReadAll();
                }
            }

            return(_lock);
        }
Ejemplo n.º 2
0
 public int GetNumberOfDigits(IDigitalLock digitalLock)
 {
     try
     {
         char firstValue     = digitalLock.Read(0);
         int  numberOfDigits = 0;
         bool isDifferent    = true;
         do
         {
             numberOfDigits++;
             digitalLock.Turn(TurnDirection.Forward, 0, 1);
             if (firstValue == digitalLock.Read(0))
             {
                 isDifferent = false;
             }
         } while (isDifferent);
         digitalLock.Reset();
         return(numberOfDigits);
     }
     catch (Exception e)
     {
         FileLogger.Log(e.Message + " -- Basamak sayısı bulunma sırasında hata oluştu.");
         throw;
     }
 }
Ejemplo n.º 3
0
        public string Unlock(IDigitalLock digitalLock)
        {
            try
            {
                int cipherLength   = digitalLock.GetCipherLength();
                int numberOfDigits = GetNumberOfDigits(digitalLock);

                int [] a = new int[cipherLength];
                for (int i = 0; i < cipherLength; i++)
                {
                    a[i] = 0;
                }
                do
                {
                    for (int j = 0; j < numberOfDigits; j++)
                    {
                        digitalLock.Lock(true);
                        if (!digitalLock.IsLocked())
                        {
                            return(digitalLock.ReadAll());
                        }
                        digitalLock.Turn(TurnDirection.Forward, 0, 1);
                        a[0]++;
                    }
                    for (int i = 0; i < (cipherLength - 1); i++)
                    {
                        if (a[i] == numberOfDigits)
                        {
                            a[i] = 0;
                            a[i + 1]++;
                            digitalLock.Turn(TurnDirection.Forward, i + 1, 1);
                        }
                    }
                    if (a[cipherLength - 1] == numberOfDigits)
                    {
                        break;
                    }
                } while (true);

                return("Şifre çözülemedi.");
            }
            catch (Exception e)
            {
                FileLogger.Log(e.Message + " -- şifre çözme sırasında hata oluştu.");
                throw;
            }
        }
Ejemplo n.º 4
0
 public void TryAllCombinations(IDigitalLock digitalLock, string pwd, int position, int size)
 {
     if (position < size)
     {
         for (int i = 0; i < digitalLock.GetCipherLength(); i++)
         {
             digitalLock.Turn(TurnDirection.Forward, position, 1);
             if (!digitalLock.IsLocked())
             {
                 break;
             }
             else
             {
                 Console.WriteLine(digitalLock.ReadAll());
                 TryAllCombinations(digitalLock, pwd + i, position + 1, size);
             }
         }
     }
 }