meditationatae

Just another WordPress.com site

The C source code file makebin02a.c

/*************************************************************************************

In the previous post, I explained how one can extract the least significant bit

from the channel 1 16-bit PCM fields of stereo (2-channel) 32-bit per sample

WAVE files, format *.wav, and write them as 1s and 0s at one bit per line

in an output file, which in my case was:

/home/david2/RANDOM/decrypt45.txt

The C source code file below reads 8 bits from

decrypt45.txt , packs an 8 bit byte (the unsigned char ‘byte’ )

with the 8 bits, and writes the unsigned char ‘byte’ to the file:

/home/david2/RANDOM/LSBwave.bin .

When the program has finished, the file

LSBwave.bin contains 1,764,000 bytes from the

14,112,000-line file: /home/david2/RANDOM/decrypt45.txt .

Each line of decrypt45.txt contains a ‘0’ or a ‘1’, at random.

Source code of makebin02a.c :

****************************************************************************/

#include <stdio.h>

int main(void)
{
unsigned char array[256];
unsigned char uc0;
unsigned char uc1;
unsigned char byte;
int j;
int i;
int bits[8];
FILE *in;
FILE *out;

uc0 = (unsigned char) 0;
uc1 = (unsigned char) 1;

in = fopen(“/home/david2/RANDOM/decrypt45.txt”, “r”);
out = fopen(“/home/david2/RANDOM/LSBwave.bin”, “w”);
array[0] = uc0;

for(j=1; j<256; j++)
{
array[j] = array[j-1] + uc1;
}

for(i=0; i<1764000; i++)
{
byte = uc0;

for(j=0; j<8; j++)
{
fscanf(in, “%d”, &bits[j]);
}
if(bits[0] > 0)
{
byte = byte + array[1];
}

if(bits[1] > 0)
{
byte = byte + array[2];
}

if(bits[2] > 0)
{
byte = byte + array[4];
}

if(bits[3] > 0)
{
byte = byte + array[8];
}

if(bits[4] > 0)
{
byte = byte + array[16];
}

if(bits[5] > 0)
{
byte = byte + array[32];
}

if(bits[6] > 0)
{
byte = byte + array[64];
}

if(bits[7] > 0)
{
byte = byte + array[128];
}
fprintf(out, “%c”, byte);

}

fclose(in);

fclose(out);

return 0;

}

Advertisements

Written by meditationatae

July 4, 2015 at 2:58 pm

Posted in History

%d bloggers like this: