Commit 14a690d8 authored by Seppia's avatar Seppia

bin dump and reverse functions

The bluh and unbluh operations have been moved to functions that
take input from string, and corrispondent code has been changed
accordingly.
parent babf2ff2
......@@ -21,6 +21,8 @@ typedef struct opts {
char* readInput (FILE* input, uint64_t size);
char* cryptXor (char* inputStr, FILE* keyFile);
char* fcryptXor (FILE* inputFile, FILE* keyFile);
char* binDump (char* inputStr, char* binChars);
char* ubinDump (char* inputStr, char* binChars);
void xor (Opts* opzioni); /* operates the bitwise XOR between mess and keyf and puts the output to outp */
void keyrand (Opts* opzioni); /* generates random numbers using RAND_bytes from openssl and puts them into outp */
void bluh (Opts* opzioni); /* performs the binary dump of the input file and prints that to outp */
......@@ -389,10 +391,43 @@ void keyrand (Opts* opzioni) {
return;
}
void bluh (Opts* opzioni) {
char* binDump (char* inputStr, char* binChars) {
int64_t len = strlen (inputStr);
char* bits = malloc (8 * len);
int64_t i,j;
for (i = 0; i < len; i ++) {
for (j = 0; j < 8; j ++) {
bits[8 * i + j] = (inputStr[i] & (1 << (7 -j))) ? binChars[1] : binChars[0];
}
}
return bits;
}
char a = opzioni->chars[0];
char b = opzioni->chars[1];
char* ubinDump (char* inputStr, char* binChars) {
int64_t len = strlen (inputStr);
char* comp = malloc ((len / 8) + 1);
memset (comp, 0, ((len / 8) + 1));
int64_t i, j;
for (i = 0; i < (len / 8); i ++) {
for (j = 0; j < 8; j ++) {
if (inputStr[8 * i + j] == binChars[1]) {
comp[i] |= 1 << (7 - j);
}
}
}
return comp;
}
void bluh (Opts* opzioni) {
char* input;
FILE* bluh;
......@@ -431,15 +466,7 @@ void bluh (Opts* opzioni) {
bytes = input;
}
char* bits = malloc (8 * len);
int64_t i,j;
for (i = 0; i < len; i ++) {
for (j = 0; j < 8; j ++) {
bits[8 * i + j] = (bytes[i] & (1 << (7 -j))) ? b : a;
}
}
char* bits = binDump (bytes, opzioni->chars);
if (opzioni->output) {
fwrite (bits, sizeof(char), (8 * len), bluh);
......@@ -475,19 +502,7 @@ void bluh (Opts* opzioni) {
bits = input;
}
char* comp = malloc ((len / 8) + 1);
memset (comp, 0, ((len / 8) + 1));
int64_t i, j;
for (i = 0; i < (len / 8); i ++) {
for (j = 0; j < 8; j ++) {
if (bits[8 * i + j] == b) {
comp[i] |= 1 << (7 - j);
}
}
}
char* comp = ubinDump (bits, opzioni->chars);
if (opzioni->output) {
fwrite (comp, sizeof(char), (len / 8), bluh);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment