mirror of
https://github.com/lucaspalomodevelop/autom.git
synced 2026-03-12 23:27:21 +00:00
add encrypt and decrypt basics
This commit is contained in:
parent
1eada80927
commit
b3dc24350f
59
src/main.cpp
59
src/main.cpp
@ -31,7 +31,10 @@ void input(int argc, char *argv[])
|
|||||||
command.addCommandAlias("remove", "r");
|
command.addCommandAlias("remove", "r");
|
||||||
command.addCommand("show", "[script] - Shows a script", showScript);
|
command.addCommand("show", "[script] - Shows a script", showScript);
|
||||||
command.addCommandAlias("show", "s");
|
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.addDefaultCommand(runScript);
|
||||||
command.runCommand(argv[1], argc, argv);
|
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[])
|
void showScript(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <conio.h>
|
||||||
|
|
||||||
#include "inputparser.h"
|
#include "inputparser.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
@ -33,6 +34,13 @@ void editScript(std::string name, std::string dir);
|
|||||||
void removeScript(int argc, char *argv[]);
|
void removeScript(int argc, char *argv[]);
|
||||||
// show a script in the autom directory
|
// show a script in the autom directory
|
||||||
void showScript(int argc, char *argv[]);
|
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
|
// help function for showing help message
|
||||||
void help(int argc, char *argv[]);
|
void help(int argc, char *argv[]);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user