Add dec and enc functions, encryption!
This commit is contained in:
parent
21a5948394
commit
a6a54ea05d
@ -38,6 +38,10 @@ at this moment!
|
|||||||
* filedata=File '%filename%' is being moved to moo -> %filename% is populated as file.txt
|
* filedata=File '%filename%' is being moved to moo -> %filename% is populated as file.txt
|
||||||
* write "%filename%" "%filedata%" -> writes filedata contents to file.txt as expected.
|
* write "%filename%" "%filedata%" -> writes filedata contents to file.txt as expected.
|
||||||
|
|
||||||
|
* Decoding and encoding strings
|
||||||
|
* enc "Regular string" -> Converts to encrypted string 'Uhjvqds#xuulqj'
|
||||||
|
* dec "Uhjvqds#xuulqj" -> Converts back to 'Regular string'
|
||||||
|
|
||||||
Todo list
|
Todo list
|
||||||
----
|
----
|
||||||
* Add in-script functions
|
* Add in-script functions
|
||||||
|
@ -19,3 +19,6 @@
|
|||||||
#define TOKEN '%'
|
#define TOKEN '%'
|
||||||
#define TOKEN_STR "%"
|
#define TOKEN_STR "%"
|
||||||
#define NULLBYTE '\0'
|
#define NULLBYTE '\0'
|
||||||
|
#define ENCOFFSET 3
|
||||||
|
#define ENCSTEPODD 2
|
||||||
|
#define ENCSTEPEVEN 2
|
||||||
|
@ -9,10 +9,54 @@
|
|||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
char *ss_encrypt(char *string)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int str_len;
|
||||||
|
|
||||||
|
str_len = strlen(string);
|
||||||
|
|
||||||
|
for(i = 0; (i < str_len && string[i] != NULLBYTE); i++)
|
||||||
|
string[i] = string[i] + ENCOFFSET;
|
||||||
|
|
||||||
|
for(i = 0; (i < str_len && string[i] != NULLBYTE); i+=3)
|
||||||
|
string[i] = string[i] - ENCSTEPODD;
|
||||||
|
|
||||||
|
for(i = 0; (i < str_len && string[i] != NULLBYTE); i+=4)
|
||||||
|
string[i] = string[i] + ENCSTEPEVEN;
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ss_decrypt(char *string)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int str_len;
|
||||||
|
|
||||||
|
str_len = strlen(string);
|
||||||
|
|
||||||
|
for(i = 0; (i < str_len && string[i] != NULLBYTE); i++)
|
||||||
|
string[i] = string[i] - ENCOFFSET;
|
||||||
|
|
||||||
|
for(i = 0; (i < str_len && string[i] != NULLBYTE); i+=3)
|
||||||
|
string[i] = string[i] + ENCSTEPODD;
|
||||||
|
|
||||||
|
for(i = 0; (i < str_len && string[i] != NULLBYTE); i+=4)
|
||||||
|
string[i] = string[i] - ENCSTEPEVEN;
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
int process_line(char *line)
|
int process_line(char *line)
|
||||||
{
|
{
|
||||||
char *tok_srch = strtok(line, "=\" ");
|
char *tok_srch = strtok(line, "=\" ");
|
||||||
|
|
||||||
|
/* reuse function */
|
||||||
|
/*else if(strncmp("temp",tok_srch,4) == 0)
|
||||||
|
{
|
||||||
|
tok_srch = strtok(NULL, " ");
|
||||||
|
}*/
|
||||||
|
|
||||||
/* if line starts with a comment, skip */
|
/* if line starts with a comment, skip */
|
||||||
if(strncmp("#",tok_srch,1) == 0)
|
if(strncmp("#",tok_srch,1) == 0)
|
||||||
{
|
{
|
||||||
@ -42,6 +86,34 @@ int process_line(char *line)
|
|||||||
sleep(atoi(tok_srch));
|
sleep(atoi(tok_srch));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ss encrypt function */
|
||||||
|
else if(strncmp("enc",tok_srch,3) == 0)
|
||||||
|
{
|
||||||
|
char *var_conv;
|
||||||
|
tok_srch = strtok(NULL, "\"");
|
||||||
|
var_conv = parse_vars(tok_srch);
|
||||||
|
if(var_conv != NULL)
|
||||||
|
{
|
||||||
|
char *encrp;
|
||||||
|
encrp = ss_encrypt(var_conv);
|
||||||
|
printf("%s\n", encrp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ss decrypt function */
|
||||||
|
else if(strncmp("dec",tok_srch,3) == 0)
|
||||||
|
{
|
||||||
|
char *var_conv;
|
||||||
|
tok_srch = strtok(NULL, "\"");
|
||||||
|
var_conv = parse_vars(tok_srch);
|
||||||
|
if(var_conv != NULL)
|
||||||
|
{
|
||||||
|
char *encrp;
|
||||||
|
encrp = ss_decrypt(var_conv);
|
||||||
|
printf("%s\n", encrp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* system execute function */
|
/* system execute function */
|
||||||
else if(strncmp("exec",tok_srch,4) == 0)
|
else if(strncmp("exec",tok_srch,4) == 0)
|
||||||
{
|
{
|
||||||
|
@ -5,4 +5,6 @@
|
|||||||
View README file supplied with this software for more details
|
View README file supplied with this software for more details
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
char *ss_encrypt(char *string);
|
||||||
|
char *ss_decrypt(char *string);
|
||||||
int process_line(char *line);
|
int process_line(char *line);
|
||||||
|
42
test.ss
42
test.ss
@ -1,18 +1,54 @@
|
|||||||
#!/usr/bin/slidescript
|
#!/usr/bin/slidescript
|
||||||
# This is a comment
|
# This is a comment
|
||||||
|
|
||||||
|
### These are variables in SS
|
||||||
|
# Sets 'ss_filename' to 'file.txt'
|
||||||
ss_filename=file.txt
|
ss_filename=file.txt
|
||||||
ss_file_content=This will be written to %ss_filename% in due course!
|
# Sets 'ss_exec_command' to 'ls -al'
|
||||||
ss_exec_command=ls -al
|
ss_exec_command=uname -a
|
||||||
|
# Sets 'ss_decoded' to 'Encrypt This Data!'
|
||||||
|
ss_decoded=Decrypt This Data!
|
||||||
|
# Sets 'ss_encoded' to 'Ghfs~su#Yilv#Gduf$'
|
||||||
|
ss_encoded=Ghfs~su#Yilv#Gduf$
|
||||||
|
# Sets 'ss_file_content' to 'This will be written to file.txt!'
|
||||||
|
ss_file_content=Encrypted data: %ss_encoded%
|
||||||
|
|
||||||
print "Writing '%ss_file_content%' to '%ss_filename%'"
|
### The main program ###
|
||||||
|
# Prints 'Writing 'This will be written to file.txt!'
|
||||||
|
# to 'file.txt'
|
||||||
|
print "Sleeping before writing '%ss_file_content%' to '%ss_filename%'"
|
||||||
|
|
||||||
|
# Pauses the script parse for x seconds, in this case 1.
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
|
# Writes the content of ss_file_content to ss_filename
|
||||||
write "%ss_filename%" "%ss_file_content%"
|
write "%ss_filename%" "%ss_file_content%"
|
||||||
|
|
||||||
|
print "Data written to %ss_filename%:"
|
||||||
|
# Reads data and prints to screen from ss_filename
|
||||||
read "%ss_filename%"
|
read "%ss_filename%"
|
||||||
|
|
||||||
|
print "Deleting %ss_filename% after 1 second sleep..."
|
||||||
|
# Sleep again for the giggles :P
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
# Deletes file written previously from ss_filename
|
||||||
delete "%ss_filename%"
|
delete "%ss_filename%"
|
||||||
|
|
||||||
|
print "Deleted %ss_filename%, executing '%ss_exec_command%' in 1 second"
|
||||||
|
# Sleep some more
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
# Executes the ss_exec_command variable data, 'ls -al'
|
||||||
exec "%ss_exec_command%"
|
exec "%ss_exec_command%"
|
||||||
|
|
||||||
|
print "Encoding '%ss_decoded%' in 1 second"
|
||||||
|
# More snooze
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
# Encodes 'ss_encode' data
|
||||||
|
enc "%ss_decoded%"
|
||||||
|
|
||||||
|
print "Decoding '%ss_encoded%'"
|
||||||
|
# Decodes 'ss_decode' data
|
||||||
|
dec "%ss_encoded%"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user