-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
60 changed files
with
29,863 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.23107.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cryptography101", "Cryptography101\Cryptography101.csproj", "{ABE5F6F8-28AD-4985-AF6D-01A6AB4367DA}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{ABE5F6F8-28AD-4985-AF6D-01A6AB4367DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{ABE5F6F8-28AD-4985-AF6D-01A6AB4367DA}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{ABE5F6F8-28AD-4985-AF6D-01A6AB4367DA}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{ABE5F6F8-28AD-4985-AF6D-01A6AB4367DA}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Cryptography101.Algorithms | ||
{ | ||
public static class Caesar | ||
{ | ||
static Regex inputValidation = new Regex("[a-z]+", RegexOptions.Compiled, new TimeSpan(0, 0, 5)); | ||
static Regex inputValidationSpacesAllowed = new Regex("[a-z ]+", RegexOptions.Compiled, new TimeSpan(0, 0, 5)); | ||
|
||
public static string Encrypt(string plainText, int key, bool allowSpace = false) | ||
{ | ||
return Transform(plainText, key, allowSpace); | ||
} | ||
|
||
public static string Decrypt(string cipherText, int key, bool allowSpace = false) | ||
{ | ||
return Transform(cipherText, -key, allowSpace); | ||
} | ||
|
||
private static string Transform(string target, int shift, bool allowSpace = false) | ||
{ | ||
if (Math.Abs(shift) < 1 || Math.Abs(shift) > 25) | ||
{ | ||
throw new ArgumentOutOfRangeException("shift", "Must be greater than 0 and less than 26."); | ||
} | ||
|
||
if (allowSpace == false) | ||
{ | ||
Match targetIsValid = inputValidation.Match(target); | ||
if (!targetIsValid.Success) | ||
{ | ||
throw new ArgumentOutOfRangeException("target", "Must be lower case English letters."); | ||
} | ||
} | ||
else | ||
{ | ||
Match targetIsValid = inputValidationSpacesAllowed.Match(target); | ||
if (!targetIsValid.Success) | ||
{ | ||
throw new ArgumentOutOfRangeException("target", "Must be lower case English letters or spaces."); | ||
} | ||
} | ||
|
||
string transformedText = string.Empty; | ||
|
||
foreach (char character in target) | ||
{ | ||
if (character == ' ') | ||
{ | ||
transformedText += ' '; | ||
continue; | ||
} | ||
|
||
char transformedCharacter = (char)(character + shift); | ||
|
||
// Wrap around. | ||
if (transformedCharacter > 'z') | ||
{ | ||
transformedCharacter = (char)(transformedCharacter - 26); | ||
} | ||
else if (transformedCharacter < 'a') | ||
{ | ||
transformedCharacter = (char)(transformedCharacter + 26); | ||
} | ||
|
||
transformedText += transformedCharacter; | ||
} | ||
|
||
return transformedText; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
using System.Web; | ||
|
||
namespace Cryptography101.Algorithms | ||
{ | ||
public static class Vigenere | ||
{ | ||
static Regex inputValidation = new Regex("[a-z]+", RegexOptions.Compiled, new TimeSpan(0, 0, 5)); | ||
static Regex inputValidationSpacesAllowed = new Regex("[a-z ]+", RegexOptions.Compiled, new TimeSpan(0, 0, 5)); | ||
|
||
static string plain = "abcdefghijklmnopqrstuvwxyz"; | ||
static string[] square = new string[27]; | ||
|
||
static Vigenere() | ||
{ | ||
for (int i = 1; i <= 26; i++) | ||
{ | ||
string rowContent = string.Empty; | ||
char currentCharacter = 'a'; | ||
currentCharacter += (char)i; | ||
if (currentCharacter > 'z') | ||
{ | ||
currentCharacter = 'a'; | ||
} | ||
|
||
for (int j = 0; j < 26; j++) | ||
{ | ||
rowContent += currentCharacter++; | ||
|
||
if (currentCharacter > 'z') | ||
{ | ||
currentCharacter = 'a'; | ||
} | ||
} | ||
square[i] = rowContent; | ||
} | ||
} | ||
|
||
public static string Encrypt(string plainText, string keyWord, bool allowSpace = false) | ||
{ | ||
if (string.IsNullOrWhiteSpace(keyWord)) | ||
{ | ||
throw new ArgumentNullException("key"); | ||
} | ||
|
||
Match keyIsValid = inputValidation.Match(keyWord); | ||
if (!keyIsValid.Success) | ||
{ | ||
throw new ArgumentOutOfRangeException("key", "Must be a series of lowercase letters."); | ||
} | ||
|
||
if (allowSpace == false) | ||
{ | ||
Match targetIsValid = inputValidation.Match(plainText); | ||
if (!targetIsValid.Success) | ||
{ | ||
throw new ArgumentOutOfRangeException("plainText", "Must be lower case English letters."); | ||
} | ||
} | ||
else | ||
{ | ||
Match targetIsValid = inputValidationSpacesAllowed.Match(plainText); | ||
if (!targetIsValid.Success) | ||
{ | ||
throw new ArgumentOutOfRangeException("plainText", "Must be lower case English letters or spaces."); | ||
} | ||
} | ||
|
||
while (keyWord.Length < plainText.Length) | ||
{ | ||
keyWord = keyWord + keyWord; | ||
} | ||
keyWord = keyWord.Substring(0, plainText.Length); | ||
|
||
string cipherText = string.Empty; | ||
|
||
for (int i = 0; i < plainText.Length; i++) | ||
{ | ||
char cipherSelector = keyWord[i]; | ||
string cipherRow = string.Empty; | ||
for (int rowIndex = 1; rowIndex <= 26; rowIndex++) | ||
{ | ||
if (square[rowIndex][0] == cipherSelector) | ||
{ | ||
cipherRow = square[rowIndex]; | ||
break; | ||
} | ||
} | ||
|
||
char characterToEncrypt = plainText[i]; | ||
int cipherOffset = characterToEncrypt - 'a'; | ||
char encryptedCharacter = cipherRow[cipherOffset]; | ||
|
||
cipherText += encryptedCharacter; | ||
} | ||
|
||
return cipherText; | ||
} | ||
|
||
public static string Decrypt(string cipherText, string keyWord, bool allowSpace = false) | ||
{ | ||
if (string.IsNullOrWhiteSpace(keyWord)) | ||
{ | ||
throw new ArgumentNullException("key"); | ||
} | ||
|
||
Match keyIsValid = inputValidation.Match(keyWord); | ||
if (!keyIsValid.Success) | ||
{ | ||
throw new ArgumentOutOfRangeException("key", "Must be a series of lowercase letters."); | ||
} | ||
|
||
if (allowSpace == false) | ||
{ | ||
Match targetIsValid = inputValidation.Match(cipherText); | ||
if (!targetIsValid.Success) | ||
{ | ||
throw new ArgumentOutOfRangeException("target", "Must be lower case English letters."); | ||
} | ||
} | ||
else | ||
{ | ||
Match targetIsValid = inputValidationSpacesAllowed.Match(cipherText); | ||
if (!targetIsValid.Success) | ||
{ | ||
throw new ArgumentOutOfRangeException("target", "Must be lower case English letters or spaces."); | ||
} | ||
} | ||
|
||
while (keyWord.Length < cipherText.Length) | ||
{ | ||
keyWord = keyWord + keyWord; | ||
} | ||
keyWord = keyWord.Substring(0, cipherText.Length); | ||
|
||
string plainText = string.Empty; | ||
|
||
for (int i = 0; i < cipherText.Length; i++) | ||
{ | ||
char cipherSelector = keyWord[i]; | ||
string cipherRow = string.Empty; | ||
for (int rowIndex = 1; rowIndex <= 26; rowIndex++) | ||
{ | ||
if (square[rowIndex][0] == cipherSelector) | ||
{ | ||
cipherRow = square[rowIndex]; | ||
break; | ||
} | ||
} | ||
|
||
char characterToDecrypt = cipherText[i]; | ||
int offset = cipherRow.IndexOf(characterToDecrypt); | ||
char decryptedCharacter = plain[offset]; | ||
|
||
plainText += decryptedCharacter; | ||
} | ||
|
||
return plainText; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Web; | ||
using System.Web.Optimization; | ||
|
||
namespace Cryptography101 | ||
{ | ||
public class BundleConfig | ||
{ | ||
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862 | ||
public static void RegisterBundles(BundleCollection bundles) | ||
{ | ||
bundles.Add(new ScriptBundle("~/bundles/jquery").Include( | ||
"~/Scripts/jquery-{version}.js")); | ||
|
||
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( | ||
"~/Scripts/jquery.validate*")); | ||
|
||
// Use the development version of Modernizr to develop with and learn from. Then, when you're | ||
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need. | ||
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( | ||
"~/Scripts/modernizr-*")); | ||
|
||
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( | ||
"~/Scripts/bootstrap.js", | ||
"~/Scripts/respond.js")); | ||
|
||
bundles.Add(new StyleBundle("~/Content/css").Include( | ||
"~/Content/bootstrap.css", | ||
"~/Content/site.css")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Web; | ||
using System.Web.Mvc; | ||
|
||
namespace Cryptography101 | ||
{ | ||
public class FilterConfig | ||
{ | ||
public static void RegisterGlobalFilters(GlobalFilterCollection filters) | ||
{ | ||
filters.Add(new HandleErrorAttribute()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.Mvc; | ||
using System.Web.Routing; | ||
|
||
namespace Cryptography101 | ||
{ | ||
public class RouteConfig | ||
{ | ||
public static void RegisterRoutes(RouteCollection routes) | ||
{ | ||
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); | ||
|
||
routes.MapRoute( | ||
name: "Default", | ||
url: "{controller}/{action}/{id}", | ||
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
body { | ||
padding-top: 50px; | ||
padding-bottom: 20px; | ||
} | ||
|
||
/* Set padding to keep content from hitting the edges */ | ||
.body-content { | ||
padding-left: 15px; | ||
padding-right: 15px; | ||
} | ||
|
||
/* Override the default bootstrap behavior where horizontal description lists | ||
will truncate terms that are too long to fit in the left column | ||
*/ | ||
.dl-horizontal dt { | ||
white-space: normal; | ||
} | ||
|
||
/* Set width on the form input elements since they're 100% wide by default */ | ||
input, | ||
select, | ||
textarea { | ||
max-width: 280px; | ||
} |
Oops, something went wrong.