diff --git a/main.cpp b/main.cpp index 70b14f6..2591477 100644 --- a/main.cpp +++ b/main.cpp @@ -3,8 +3,16 @@ #include #include #include +#include #include "velvet_ring.h" + +bool is_ascii(const std::string& str) { + return std::all_of(str.begin(), str.end(), [](unsigned char c) { + return std::isprint(c) || c == '\n' || c == '\r' || c == '\t'; + }); +} + using ByteVec = std::vector; ByteVec read_file(const std::string path) { @@ -106,6 +114,9 @@ int main(int argc, char* argv[]) { std::string dec = dec_wky(input, key); write_file(out, ByteVec(dec.begin(), dec.end())); + if (is_ascii(dec)) + std::cout << dec; + //std::cout << "Decrypted " << out << "\n"; } @@ -134,6 +145,10 @@ int main(int argc, char* argv[]) { std::string dec = dec_p(input, pass); write_file(out, ByteVec(dec.begin(), dec.end())); + if (is_ascii(dec)) { + std::cout << dec; + } + //std::cout << "Decrypted " << out << "\n"; // i think this is redundnant now cuz duh it better be there } @@ -142,7 +157,7 @@ int main(int argc, char* argv[]) { return 1; } } - catch (const std::exception e) { + catch (const std::exception& e) { std::cerr << "error: " << e.what() << "\n"; return 1; }