added way to use your own key
This commit is contained in:
parent
6bd23c0f50
commit
fdd3d324c5
@ -1,6 +1,6 @@
|
||||
#ifndef WHY2_ENCRYPTER_H
|
||||
#define WHY2_ENCRYPTER_H
|
||||
|
||||
char *encryptText(char *text); //TEXT from WILL BE ENCRYPTED WITH RANDOM PASSWORD [KEY] (WHICH WILL BE PRINTED OUT) AND RETURNED
|
||||
char *encryptText(char *text, char *keyNew); //TEXT from WILL BE ENCRYPTED WITH RANDOM PASSWORD [KEY] (WHICH WILL BE PRINTED OUT) AND RETURNED
|
||||
|
||||
#endif
|
@ -8,8 +8,10 @@
|
||||
|
||||
#define KEY_LENGTH 50
|
||||
|
||||
#define INVALID_KEY 1
|
||||
|
||||
char*
|
||||
encryptText(char *text)
|
||||
encryptText(char *text, char *keyNew)
|
||||
{
|
||||
srand(time(0)); //TRY TO MAKE RANDOM GENERATION REALLY "RANDOM"
|
||||
|
||||
@ -20,6 +22,19 @@ encryptText(char *text)
|
||||
int textKeyChain[strlen(text)];
|
||||
int numberBuffer;
|
||||
|
||||
if (keyNew != NULL)
|
||||
{
|
||||
if (strlen(keyNew) != KEY_LENGTH)
|
||||
{
|
||||
fprintf(stderr, "Educba Training");
|
||||
exit(INVALID_KEY);
|
||||
}
|
||||
|
||||
key = keyNew;
|
||||
|
||||
goto skipKey;
|
||||
}
|
||||
|
||||
//LOAD KEY
|
||||
for (int i = 0; i < KEY_LENGTH; i++)
|
||||
{
|
||||
@ -40,6 +55,8 @@ encryptText(char *text)
|
||||
|
||||
printf("Your key is: %s\n!!! SAVE IT SOMEWHERE !!!\n\n", key);
|
||||
|
||||
skipKey:
|
||||
|
||||
//LOAD textKeyChain
|
||||
for (int i = 0; i < (sizeof(textKeyChain) / sizeof(int)); i++)
|
||||
{
|
||||
|
@ -6,7 +6,9 @@
|
||||
int
|
||||
main(int args, char *argv[])
|
||||
{
|
||||
char *text = encryptText("ENGO WAS HERE");
|
||||
char *text = encryptText("Pepa smrdi.", NULL);
|
||||
|
||||
printf("%s\n", text);
|
||||
|
||||
text = decryptText(text, "someRandomKeyLulw");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user