summaryrefslogtreecommitdiffstats
path: root/src/onetimebluh.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/onetimebluh.c')
-rw-r--r--src/onetimebluh.c117
1 files changed, 1 insertions, 116 deletions
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;