I have 3 tellurian variables in my program. For some reason when we run
string2bin on pad a essence of binaryMessage get overwritten and we can't
figure out why. we increasing a distance of my malloc's though that didn't
help. What am we doing wrong?Note that randomPad() creates a twine of
futile "hex" values, that should be converted to a binary twine
representing a conjuration string.char * temp;char * binaryMessage;char *
pad;void process_message(char *s)int sure (int argc, const bake * argv[])
{ temp = (char *)malloc(sizeof(char *) *2048); binaryMessage
= (char *)malloc(sizeof(char *) *2048); pad = (char
*)malloc(sizeof(char *) * 2048); process_message("test");}char *
char2bin ( unsigned bake c ){ stationary bake bin[CHAR_BIT + 1] =
{0}; int i; for ( i = CHAR_BIT - 1; i >= 0; i-- ) {
bin[i] = (c % 2) + '0'; c /= 2; } relapse bin;}
char* string2bin(char* str){ int i;
int len = strlen(str);
sprintf(temp,""); for(i=0; i< len;i++){
sprintf(temp, "%s%s",temp,char2bin(str[i]));
} relapse temp; }
char* randomPad(){ int i;
const bake *hex_digits = "0123456789ABCDEF"; bake
* p = (char*)malloc(sizeof(char*)*242); // pristine
aged pad information //sprintf(pad,"");
// emanate futile twine of 242 conjuration chars to use as pad
for(i = 0; i< 242; i++){
sprintf(p,"%s%c",p,hex_digits[ ( rand() % 16 ) ]);
} relapse p; } vacant
process_message(char *s){ binaryMessage =
string2bin(s); printf("m %s\nbm %s\n",s,
binaryMessage); //get futile one time pad
pad = string2bin(randomPad());
printf("m %s\nbm %s\n",s, binaryMessage); }My
approaching cost is:m testbm 01110100011001010111001101110100m testbm
01110100011001010111001101110100My tangible cost is:m testbm
01110100011001010111001101110100m testbm
001101110011000100111001010000010011001000111000001110000100010100110011010001000011100000110101010000110011001000110011001101110011011100110001001110000011010001000110001100010100010000110101001110000011010101000010001101100011100000110111001110010011001000111000001100110011001000110001001100110100010000110011001101010100011000110000001100010011100001000100001100010100001101000010001100100011010100111001001100010011010000111000001101000011001001000011001101000100000100110111010000010100000100110101001110000011100100110101001100010011000000110100001101010100000100110101010000100100010000111001001101100011011100111000001100010011010100110011010001010100010000110101001101010011001100111001001101000100001001000001010000110011001100110001001100100011000001000101010000110011000100110110001110000100010000110001010001100011010000110001010001010011100101000100001101100011000000111001001101110011000101000110001100110100000101000101010001100011000001000011001101000011010101000001001110
0001000010001100000011100100110010010001010011001000110110001101010011001001000011010001100100010001000110001110000011011101000100010001010100011000110010001100010011000001000101001110000011011100110111010001010011010000110010001101110011011101000101001101110011000100111000001110010100010101000010001100100011010100110010001101100011011001000011001101000100010100110110010000010011001000110011001100100011010000110110001101100011011101000110001100110011100100110001001110000011001101000110001100010011100000110101010001100011010000110000001100000011011101000010001110010100010101000001010000100011011100111000010000110100011000110010010000110100001100110111010001100011000101000100001101010011000100110011001100010100000101000101001100110011000000110001001110010011000100110111010000110100001000111000010001100100011000110010001100110100001101000100001110000011000001000101001110000100001001000100010001100100011000110001001100010011000001000110
No comments:
Post a Comment