Skip to content

Instantly share code, notes, and snippets.

@slice
Created April 24, 2016 18:02
Show Gist options
  • Save slice/aae504ca921421bf26d077e07136ed22 to your computer and use it in GitHub Desktop.
Save slice/aae504ca921421bf26d077e07136ed22 to your computer and use it in GitHub Desktop.
TSCDecrypt - Decrypts Cave Story *.tsc files into plain text.
#include <iostream>
#include <fstream>
#include <sstream>
class TSCDecrypt {
public:
std::string decrypt_file(const std::string& file_name) const {
// Read the file into a string.
std::ifstream file(file_name);
std::stringstream stream;
stream << file.rdbuf();
std::string contents = stream.str();
// Decrypt contents.
return decrypt(contents);
}
std::string decrypt(const std::string& content) const {
// Get key.
const char& key = content[content.size() / 2];
std::string decrypted;
// Decrypt characters.
for (const char& char_ : content)
decrypted += char_ - key;
return decrypted;
}
};
int main(int argc, char* argv[]) {
if (argc == 1) {
std::cerr << "usage: tscdecrypt [file]\n";
return -1;
} else {
// Decrypt the file.
TSCDecrypt decrypter;
std::cout << decrypter.decrypt_file(std::string(argv[1]));
std::cout << std::flush;
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment