Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions XOR Cipher/XOR_Cipher.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
#include <iostream>
#include <string>

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() {
Expand All @@ -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;
}
}