added way to use your own key
This commit is contained in:
parent
6bd23c0f50
commit
fdd3d324c5
@ -1,6 +1,6 @@
|
|||||||
#ifndef WHY2_ENCRYPTER_H
|
#ifndef WHY2_ENCRYPTER_H
|
||||||
#define 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
|
#endif
|
@ -8,8 +8,10 @@
|
|||||||
|
|
||||||
#define KEY_LENGTH 50
|
#define KEY_LENGTH 50
|
||||||
|
|
||||||
|
#define INVALID_KEY 1
|
||||||
|
|
||||||
char*
|
char*
|
||||||
encryptText(char *text)
|
encryptText(char *text, char *keyNew)
|
||||||
{
|
{
|
||||||
srand(time(0)); //TRY TO MAKE RANDOM GENERATION REALLY "RANDOM"
|
srand(time(0)); //TRY TO MAKE RANDOM GENERATION REALLY "RANDOM"
|
||||||
|
|
||||||
@ -20,6 +22,19 @@ encryptText(char *text)
|
|||||||
int textKeyChain[strlen(text)];
|
int textKeyChain[strlen(text)];
|
||||||
int numberBuffer;
|
int numberBuffer;
|
||||||
|
|
||||||
|
if (keyNew != NULL)
|
||||||
|
{
|
||||||
|
if (strlen(keyNew) != KEY_LENGTH)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Educba Training");
|
||||||
|
exit(INVALID_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
key = keyNew;
|
||||||
|
|
||||||
|
goto skipKey;
|
||||||
|
}
|
||||||
|
|
||||||
//LOAD KEY
|
//LOAD KEY
|
||||||
for (int i = 0; i < KEY_LENGTH; i++)
|
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);
|
printf("Your key is: %s\n!!! SAVE IT SOMEWHERE !!!\n\n", key);
|
||||||
|
|
||||||
|
skipKey:
|
||||||
|
|
||||||
//LOAD textKeyChain
|
//LOAD textKeyChain
|
||||||
for (int i = 0; i < (sizeof(textKeyChain) / sizeof(int)); i++)
|
for (int i = 0; i < (sizeof(textKeyChain) / sizeof(int)); i++)
|
||||||
{
|
{
|
||||||
|
@ -4,9 +4,11 @@
|
|||||||
#include "../../include/decrypter.h"
|
#include "../../include/decrypter.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int args, char * argv[])
|
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");
|
text = decryptText(text, "someRandomKeyLulw");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user