summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSeppia <seppia@seppio.fish>2018-07-06 01:27:52 +0200
committerSeppia <seppia@seppio.fish>2018-07-06 01:27:52 +0200
commit6d532fd3993f2c86a39071636bf330135541f80f (patch)
treee30cbb077a8505d5359b0c6a8d3dcc57a9f90913 /src
parentbf07e0d2f69d7e801515ae33393f91a7867604b4 (diff)
downloadonetimebluh-6d532fd3993f2c86a39071636bf330135541f80f.tar.gz
onetimebluh-6d532fd3993f2c86a39071636bf330135541f80f.tar.bz2
onetimebluh-6d532fd3993f2c86a39071636bf330135541f80f.zip
Moved new functions to separate header and source
Moved new core functions to separate source file and created new header file. Adjusted Makefile and onetimebluh.c accordingly.
Diffstat (limited to 'src')
-rw-r--r--src/libluh.c105
-rw-r--r--src/libluh.h21
-rw-r--r--src/onetimebluh.c117
3 files changed, 127 insertions, 116 deletions
diff --git a/src/libluh.c b/src/libluh.c
new file mode 100644
index 0000000..b7412b4
--- /dev/null
+++ b/src/libluh.c
@@ -0,0 +1,105 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include "libluh.h"
+
+char* readInput (FILE* stdinput, uint64_t size) {
+
+ int64_t character;
+ uint64_t length = 0;
+ char* input;
+
+ input = malloc (sizeof (char) * size);
+
+ while (EOF != (character = fgetc (stdinput))) {
+ input[length++] = character;
+ if (length == size) {
+ input = realloc (input, sizeof (char) * (size += 8));
+ }
+ }
+
+ input[length++] = '\0';
+
+ return realloc (input, sizeof (char) * length);
+}
+
+char* cryptXor (char* inputStr, FILE* keyFile) {
+
+ int64_t i;
+ char in1, in2;
+ int64_t inputSize = strlen (inputStr);
+ char* bytes = malloc (inputSize);
+
+ fseek (keyFile, 0L, SEEK_END);
+ int64_t keySize = ftell (keyFile);
+ fseek (keyFile, (keySize - inputSize), SEEK_SET);
+
+ for (i = 0; i < inputSize; i ++) {
+ in1 = inputStr[i];
+ fscanf (keyFile, "%c", &in2);
+ bytes[i] = in1 ^ in2;
+ }
+
+ return bytes;
+}
+
+char* fcryptXor (FILE* inputFile, FILE* keyFile) {
+
+ int64_t i;
+ char in1, in2;
+
+ fseek (inputFile, 0L, SEEK_END);
+ int64_t inputSize = ftell (inputFile);
+ rewind (inputFile);
+
+ char* bytes = malloc (inputSize);
+
+ fseek (keyFile, 0L, SEEK_END);
+ int64_t keySize = ftell (keyFile);
+ fseek (keyFile, (keySize - inputSize), SEEK_SET);
+
+ for (i = 0; i < inputSize; i ++) {
+ fscanf (inputFile, "%c", &in1);
+ fscanf (keyFile, "%c", &in2);
+ bytes[i] = in1 ^ in2;
+ }
+
+ return bytes;
+}
+
+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* 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;
+}
diff --git a/src/libluh.h b/src/libluh.h
new file mode 100644
index 0000000..2e44c01
--- /dev/null
+++ b/src/libluh.h
@@ -0,0 +1,21 @@
+#ifndef LIBLUH
+#define LIBLUH
+
+typedef struct opts {
+ int64_t comm;
+ int64_t nbytes;
+ int64_t quiet;
+ int64_t tear;
+ char* chars;
+ char* keyfile;
+ char* input;
+ char* output;
+} 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);
+
+#endif
diff --git a/src/onetimebluh.c b/src/onetimebluh.c
index b9cd8ec..fed8476 100644
--- a/src/onetimebluh.c
+++ b/src/onetimebluh.c
@@ -6,23 +6,8 @@
#include <unistd.h>
#include <errno.h>
#include <error.h>
+#include "libluh.h"
-typedef struct opts {
- int64_t comm;
- int64_t nbytes;
- int64_t quiet;
- int64_t tear;
- char* chars;
- char* keyfile;
- char* input;
- char* output;
-} 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);
void keyrand (Opts* opzioni);
void bluh (Opts* opzioni);
@@ -182,70 +167,6 @@ int main (int argc, char* argv[]) {
exit (EXIT_SUCCESS);
}
-char* readInput (FILE* stdinput, uint64_t size) {
-
- int64_t character;
- uint64_t length = 0;
- char* input;
-
- input = malloc (sizeof (char) * size);
-
- while (EOF != (character = fgetc (stdinput))) {
- input[length++] = character;
- if (length == size) {
- input = realloc (input, sizeof (char) * (size += 8));
- }
- }
-
- input[length++] = '\0';
-
- return realloc (input, sizeof (char) * length);
-}
-
-char* cryptXor (char* inputStr, FILE* keyFile) {
-
- int64_t i;
- char in1, in2;
- int64_t inputSize = strlen (inputStr);
- char* bytes = malloc (inputSize);
-
- fseek (keyFile, 0L, SEEK_END);
- int64_t keySize = ftell (keyFile);
- fseek (keyFile, (keySize - inputSize), SEEK_SET);
-
- for (i = 0; i < inputSize; i ++) {
- in1 = inputStr[i];
- fscanf (keyFile, "%c", &in2);
- bytes[i] = in1 ^ in2;
- }
-
- return bytes;
-}
-
-char* fcryptXor (FILE* inputFile, FILE* keyFile) {
-
- int64_t i;
- char in1, in2;
-
- fseek (inputFile, 0L, SEEK_END);
- int64_t inputSize = ftell (inputFile);
- rewind (inputFile);
-
- char* bytes = malloc (inputSize);
-
- fseek (keyFile, 0L, SEEK_END);
- int64_t keySize = ftell (keyFile);
- fseek (keyFile, (keySize - inputSize), SEEK_SET);
-
- for (i = 0; i < inputSize; i ++) {
- fscanf (inputFile, "%c", &in1);
- fscanf (keyFile, "%c", &in2);
- bytes[i] = in1 ^ in2;
- }
-
- return bytes;
-}
-
void xor (Opts* opzioni) {
char* input;
@@ -391,42 +312,6 @@ void keyrand (Opts* opzioni) {
return;
}
-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* 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;