diff --git a/caesarcrypt.licenseheader b/caesarcrypt.licenseheader new file mode 100644 index 0000000..81fbed0 --- /dev/null +++ b/caesarcrypt.licenseheader @@ -0,0 +1,10 @@ +extensions: .c .h +/* + * Filename: %FileName% + * Authors(s): %UserName% (%UserName%@example.com) + * Description: Short description here + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ diff --git a/caesarcrypt.sln b/caesarcrypt.sln new file mode 100644 index 0000000..4c14ae7 --- /dev/null +++ b/caesarcrypt.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32602.215 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "caesarcrypt", "caesarcrypt.vcxproj", "{BFB0CF25-00F6-4352-9057-5349E4B0BDFA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BFB0CF25-00F6-4352-9057-5349E4B0BDFA}.Debug|x64.ActiveCfg = Debug|x64 + {BFB0CF25-00F6-4352-9057-5349E4B0BDFA}.Debug|x64.Build.0 = Debug|x64 + {BFB0CF25-00F6-4352-9057-5349E4B0BDFA}.Release|x64.ActiveCfg = Release|x64 + {BFB0CF25-00F6-4352-9057-5349E4B0BDFA}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3168F4B4-5B29-4F5A-A29C-77AA5D538D1F} + EndGlobalSection +EndGlobal diff --git a/caesarcrypt.vcxproj b/caesarcrypt.vcxproj new file mode 100644 index 0000000..17290f0 --- /dev/null +++ b/caesarcrypt.vcxproj @@ -0,0 +1,99 @@ + + + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + 16.0 + Win32Proj + {bfb0cf25-00f6-4352-9057-5349e4b0bdfa} + caesarcrypt + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + $(SolutionDir)out\$(Configuration)\ + out\$(Configuration)\ + + + $(SolutionDir)out\$(Configuration)\ + out\$(Configuration)\ + + + + Level4 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + stdc17 + + + Console + true + + + + + Level4 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + stdcpp20 + stdc17 + + + Console + true + true + true + + + + + + \ No newline at end of file diff --git a/caesarcrypt.vcxproj.filters b/caesarcrypt.vcxproj.filters new file mode 100644 index 0000000..c52380a --- /dev/null +++ b/caesarcrypt.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + + + + Header Files + + + \ No newline at end of file diff --git a/src/caesarcrypt.c b/src/caesarcrypt.c new file mode 100644 index 0000000..b2e6c65 --- /dev/null +++ b/src/caesarcrypt.c @@ -0,0 +1,60 @@ +/* + * Filename: caesarcrypt.c + * Authors(s): Roland (r.weirhowell@gmail.com) + * Description: Encrypt and decrypt text using the Caesar Cipher algorithm + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ + +#include "crypt.h" + +#include +#include +#include +#include + + +int main() +{ + fputs( + "1. Encrypt message\n" + "2. Decrypt message\n" + "Pick operation mode: " + ,stdout + ); + char buf[4]; + fgets(buf, 3, stdin); + int choice = strtol(buf, NULL, 10); + + char* msg = calloc(128, sizeof(char)); + + fputs("Enter your message text: ", stdout); + if (msg) fgets(msg, 128, stdin); + + fputs("Enter your key (shift value): ", stdout); + fgets(buf, 4, stdin); + int key = strtol(buf, NULL, 10); + + if (choice == 1) + { + caesar_encrypt(msg, 128, key); + puts("\nYour encrypted message is:"); + for (int i = 0; i < 128 && msg[i]; i++) + { + putchar(msg[i]); + } + } + else if (choice == 2) + { + caesar_decrypt(msg, 128, key); + puts("\nYour decrypted message is:"); + for (int i = 0; i < 128 && msg[i]; i++) + { + putchar(msg[i]); + } + } + + return 0; +} diff --git a/src/crypt.c b/src/crypt.c new file mode 100644 index 0000000..75f9cde --- /dev/null +++ b/src/crypt.c @@ -0,0 +1,25 @@ +/* + * Filename: crypt.c + * Authors(s): Roland (r.weirhowell@gmail.com) + * Description: Perform caesar cipher cryptographic operations + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ + +#include "crypt.h" + + +void caesar_encrypt(char* str, int size, int key) +{ + for (int i = 0; i < size && str[i] != '\n'; i++) + if (str[i] != ' ') str[i] += key % 26; +} + + +void caesar_decrypt(char* str, int size, int key) +{ + for (int i = 0; i < size && str[i] != '\n'; i++) + if (str[i] != ' ') str[i] -= key % 26; +} diff --git a/src/crypt.h b/src/crypt.h new file mode 100644 index 0000000..cfe42dd --- /dev/null +++ b/src/crypt.h @@ -0,0 +1,16 @@ +/* + * Filename: crypt.h + * Authors(s): Roland (r.weirhowell@gmail.com) + * Description: Header file for crypt.c + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. +*/ + +#pragma once + + +void caesar_encrypt(char* str, int size, int key); + +void caesar_decrypt(char* str, int size, int key);