implemented inputFlags & outputFlags
This commit is contained in:
parent
60356033fa
commit
a11415b949
@ -1,6 +1,8 @@
|
||||
#ifndef WHY2_DECRYPTER_H
|
||||
#define WHY2_DECRYPTER_H
|
||||
|
||||
char *decryptText(char *text, char *key); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED
|
||||
#include <why2/flags.h>
|
||||
|
||||
outputFlags decryptText(char *text, char *key, inputFlags flags); //TEXT from WILL BE DECRYPTED WITH KEY AND RETURNED
|
||||
|
||||
#endif
|
@ -1,6 +1,8 @@
|
||||
#ifndef WHY2_ENCRYPTER_H
|
||||
#define WHY2_ENCRYPTER_H
|
||||
|
||||
char *encryptText(char *text, char *keyNew); //TEXT from WILL BE ENCRYPTED WITH RANDOM PASSWORD [KEY] (WHICH WILL BE PRINTED OUT) AND RETURNED
|
||||
#include <why2/flags.h>
|
||||
|
||||
outputFlags encryptText(char *text, char *keyNew, inputFlags flags); //TEXT from WILL BE ENCRYPTED WITH RANDOM PASSWORD [KEY] (WHICH WILL BE PRINTED OUT) AND RETURNED
|
||||
|
||||
#endif
|
@ -23,17 +23,17 @@
|
||||
|
||||
#define DEPRECATED __attribute__((deprecated))
|
||||
|
||||
typedef struct inputFlag
|
||||
typedef struct input
|
||||
{
|
||||
int skipCheck;
|
||||
int noOutput;
|
||||
} inputFlags;
|
||||
|
||||
typedef struct outputFlag
|
||||
typedef struct output
|
||||
{
|
||||
char *outputText;
|
||||
char *usedKey;
|
||||
} *outputFlags;
|
||||
} outputFlags;
|
||||
|
||||
//VARIABLES
|
||||
static int keyLength = 50; //LENGTH OF KEY > DO NOT TOUCH THIS <
|
||||
|
@ -6,10 +6,13 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
setNoOutput(1);
|
||||
setSkipCheck(1);
|
||||
inputFlags flags =
|
||||
{
|
||||
1, //SKIP CHECK
|
||||
1 //NO OUTPUT
|
||||
};
|
||||
|
||||
char *encryptedText = encryptText(TEXT_TO_ENCRYPT, NULL);
|
||||
outputFlags encryptedText = encryptText(TEXT_TO_ENCRYPT, NULL, flags);
|
||||
|
||||
printf
|
||||
(
|
||||
@ -21,9 +24,8 @@ int main(void)
|
||||
"If you'd like to know more about WHY2 Encryption System, please visit: https://github.com/ENGO150/WHY2/wiki \n"
|
||||
"Thank you so much for supporting this project!\n"
|
||||
|
||||
, TEXT_TO_ENCRYPT, encryptedText
|
||||
, TEXT_TO_ENCRYPT, encryptedText.outputText
|
||||
);
|
||||
|
||||
free(encryptedText);
|
||||
return 0;
|
||||
}
|
@ -7,8 +7,7 @@
|
||||
#include <why2/flags.h>
|
||||
#include <why2/misc.h>
|
||||
|
||||
char*
|
||||
decryptText(char *text, char *key)
|
||||
outputFlags decryptText(char *text, char *key, inputFlags flags)
|
||||
{
|
||||
//CHECK FOR INVALID key
|
||||
if (strlen(key) < getKeyLength())
|
||||
@ -83,8 +82,15 @@ decryptText(char *text, char *key)
|
||||
returningText[i] = (char) textKeyChain[i];
|
||||
}
|
||||
|
||||
//LOAD output
|
||||
outputFlags output =
|
||||
{
|
||||
returningText, //DECRYPTED TEXT
|
||||
key //USED KEY
|
||||
};
|
||||
|
||||
//DEALLOCATION
|
||||
free(textKeyChain);
|
||||
|
||||
return returningText;
|
||||
return output;
|
||||
}
|
||||
|
@ -9,8 +9,7 @@
|
||||
#include <why2/flags.h>
|
||||
#include <why2/misc.h>
|
||||
|
||||
char*
|
||||
encryptText(char *text, char *keyNew)
|
||||
outputFlags encryptText(char *text, char *keyNew, inputFlags flags)
|
||||
{
|
||||
//CHECK FOR ACTIVE VERSION
|
||||
checkVersion();
|
||||
@ -58,8 +57,6 @@ encryptText(char *text, char *keyNew)
|
||||
key[i] = (char) numberBuffer;
|
||||
}
|
||||
|
||||
if (!getNoOutput()) printf("Your key is: %s\n!!! SAVE IT SOMEWHERE !!!\n\n", key);
|
||||
|
||||
skipKey:
|
||||
|
||||
//LOAD textKeyChain
|
||||
@ -98,8 +95,15 @@ encryptText(char *text, char *keyNew)
|
||||
free(textBuffer);
|
||||
}
|
||||
|
||||
//LOAD output
|
||||
outputFlags output =
|
||||
{
|
||||
returningText, //ENCRYPTED TEXT
|
||||
key //GENERATED/USED KEY
|
||||
};
|
||||
|
||||
//DEALLOCATION
|
||||
free(key);
|
||||
|
||||
return returningText;
|
||||
return output;
|
||||
}
|
||||
|
@ -6,18 +6,18 @@
|
||||
#include <why2/decrypter.h>
|
||||
#include <why2/flags.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
int main(void)
|
||||
{
|
||||
if (argc == 2 && strcmp(argv[1], "skipCheck") == 0)
|
||||
inputFlags flags =
|
||||
{
|
||||
setSkipCheck(1);
|
||||
}
|
||||
1, //SKIP CHECK
|
||||
0, //NO OUTPUT
|
||||
};
|
||||
|
||||
char *text = encryptText(TEST_TEXT, TEST_KEY);
|
||||
text = decryptText(text, TEST_KEY);
|
||||
outputFlags encrypted = encryptText(TEST_TEXT, TEST_KEY, flags);
|
||||
encrypted = decryptText(encrypted.outputText, TEST_KEY, flags);
|
||||
|
||||
if (strcmp(text, TEST_TEXT) == 0)
|
||||
if (strcmp(encrypted.outputText, TEST_TEXT) == 0)
|
||||
{
|
||||
printf("Test successful!\n");
|
||||
}
|
||||
@ -27,6 +27,5 @@ main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
free(text);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user