initial code commit
This commit is contained in:
parent
621c4d8ec6
commit
79dd09da1a
10
caesarcrypt.licenseheader
Normal file
10
caesarcrypt.licenseheader
Normal file
@ -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/.
|
||||
*/
|
25
caesarcrypt.sln
Normal file
25
caesarcrypt.sln
Normal file
@ -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
|
99
caesarcrypt.vcxproj
Normal file
99
caesarcrypt.vcxproj
Normal file
@ -0,0 +1,99 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\caesarcrypt.c" />
|
||||
<ClCompile Include="src\crypt.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="caesarcrypt.licenseheader" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\crypt.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{bfb0cf25-00f6-4352-9057-5349e4b0bdfa}</ProjectGuid>
|
||||
<RootNamespace>caesarcrypt</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)out\$(Configuration)\</OutDir>
|
||||
<IntDir>out\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)out\$(Configuration)\</OutDir>
|
||||
<IntDir>out\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<LanguageStandard_C>stdc17</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
33
caesarcrypt.vcxproj.filters
Normal file
33
caesarcrypt.vcxproj.filters
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\caesarcrypt.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\crypt.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="caesarcrypt.licenseheader" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\crypt.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
60
src/caesarcrypt.c
Normal file
60
src/caesarcrypt.c
Normal file
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
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;
|
||||
}
|
25
src/crypt.c
Normal file
25
src/crypt.c
Normal file
@ -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;
|
||||
}
|
16
src/crypt.h
Normal file
16
src/crypt.h
Normal file
@ -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);
|
Loading…
x
Reference in New Issue
Block a user