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); }
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; } }