summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSeppia <seppia@seppio.fish>2018-07-05 17:12:29 +0200
committerSeppia <seppia@seppio.fish>2018-07-05 17:12:29 +0200
commit14a690d85cf9e06be1708e515fd029d1666dbd6d (patch)
tree919a8709832b5aa31783727d148e2586e3e1e380 /src
parentbabf2ff29cda90ceadcb2af593f264575dee0faf (diff)
downloadonetimebluh-14a690d85cf9e06be1708e515fd029d1666dbd6d.tar.gz
onetimebluh-14a690d85cf9e06be1708e515fd029d1666dbd6d.tar.bz2
onetimebluh-14a690d85cf9e06be1708e515fd029d1666dbd6d.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/onetimebluh.c65
1 files changed, 40 insertions, 25 deletions
diff --git a/src/onetimebluh.c b/src/onetimebluh.c
index 4cbd99a..960b259 100644
--- a/src/onetimebluh.c
+++ b/src/onetimebluh.c
@@ -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);