Show decrypted text after decryption if it's readable
This commit is contained in:
@@ -3,8 +3,16 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <algorithm>
|
||||||
#include "velvet_ring.h"
|
#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<unsigned char>;
|
using ByteVec = std::vector<unsigned char>;
|
||||||
|
|
||||||
ByteVec read_file(const std::string path) {
|
ByteVec read_file(const std::string path) {
|
||||||
@@ -106,6 +114,9 @@ int main(int argc, char* argv[]) {
|
|||||||
std::string dec = dec_wky(input, key);
|
std::string dec = dec_wky(input, key);
|
||||||
write_file(out, ByteVec(dec.begin(), dec.end()));
|
write_file(out, ByteVec(dec.begin(), dec.end()));
|
||||||
|
|
||||||
|
if (is_ascii(dec))
|
||||||
|
std::cout << dec;
|
||||||
|
|
||||||
//std::cout << "Decrypted " << out << "\n";
|
//std::cout << "Decrypted " << out << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,6 +145,10 @@ int main(int argc, char* argv[]) {
|
|||||||
std::string dec = dec_p(input, pass);
|
std::string dec = dec_p(input, pass);
|
||||||
write_file(out, ByteVec(dec.begin(), dec.end()));
|
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
|
//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;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const std::exception e) {
|
catch (const std::exception& e) {
|
||||||
std::cerr << "error: " << e.what() << "\n";
|
std::cerr << "error: " << e.what() << "\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user