Skip to content

Added decryptXOR() #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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;
}
}