PasswordCrackerViewModel.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using Caliburn.Micro;
  2. using friaLabbar.Models;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Data;
  10. using System.Windows.Media;
  11. namespace friaLabbar.ViewModels
  12. {
  13. public class PasswordCrackerViewModel
  14. {
  15. private List<string> passwordPool = new List<string>()
  16. {"BELOW", "PLANT", "WHICH", "WORLD", "WATER", "THESE", "THERE", "HOUSE", "WOULD", "WRITE", "ABOUT", "LEARN" };
  17. private PasswordCracker pwCracker;
  18. public BindableCollection<PositionalPasswordCharacter> PossiblePasswords { get; set; }
  19. public BindableCollection<PossiblePassword> AllPasswords { get; set; }
  20. public PasswordCrackerViewModel()
  21. {
  22. pwCracker = new PasswordCracker(passwordPool);
  23. pwCracker.PositionalCharacters[0].Text = "WHLXAS";
  24. pwCracker.PositionalCharacters[1].Text = "ORHEQZT";
  25. pwCracker.PositionalCharacters[4].Text = "EDQZP";
  26. IEnumerable<PossiblePassword> pp = pwCracker.AllPasswords;
  27. PossiblePasswords = new BindableCollection<PositionalPasswordCharacter>(pwCracker.PositionalCharacters);
  28. AllPasswords = new BindableCollection<PossiblePassword>(pwCracker.AllPasswords);
  29. }
  30. }
  31. public class PasswordToColorConverter : IValueConverter
  32. {
  33. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  34. {
  35. if (value is Boolean)
  36. {
  37. if ((Boolean)value)
  38. {
  39. return Brushes.Gray;
  40. }
  41. else
  42. {
  43. return Brushes.Red;
  44. }
  45. }
  46. return Brushes.White;
  47. }
  48. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  49. {
  50. throw new NotImplementedException();
  51. }
  52. }
  53. public class PasswordCharacterToColorConverter : IValueConverter
  54. {
  55. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  56. {
  57. Brush color = Brushes.White;
  58. if (value is CharacterState)
  59. {
  60. switch ((CharacterState)value)
  61. {
  62. case CharacterState.Possible:
  63. color = Brushes.Green;
  64. break;
  65. case CharacterState.Impossible:
  66. color = Brushes.Red;
  67. break;
  68. case CharacterState.Unknown:
  69. color = Brushes.White;
  70. break;
  71. }
  72. }
  73. return color;
  74. }
  75. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  76. {
  77. throw new NotImplementedException();
  78. }
  79. }
  80. }