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 +}