diff --git a/01-Substitution/01-simple-caesar/EmenikeAndPaul/.gitignore b/01-Substitution/01-simple-caesar/EmenikeAndPaul/.gitignore new file mode 100644 index 0000000..67acbf4 --- /dev/null +++ b/01-Substitution/01-simple-caesar/EmenikeAndPaul/.gitignore @@ -0,0 +1,253 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +project.fragment.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml diff --git a/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar.sln b/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar.sln new file mode 100644 index 0000000..aa94663 --- /dev/null +++ b/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar.sln @@ -0,0 +1,17 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Simple-Caesar", "Simple-Caesar\Simple-Caesar.csproj", "{4435FD7D-921F-4955-95AC-392A0AEEE7CE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4435FD7D-921F-4955-95AC-392A0AEEE7CE}.Debug|x86.ActiveCfg = Debug|x86 + {4435FD7D-921F-4955-95AC-392A0AEEE7CE}.Debug|x86.Build.0 = Debug|x86 + {4435FD7D-921F-4955-95AC-392A0AEEE7CE}.Release|x86.ActiveCfg = Release|x86 + {4435FD7D-921F-4955-95AC-392A0AEEE7CE}.Release|x86.Build.0 = Release|x86 + EndGlobalSection +EndGlobal diff --git a/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar/Program.cs b/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar/Program.cs new file mode 100644 index 0000000..6ab5e6b --- /dev/null +++ b/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar/Program.cs @@ -0,0 +1,61 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; + +namespace SimpleCaesar +{ + class MainClass + { + static Regex rx = new Regex("[a-z]"); + + public static void Main(string[] args) + { + IEnumerable text = File.ReadAllText("cipher.txt") + .ToLower() + .Where(c => rx.IsMatch(c.ToString())); + + var countDictionary = new Dictionary(); + + foreach (char item in text) { + if (countDictionary.ContainsKey(item)) + countDictionary[item]++; + else + countDictionary[item] = 1; + } + + foreach (KeyValuePair kvp in countDictionary) { + Console.WriteLine("{0} ({1}): {2}", kvp.Key, (int)kvp.Key, kvp.Value); + } + + // find the most common letter + KeyValuePair mostCommon = new KeyValuePair('?',0); + foreach (KeyValuePair current in countDictionary) { + if (current.Value > mostCommon.Value) + mostCommon = current; + } + + Console.WriteLine("Most common was {0} with {1}", mostCommon.Key, mostCommon.Value); + + // work out the shift + int shift = mostCommon.Key - 101; + Console.WriteLine("The shift was: {0}", shift); + + // reverse the encryption + var result = File.ReadAllText("cipher.txt").Select(c => decrypt(c, shift)).ToArray(); + + Console.WriteLine(new String(result)); + } + + private static char decrypt(char c, int shift) { + if (rx.IsMatch(c.ToString())) { + var result = (char)(c - shift); + if (result < 97) + result = (char)(result + 26); + return result; + } else + return c; + } + } +} diff --git a/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar/Properties/AssemblyInfo.cs b/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b048367 --- /dev/null +++ b/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("Simple-Caesar")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("pav")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar/Simple-Caesar.csproj b/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar/Simple-Caesar.csproj new file mode 100644 index 0000000..3e74513 --- /dev/null +++ b/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar/Simple-Caesar.csproj @@ -0,0 +1,45 @@ + + + + Debug + x86 + {4435FD7D-921F-4955-95AC-392A0AEEE7CE} + Exe + SimpleCaesar + Simple-Caesar + v4.5 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + x86 + + + full + true + bin\Release + prompt + 4 + true + x86 + + + + + + + + + + + + PreserveNewest + + + \ No newline at end of file diff --git a/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar/cipher.txt b/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar/cipher.txt new file mode 100644 index 0000000..faa7f52 --- /dev/null +++ b/01-Substitution/01-simple-caesar/EmenikeAndPaul/Simple-Caesar/Simple-Caesar/cipher.txt @@ -0,0 +1 @@ +Bs pbhefr, va bar frafr, gur svefg rffragvny sbe n zna'f orvat n tbbq pvgvmra vf uvf cbffrffvba bs gur ubzr iveghrf bs juvpu jr guvax jura jr pnyy n zna ol gur rzcungvp nqwrpgvir bs znayl. Ab zna pna or n tbbq pvgvmra jub vf abg n tbbq uhfonaq naq n tbbq sngure, jub vf abg ubarfg va uvf qrnyvatf jvgu bgure zra naq jbzra, snvgushy gb uvf sevraqf naq srneyrff va gur cerfrapr bs uvf sbrf, jub unf abg tbg n fbhaq urneg, n fbhaq zvaq, naq n fbhaq obql; rknpgyl nf ab nzbhag bs nggragvba gb pvivy qhgvrf jvyy fnir n angvba vs gur qbzrfgvp yvsr vf haqrezvarq, be gurer vf ynpx bs gur ehqr zvyvgnel iveghrf juvpu nybar pna nffher n pbhagel'f cbfvgvba va gur jbeyq. Va n serr erchoyvp gur vqrny pvgvmra zhfg or bar jvyyvat naq noyr gb gnxr nezf sbe gur qrsrafr bs gur synt, rknpgyl nf gur vqrny pvgvmra zhfg or gur sngure bs znal urnygul puvyqera. N enpr zhfg or fgebat naq ivtbebhf; vg zhfg or n enpr bs tbbq svtugref naq tbbq oerrqref, ryfr vgf jvfqbz jvyy pbzr gb anhtug naq vgf iveghr or varssrpgvir; naq ab fjrrgarff naq qryvpnpl, ab ybir sbe naq nccerpvngvba bs ornhgl va neg be yvgrengher, ab pncnpvgl sbe ohvyqvat hc zngrevny cebfcrevgl pna cbffvoyl ngbar sbe gur ynpx bs gur terng ivevyr iveghrf.