Getting rid of static privates on CryptoWorkbench; camel-casing names; introducing SharedLibraries dependency

This commit is contained in:
DarkFeather 2016-12-15 16:29:07 -06:00
parent d2b8b98f08
commit c653fece93
14 changed files with 15 additions and 81 deletions

View File

@ -29,7 +29,7 @@ namespace AniNIX.Crypto {
} }
/// <summary> /// <summary>
/// We should be able to act on a workspace and command line. Most ciphers will sue the same syntax. Those that don't can override. /// We should be able to act on a workspace and command line. Most ciphers will use the same syntax. Those that don't can override.
/// </summary> /// </summary>
/// <param name=workSpace>The current version of the text being worked on.</param> /// <param name=workSpace>The current version of the text being worked on.</param>
/// <param name=line>The command sequence.</param> /// <param name=line>The command sequence.</param>

View File

@ -3,7 +3,8 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Collections.Generic; using System.Collections.Generic;
using AniNIX.TheRaven; using System.Reflection;
using AniNIX.Shared;
namespace AniNIX.Crypto { namespace AniNIX.Crypto {
public class Workbench { public class Workbench {
@ -12,14 +13,7 @@ namespace AniNIX.Crypto {
public StringBuilder HelpText = new StringBuilder(); public StringBuilder HelpText = new StringBuilder();
public Dictionary<String,Cipher> SwitchCases = new Dictionary<String,Cipher>(); public Dictionary<String,Cipher> SwitchCases = new Dictionary<String,Cipher>();
// The workbench needs to maintain an instance of each ciphersuite for operation. // The workbench needs to maintain an instance of each ciphersuite for operation.
private Substitution _sub; private List<Cipher> _ciphers = new List<Cipher>();
private Analysis _analysis;
private Simple _simple;
private Caesarian _caesar;
private Affine _affine;
private Vigenere _vig;
private ColumnTransposition _col;
private Ubchi _ubchi;
// If this is true, we will prevent prompt and filesystem access. // If this is true, we will prevent prompt and filesystem access.
private bool _isBlind = false; private bool _isBlind = false;
@ -107,15 +101,11 @@ namespace AniNIX.Crypto {
HelpText.Append("exit -- exit and show the result.\n"); HelpText.Append("exit -- exit and show the result.\n");
HelpText.Append("quit -- alias of exit.\n"); HelpText.Append("quit -- alias of exit.\n");
// Initialize the ciphersuites. // Initialize the ciphersuites.
_sub = new Substitution(this); Object[] cipherArgs = { (Object)this };
_analysis = new Analysis(this); foreach (Type cipherType in Assembly.GetAssembly(typeof(Cipher)).GetTypes()
_simple = new Simple(this); .Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(Cipher)))) {
_caesar = new Caesarian(this); _ciphers.Add((Cipher)Activator.CreateInstance(cipherType, cipherArgs));
_affine = new Affine(this); }
_vig = new Vigenere(this);
_col = new ColumnTransposition(this);
_ubchi = new Ubchi(this);
} }
/// <summary> /// <summary>
@ -250,9 +240,9 @@ namespace AniNIX.Crypto {
case "regex": case "regex":
try { try {
if (line.Length == 3) { if (line.Length == 3) {
Console.Write(RavenExecute.Command(String.Format("bash /usr/local/src/CryptoWorkbench/regex-lookup.bash \"{0}\" \"{1}\"",line[1].Replace("\\","\\\\").Replace("$","\\$"),line[2].Replace("\\","\\\\").Replace("$","\\$")))); Console.Write(ExecuteCommand.Run(String.Format("bash /usr/local/src/CryptoWorkbench/regex-lookup.bash \"{0}\" \"{1}\"",line[1].Replace("\\","\\\\").Replace("$","\\$"),line[2].Replace("\\","\\\\").Replace("$","\\$"))));
} else if (line.Length == 2) { } else if (line.Length == 2) {
Console.Write(RavenExecute.Command(String.Format("bash /usr/local/src/CryptoWorkbench/regex-lookup.bash \"{0}\"",line[1].Replace("\\","\\\\").Replace("$","\\$")))); Console.Write(ExecuteCommand.Run(String.Format("bash /usr/local/src/CryptoWorkbench/regex-lookup.bash \"{0}\"",line[1].Replace("\\","\\\\").Replace("$","\\$"))));
} else { } else {
Console.Error.WriteLine("Need at least one search term."); Console.Error.WriteLine("Need at least one search term.");
} }

View File

@ -1,7 +1,9 @@
TMUXSetting != grep -c "cryptoworkbench" /etc/tmux.conf TMUXSetting != grep -c "cryptoworkbench" /etc/tmux.conf
compile: clean /usr/bin/mcs analysis.csharp substitution.csharp caesarian.csharp cryptoworkbench.csharp compile: clean /usr/bin/mcs CryptoWorkbench.csharp
/usr/bin/mcs -out:cryptoworkbench.exe *.csharp 2>&1 | grep -v 'is assigned but its value is never used' if [ ! -d ../SharedLibraries ]; then git -C /usr/local/src clone https://aninix.net/foundation/SharedLibraries; fi
git -c /usr/local/src/SharedLibraries pull
/usr/bin/mcs -out:cryptoworkbench.exe ../SharedLibraries/CSharp/*.csharp *.csharp 2>&1
test: /usr/bin/mono compile test: /usr/bin/mono compile
/usr/bin/mono cryptoworkbench.exe ./sample.txt /usr/bin/mono cryptoworkbench.exe ./sample.txt

View File

View File

@ -1,58 +0,0 @@
using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;
namespace AniNIX.TheRaven {
public static class RavenExecute {
/// <summary>
/// This method allows TheRaven to execute a command on the OS.
/// </summary>
/// <param name=command>The command string to run as the string argument to "bash -c 'command'"</param>
/// <param name=input>The effective replacement for the command's stdin</param
/// <return>The stdout of the command</return>
/// </summary>
public static String Command(String command, String input) {
//Sanitize inputs.
if (command.Contains("\'")) {
throw new Exception("Command strings cannot include \'.");
}
//Create process.
Process proc = new Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = "/bin/bash";
proc.StartInfo.Arguments = String.Format("-c \'{0}\'",command);
proc.StartInfo.UseShellExecute=false;
//Redirect input
proc.StartInfo.RedirectStandardOutput=true;
proc.StartInfo.RedirectStandardInput=true;
//Start process
proc.Start();
//Add input and read output.
proc.StandardInput.Write(input);
proc.StandardInput.Close();
proc.WaitForExit();
if (proc.ExitCode != 0) {
throw new Exception(String.Format("Failed to exit command with return code {0}",proc.ExitCode));
}
String stdoutString = proc.StandardOutput.ReadToEnd();
//Close up and return
proc.Close();
return stdoutString;
}
//Add polymorphism to allow no stdin
public static String Command(String command) {
return Command(command,null);
}
}
}