Skip to content

Commit

Permalink
Makefile and Basic functionalities
Browse files Browse the repository at this point in the history
  • Loading branch information
terragou committed Sep 3, 2013
0 parents commit 9cf4fec
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
GCC = gcc
CFLAGS = -g -Wall -Wshadow

duckbits: duck.o
$(GCC) $(CFLAGS) duck.o -o duckbits

duck.o: duck.c
$(GCC) $(CFLAGS) -c duck.c

bitwise_op.o: bitwise_op.c
$(GCC) $(CFLAGS) -c bitwise_op.c

sample:
make duckbits
./duckbits
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Duckbits
Duckbits flips bit according to the sequence calculated by the encryption key user entered.
45 changes: 45 additions & 0 deletions bitwise_op.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <stdio.h>
#include <stdlib.h>
#include "bitwise_op.h"

int getBitFromByte(int maskposition, unsigned char byte){
unsigned char mask = 0x80;
switch(maskposition){
case 1:
mask = 0x80;
break;
case 2:
mask = 0x40;
break;
case 3:
mask = 0x20;
break;
case 4:
mask = 0x10;
break;
case 5:
mask = 0x08;
break;
case 6:
mask = 0x04;
break;
case 7:
mask = 0x02;
break;
case 8:
mask = 0x01;
break;
}

return ((byte & mask) != 0);
}

unsigned char FillBit(unsigned char Bucket, int bitToFill, int offset){
//Position: LSB ...MSB 7..0
int absoffset = (offset - 8);
if(absoffset < 0) absoffset *= -1;
Bucket |= (bitToFill << absoffset);
return Bucket;
}


6 changes: 6 additions & 0 deletions bitwise_op.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef BITWISEOP_H

int getBitFromByte(int maskposition, unsigned char byte);
unsigned char FillBit(unsigned char Bucket, int bitToFill, int offset);

#endif
Binary file added bitwise_op.o
Binary file not shown.
72 changes: 72 additions & 0 deletions duck.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include <stdio.h>
#include "bitwise_op.c"
#include <stdio.h>
#include <string.h>

FILE * OpenFile(char FileName[], char mode[]);
void Duckfile(FILE * fptr_in, FILE * fptr_out);

FILE * OpenFile(char FileName[], char mode[]){
FILE *myfile = NULL;
myfile = fopen(FileName,mode);

return myfile;
}

int main(int argc, const char * argv[])
{

// scanf("%d");

FILE * fptr_in = OpenFile("Breaking.Bad.S05E12.720p.HDTV.x264-EVOLVE.mkv", "rb");
FILE * fptr_out = OpenFile("Breaking.Bad.S05E12.720p.HDTV.x264-EVOLVE.ducked", "wb");

Duckfile(fptr_in,fptr_out);

return 0;
}

void Duckfile(FILE * fptr_in, FILE * fptr_out){
char duck_key[64];
printf("Duckbits TWO-WAY ducking algorithm uses a 64 bytes key to secure your file using the low level DUCKMAN algorithm. Please enter the Ducking-Key (DK) you wish to use for this ducking: ");
scanf("%s",duck_key);

int bytecount = 0;
unsigned int block;
unsigned char byte_ducked;

while(block != EOF){
// byte_buffer = 0x00;
byte_ducked = 0x00;

block = fgetc(fptr_in);
if(block == EOF){
break;
}

int i = 0;
for(i = 1; i <= 8; i++){
bytecount += 1;
int writebit = getBitFromByte(i, block);
// byte_buffer = FillBit(byte_buffer, writebit, i);
int DUCKTHIS = i % 2;

if(DUCKTHIS){
//If the Ducking-Key tells you to duck this bit, do it
byte_ducked = FillBit(byte_ducked, (writebit == 0 ? 1 : 0), i);
}else{
//Leave intact otherwise
byte_ducked = FillBit(byte_ducked, writebit, i);
}

}
// printf("\nOriginal: %d (%c)\n",byte_buffer,byte_buffer);
// printf("Ducked: %d (%c)\n",byte_ducked,byte_ducked);

fputc(byte_ducked,fptr_out);
}

printf("\n");

printf("%d Bytes Can Fly!\n", bytecount);
}
Binary file added duck.o
Binary file not shown.
Binary file added duckbits
Binary file not shown.
1 change: 1 addition & 0 deletions file.ducked
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
���ߋ����ߑ�����ߐ�ߚ�������ߌ�����������߈������ߖ�ߍ�����������ߋ���ߑ�����ߛ������ߙ���ߋ��ߜ����ߏ���������ߞ߈������ߚ����ߏ��������ߋ��ߙ�������ߙ���ߜ����������߶�ߋ���ߜ����ߋ��ߚ����ߖ���������י������߈���ߝ�ߌ��ߙ��ߋ��ߌ���������ߚ�����ߌ���ߐ�ߜ����ߖ�߅����ߋ��ߙ�������ߍ������߅���ߞ��ߋ��ߚ����ߖ��������ߍ������ߊ����������������ߖ�ߞ�ߊ�������ߖ�������ߋ�����
4 changes: 4 additions & 0 deletions file.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The total number of elements successfully written is returned.
If this number differs from the count parameter, a writing error prevented the function from completing. In this case, the error indicator (ferror) will be set for the stream.
If either size or count is zero, the function returns zero and the error indicator remains unchanged.
size_t is an unsigned integral type.

0 comments on commit 9cf4fec

Please sign in to comment.