implemented generateTextKeyChain
This commit is contained in:
parent
0a2066e55c
commit
4f50c2b4bb
@ -5,6 +5,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "../include/flags.h"
|
#include "../include/flags.h"
|
||||||
|
#include "../include/misc.h"
|
||||||
|
|
||||||
char*
|
char*
|
||||||
decryptText(char *text, char *key)
|
decryptText(char *text, char *key)
|
||||||
@ -22,10 +23,9 @@ decryptText(char *text, char *key)
|
|||||||
|
|
||||||
//VARIABLES
|
//VARIABLES
|
||||||
char *returningText;
|
char *returningText;
|
||||||
int numberBuffer;
|
int numberBuffer = 1;
|
||||||
char *textBuffer;
|
char *textBuffer;
|
||||||
|
int textKeyChainLength;
|
||||||
numberBuffer = 1;
|
|
||||||
|
|
||||||
//GET LENGTH OF returningText AND textKeyChain
|
//GET LENGTH OF returningText AND textKeyChain
|
||||||
for (int i = 0; i < strlen(text); i++)
|
for (int i = 0; i < strlen(text); i++)
|
||||||
@ -33,34 +33,14 @@ decryptText(char *text, char *key)
|
|||||||
if (text[i] == ENCRYPTION_SEPARATOR) numberBuffer++;
|
if (text[i] == ENCRYPTION_SEPARATOR) numberBuffer++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//SET LENGTH
|
//SET LENGTH (numberBuffer)
|
||||||
returningText = malloc(numberBuffer);
|
returningText = malloc(numberBuffer);
|
||||||
int textKeyChain[numberBuffer];
|
int *textKeyChain = malloc(numberBuffer * sizeof(int));
|
||||||
int encryptedTextKeyChain[numberBuffer];
|
int encryptedTextKeyChain[numberBuffer];
|
||||||
|
textKeyChainLength = numberBuffer;
|
||||||
|
|
||||||
//LOAD textKeyChain
|
//LOAD textKeyChain
|
||||||
for (int i = 0; i < (sizeof(textKeyChain) / sizeof(int)); i++)
|
generateTextKeyChain(key, textKeyChain, numberBuffer);
|
||||||
{
|
|
||||||
numberBuffer = i;
|
|
||||||
|
|
||||||
//CHECK, IF numberBuffer ISN'T GREATER THAN KEY_LENGTH AND CUT UNUSED LENGTH
|
|
||||||
while (numberBuffer >= KEY_LENGTH)
|
|
||||||
{
|
|
||||||
numberBuffer -= KEY_LENGTH;
|
|
||||||
}
|
|
||||||
|
|
||||||
//FILL textKeyChain
|
|
||||||
if ((numberBuffer + 1) % 3 == 0)
|
|
||||||
{
|
|
||||||
textKeyChain[i] = key[numberBuffer] * key[numberBuffer + 1];
|
|
||||||
} else if ((numberBuffer + 1) % 2 == 0)
|
|
||||||
{
|
|
||||||
textKeyChain[i] = key[numberBuffer] - key[numberBuffer + 1];
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
textKeyChain[i] = key[numberBuffer] + key[numberBuffer + 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//LOAD encryptedTextKeyChain
|
//LOAD encryptedTextKeyChain
|
||||||
for (int i = 0; i < (sizeof(encryptedTextKeyChain) / sizeof(int)); i++)
|
for (int i = 0; i < (sizeof(encryptedTextKeyChain) / sizeof(int)); i++)
|
||||||
@ -92,13 +72,13 @@ decryptText(char *text, char *key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//DECRYPT TEXT
|
//DECRYPT TEXT
|
||||||
for (int i = 0; i < (sizeof(textKeyChain) / sizeof(int)); i++)
|
for (int i = 0; i < textKeyChainLength; i++)
|
||||||
{
|
{
|
||||||
textKeyChain[i] -= encryptedTextKeyChain[i];
|
textKeyChain[i] -= encryptedTextKeyChain[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
//LOAD returningText
|
//LOAD returningText
|
||||||
for (int i = 0; i < sizeof(textKeyChain) / sizeof(int); i++)
|
for (int i = 0; i < textKeyChainLength; i++)
|
||||||
{
|
{
|
||||||
returningText[i] = (char) textKeyChain[i];
|
returningText[i] = (char) textKeyChain[i];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user