Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ringosham committed Dec 6, 2020
1 parent 15a80fc commit 94aa791
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 12 deletions.
5 changes: 5 additions & 0 deletions PasswordDefuser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ VisualStudioVersion = 15.0.28307.1300
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PasswordDefuser", "PasswordDefuser\PasswordDefuser.csproj", "{C785B8D9-B0E3-4B02-9886-C3486C0C8252}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CA304002-3BF8-44FD-B3BC-DCCEB6B25DBA}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
14 changes: 11 additions & 3 deletions PasswordDefuser/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PasswordDefuser"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>

Title="PasswordDefuser" Height="354.661" Width="391.949" ResizeMode="NoResize">
<Grid Height="324" VerticalAlignment="Top">
<TextBox x:Name="FirstBox" HorizontalAlignment="Left" Height="137" Margin="46,43,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="33" AcceptsReturn="True" TextChanged="UpdateSearch"/>
<TextBox x:Name="SecondBox" HorizontalAlignment="Left" Height="137" Margin="176,43,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="33" AcceptsReturn="True" TextChanged="UpdateSearch"/>
<TextBox x:Name="LastBox" HorizontalAlignment="Right" Height="137" Margin="0,43,46,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="33" AcceptsReturn="True" TextChanged="UpdateSearch"/>
<Label Content="First letter" HorizontalAlignment="Left" Margin="30,17,0,0" VerticalAlignment="Top"/>
<Label Content="Second letter" HorizontalAlignment="Left" Margin="152,17,0,0" VerticalAlignment="Top"/>
<Label Content="Last letter" HorizontalAlignment="Left" Margin="280,17,0,0" VerticalAlignment="Top"/>
<Button Content="Reset" HorizontalAlignment="Left" Margin="157,291,0,0" VerticalAlignment="Top" Width="75" Click="onReset"/>
<Label Content="Possible passwords" HorizontalAlignment="Left" Margin="134,185,0,0" VerticalAlignment="Top"/>
<TextBlock x:Name="Result" TextAlignment="Center" HorizontalAlignment="Left" Margin="27,210,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="76" Width="331"/>
</Grid>
</Window>
80 changes: 71 additions & 9 deletions PasswordDefuser/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,86 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PasswordDefuser {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
private static readonly string[] passwords = {
"about", "after", "again", "below", "could", "every", "first", "found", "great",
"house", "large", "learn", "never", "other", "place", "plant", "point", "right", "small", "sound", "spell",
"still", "study", "their", "there", "these",
"thing", "think", "three", "water", "where", "which", "world", "would", "write"
};

public MainWindow() {
InitializeComponent();
}

private void UpdateSearch(object sender, TextChangedEventArgs e) {
string[] first = FirstBox.Text.Split(new[] {Environment.NewLine}, StringSplitOptions.None);
string[] second = SecondBox.Text.Split(new[] {Environment.NewLine}, StringSplitOptions.None);
string[] last = LastBox.Text.Split(new[] {Environment.NewLine}, StringSplitOptions.None);
List<char> firstChars =
(from possibleChar in first where possibleChar.Length == 1 select possibleChar.ToCharArray()[0])
.ToList();

List<char> secondChars = (from possibleChar2 in second
where possibleChar2.Length == 1
select possibleChar2.ToCharArray()[0]).ToList();

List<char> lastChars = (from possibleCharLast in last
where possibleCharLast.Length == 1
select possibleCharLast.ToCharArray()[0]).ToList();

string regex = constructRegex(firstChars, secondChars, lastChars);
List<string> matches = passwords.Where(possiblePw => Regex.IsMatch(possiblePw, regex)).ToList();

Result.Text = "";
StringBuilder resultBuilder = new StringBuilder();
foreach (string match in matches) {
resultBuilder.Append(match);
resultBuilder.Append(", ");
}

string resultText = resultBuilder.ToString();
if (resultText.Length > 0)
Result.Text = resultBuilder.ToString().Substring(0, resultBuilder.Length - 2);
}

private string constructRegex(List<char> first, List<char> second, List<char> last) {
StringBuilder regexBuilder = new StringBuilder();
regexBuilder.Append("^[");
if (first.Count == 0)
regexBuilder.Append("a-z");
else
foreach (char firstChar in first)
regexBuilder.Append(firstChar);
regexBuilder.Append("][");
if (second.Count == 0)
regexBuilder.Append("a-z");
else
foreach (char secondChar in second)
regexBuilder.Append(secondChar);
regexBuilder.Append("][a-z]+[");
if (last.Count == 0)
regexBuilder.Append("a-z");
else
foreach (char lastChar in last)
regexBuilder.Append(lastChar);

regexBuilder.Append("]");
return regexBuilder.ToString();
}

private void onReset(object sender, RoutedEventArgs e) {
FirstBox.Text = "";
SecondBox.Text = "";
LastBox.Text = "";
}
}
}
}
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# PasswordDefuser

A program to crack the passwords in Keep Talking and Nobody Explodes, complete with a GUI frontend.

Enter the letters line by line.

Binary download on relaese tab.

\#DumbStuffIWroteForFun

0 comments on commit 94aa791

Please sign in to comment.