...
 
Commits (2)
......@@ -3,12 +3,15 @@ CFLAGS = -march=native -Wall -Wpedantic -lcrypto
SOURCE = onetimebluh
TARGET = otbluh
PREFIX = /usr
LIBRARY = libluh
all: $(SOURCE)
$(SOURCE): src/$(SOURCE).c
mkdir build
$(CC) $(CFLAGS) -o build/$(TARGET) src/$(SOURCE).c -v
$(CC) $(CFLAGS) -c -o build/$(LIBRARY).o src/$(LIBRARY).c -v
$(CC) $(CFLAGS) -c -o build/$(SOURCE).o src/$(SOURCE).c -v
$(CC) $(CFLAGS) -o build/$(TARGET) build/$(SOURCE).o build/$(LIBRARY).o -v
install:
mkdir -p $(DESTDIR)$(PREFIX)/bin
......
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "libluh.h"
char* readInput (FILE* inputFile, uint64_t allocSize) {
int64_t character;
uint64_t length = 0;
char* input;
input = malloc (sizeof (char) * allocSize);
while (EOF != (character = fgetc (inputFile))) {
input[length++] = character;
if (length == allocSize) {
input = realloc (input, sizeof (char) * (allocSize += 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;
}
#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* inputFile, uint64_t allocSize);
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
......@@ -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;
......