From 26ce345656e7bcee6e938f8546462d4f98f28cb7 Mon Sep 17 00:00:00 2001 From: Anmol Jain <59761332+NotAnmol@users.noreply.github.com> Date: Tue, 20 Oct 2020 14:33:04 +0530 Subject: [PATCH 1/2] Added Better Usage of Functions --- XOR Cipher/XOR_Cipher.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/XOR Cipher/XOR_Cipher.cpp b/XOR Cipher/XOR_Cipher.cpp index b5ee272..9ac4477 100644 --- a/XOR Cipher/XOR_Cipher.cpp +++ b/XOR Cipher/XOR_Cipher.cpp @@ -1,15 +1,23 @@ #include #include -std::string encryptXOR(const std::string& inputString, const std::string& key) { +std::string XORCipher(const std::string& inputString, const std::string& key) { int keySize = key.size(); - std::string encryptedString = inputString; - int size = inputString.size(); - for (int i = 0; i < size; i++) { - encryptedString[i] = char(int(inputString[i]) ^ int(key[i%keySize])); + int inputSize = inputString.size(); + std::string xorString = inputString; + for (int i = 0; i < inputSize; i++) { + xorString[i] = char(int(inputString[i]) ^ int(key[i%keySize])); } - return encryptedString; + return xorString; +} + +std::string encryptXOR(const std::string& inputString, const std::string& key) { + return XORCipher(inputString, key); +} + +std::string decryptXOR(const std::string& inputString, const std::string& key) { + return XORCipher(inputString, key); } int main() { @@ -21,7 +29,7 @@ int main() { std::getline(std::cin, key); encryptedString = encryptXOR(inputString, key); - std::cout << std::endl << encryptedString << std::endl; //Encryption using key - std::cout << encryptXOR(encryptedString, key) << std::endl; //Decryption using same key and function + std::cout << encryptedString << std::endl; //Encryption using key + std::cout << decryptXOR(encryptedString, key) << std::endl; //Decryption using same key and function return 0; -} \ No newline at end of file +} From e5304c901b54b2c76f792d68136b873098c29ff4 Mon Sep 17 00:00:00 2001 From: Anmol Jain <59761332+NotAnmol@users.noreply.github.com> Date: Tue, 20 Oct 2020 14:33:12 +0530 Subject: [PATCH 2/2] Added Better Usage of Functions