Created
April 24, 2016 18:02
-
-
Save slice/aae504ca921421bf26d077e07136ed22 to your computer and use it in GitHub Desktop.
TSCDecrypt - Decrypts Cave Story *.tsc files into plain text.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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