diff --git a/GhettoCrypt/Config.h b/GhettoCrypt/Config.h index 5cf1f74..8ac8945 100644 --- a/GhettoCrypt/Config.h +++ b/GhettoCrypt/Config.h @@ -1,7 +1,8 @@ #pragma once +#include namespace GhettoCipher { - constexpr int BLOCK_SIZE = 512; - constexpr int N_ROUNDS = 64; + constexpr std::size_t BLOCK_SIZE = 512; + constexpr std::size_t N_ROUNDS = 64; } diff --git a/GhettoCrypt/Halfblock.h b/GhettoCrypt/Halfblock.h index f11151b..ed13692 100644 --- a/GhettoCrypt/Halfblock.h +++ b/GhettoCrypt/Halfblock.h @@ -1,9 +1,10 @@ #pragma once #include +#include #include "Config.h" namespace GhettoCipher { - constexpr int HALFBLOCK_SIZE = (BLOCK_SIZE / 2); + constexpr std::size_t HALFBLOCK_SIZE = (BLOCK_SIZE / 2); typedef std::bitset Halfblock; } diff --git a/GhettoCrypt/Util.h b/GhettoCrypt/Util.h index 4b4dbbf..8a528ea 100644 --- a/GhettoCrypt/Util.h +++ b/GhettoCrypt/Util.h @@ -8,27 +8,27 @@ namespace GhettoCipher { //! Mod-operator that works with negative values - inline int Mod(int numerator, int denominator) + inline int Mod(const int numerator, const int denominator) { return (denominator + (numerator % denominator)) % denominator; } //! Will perform a wrapping left-bitshift on a bitset template - inline std::bitset Shiftl(const std::bitset& bits, std::size_t amount) + inline std::bitset Shiftl(const std::bitset& bits, const std::size_t amount) { std::stringstream ss; const std::string bitss = bits.to_string(); for (std::size_t i = 0; i < bitss.size(); i++) - ss << bitss[Mod((i + amount), bitss.size())]; + ss << bitss[Mod((int)(i + amount), (int)bitss.size())]; return std::bitset(ss.str()); } //! Will perform a wrapping right-bitshift on a bitset template - inline std::bitset Shiftr(const std::bitset& bits, std::size_t amount) + inline std::bitset Shiftr(const std::bitset& bits, const std::size_t amount) { std::stringstream ss; const std::string bitss = bits.to_string(); @@ -159,10 +159,10 @@ namespace GhettoCipher std::size_t value; if ((c >= '0') && (c <= '9')) // Is it a number? - value = (c - '0') + 0; + value = ((std::size_t)c - '0') + 0; else if ((c >= 'a') && (c <= 'f')) // Else, it is a lowercase letter - value = (c - 'a') + 10; + value = ((std::size_t)c - 'a') + 10; else throw std::logic_error("non-hex string detected in HexstringToBits()"); @@ -186,10 +186,10 @@ namespace GhettoCipher std::size_t value; if ((c >= '0') && (c <= '9')) // Is it a number? - value = (c - '0') + 0; + value = ((std::size_t)c - '0') + 0; else if ((c >= 'a') && (c <= 'f')) // Else, it is a lowercase letter - value = (c - 'a') + 10; + value = ((std::size_t)c - 'a') + 10; else throw std::logic_error("non-hex string detected in HexstringToBits()"); diff --git a/INCLUDE/GhettoCrypt.h b/INCLUDE/GhettoCrypt.h index fa9eff0..10f759c 100644 --- a/INCLUDE/GhettoCrypt.h +++ b/INCLUDE/GhettoCrypt.h @@ -28,6 +28,11 @@ #pragma once +/*** ./../GhettoCrypt/Version.h ***/ + +#pragma once +#define GHETTOCRYPT_VERSION 0.1 + /*** ./../GhettoCrypt/GhettoCryptWrapper.h ***/ #pragma once @@ -75,19 +80,15 @@ namespace GhettoCipher typedef std::string Flexblock; } -/*** ./../GhettoCrypt/Version.h ***/ - -#pragma once -#define GHETTOCRYPT_VERSION 0.1 - /*** ./../GhettoCrypt/Config.h ***/ #pragma once +#include namespace GhettoCipher { - constexpr int BLOCK_SIZE = 512; - constexpr int N_ROUNDS = 64; + constexpr std::size_t BLOCK_SIZE = 512; + constexpr std::size_t N_ROUNDS = 64; } /*** ./../GhettoCrypt/Block.h ***/ @@ -110,27 +111,27 @@ namespace GhettoCipher namespace GhettoCipher { //! Mod-operator that works with negative values - inline int Mod(int numerator, int denominator) + inline int Mod(const int numerator, const int denominator) { return (denominator + (numerator % denominator)) % denominator; } //! Will perform a wrapping left-bitshift on a bitset template - inline std::bitset Shiftl(const std::bitset& bits, std::size_t amount) + inline std::bitset Shiftl(const std::bitset& bits, const std::size_t amount) { std::stringstream ss; const std::string bitss = bits.to_string(); for (std::size_t i = 0; i < bitss.size(); i++) - ss << bitss[Mod((i + amount), bitss.size())]; + ss << bitss[Mod((int)(i + amount), (int)bitss.size())]; return std::bitset(ss.str()); } //! Will perform a wrapping right-bitshift on a bitset template - inline std::bitset Shiftr(const std::bitset& bits, std::size_t amount) + inline std::bitset Shiftr(const std::bitset& bits, const std::size_t amount) { std::stringstream ss; const std::string bitss = bits.to_string(); @@ -261,10 +262,10 @@ namespace GhettoCipher std::size_t value; if ((c >= '0') && (c <= '9')) // Is it a number? - value = (c - '0') + 0; + value = ((std::size_t)c - '0') + 0; else if ((c >= 'a') && (c <= 'f')) // Else, it is a lowercase letter - value = (c - 'a') + 10; + value = ((std::size_t)c - 'a') + 10; else throw std::logic_error("non-hex string detected in HexstringToBits()"); @@ -288,10 +289,10 @@ namespace GhettoCipher std::size_t value; if ((c >= '0') && (c <= '9')) // Is it a number? - value = (c - '0') + 0; + value = ((std::size_t)c - '0') + 0; else if ((c >= 'a') && (c <= 'f')) // Else, it is a lowercase letter - value = (c - 'a') + 10; + value = ((std::size_t)c - 'a') + 10; else throw std::logic_error("non-hex string detected in HexstringToBits()"); @@ -361,17 +362,6 @@ namespace GhettoCipher } } -/*** ./../GhettoCrypt/Halfblock.h ***/ - -#pragma once -#include - -namespace GhettoCipher -{ - constexpr int HALFBLOCK_SIZE = (BLOCK_SIZE / 2); - typedef std::bitset Halfblock; -} - /*** ./../GhettoCrypt/Keyset.h ***/ #pragma once @@ -382,6 +372,18 @@ namespace GhettoCipher typedef std::array Keyset; } +/*** ./../GhettoCrypt/Halfblock.h ***/ + +#pragma once +#include +#include + +namespace GhettoCipher +{ + constexpr std::size_t HALFBLOCK_SIZE = (BLOCK_SIZE / 2); + typedef std::bitset Halfblock; +} + /*** ./../GhettoCrypt/Feistel.h ***/ #pragma once