add encrypt and decrypt basics

This commit is contained in:
lucaspalomodevelop 2023-10-18 21:04:07 +02:00
parent 1eada80927
commit b3dc24350f
2 changed files with 66 additions and 1 deletions

View File

@ -31,7 +31,10 @@ void input(int argc, char *argv[])
command.addCommandAlias("remove", "r");
command.addCommand("show", "[script] - Shows a script", showScript);
command.addCommandAlias("show", "s");
command.addCommand("encrypt", "[script] - Encrypts a script", encryptScript);
command.addCommandAlias("encrypt", "enc");
command.addCommand("decrypt", "[script] - Decrypts a script", decryptScript);
command.addCommandAlias("decrypt", "dec");
command.addDefaultCommand(runScript);
command.runCommand(argv[1], argc, argv);
}
@ -107,6 +110,60 @@ void runScript(int argc, char *argv[])
// }
}
// encrypt a script in the autom directory
void encryptScript(int argc, char *argv[])
{
std::string password = "";
std::string password2 = "";
std::string script = home_dir + "/" + argv[1];
std::cout << "encrypting file " << script << std::endl;
std::cout << "Enter password: ";
password = EnterPassword();
std::cout << "Enter password again: ";
password2 = EnterPassword();
if (password != password2)
{
std::cout << "Passwords do not match" << std::endl;
return;
}
if (password == "")
{
std::cout << "Password cannot be empty" << std::endl;
return;
}
if (!std::filesystem::exists(script))
{
std::cout << "Script " << argv[1] << " does not exist" << std::endl;
return;
}
}
// encrypt a script in the autom directory
void decryptScript(int argc, char *argv[])
{
std::cout << "decrypting file " << argv[1] << std::endl;
}
std::string EnterPassword()
{
std::string password = "";
char c;
while (true)
{
c = getch();
if (c == '\n')
break;
password += c;
std::cout << "*";
}
std::cout << std::endl;
return password;
}
void showScript(int argc, char *argv[])
{

View File

@ -8,6 +8,7 @@
#include <sys/stat.h>
#include <filesystem>
#include <fstream>
#include <conio.h>
#include "inputparser.h"
#include "command.h"
@ -33,6 +34,13 @@ void editScript(std::string name, std::string dir);
void removeScript(int argc, char *argv[]);
// show a script in the autom directory
void showScript(int argc, char *argv[]);
// encrypt a script in the autom directory
void encryptScript(int argc, char *argv[]);
// decrypt a script in the autom directory
void decryptScript(int argc, char *argv[]);
std::string EnterPassword();
// help function for showing help message
void help(int argc, char *argv[]);