I am really new to coding and I have to do this project for school. We were required to encrypt a paragraph into binary and put that into a .out file. I did that, but now I have to take that .out file and work 'backwards' to translate that .out file from binary back into ASCII. We are not allowed to use math.h or stdlib.h I am currently trying:
#include <stdio.h>
int main()
{
char x = 0;
int i;
int asciiVal = 0;
while(x != EOF)
{
int binary[8];
for(i = 7; i >= 0; i--)
{
asciiVal += (1 << i) * binary[7 - i];
}
return asciiVal;
}
return 0;
}
This is the encryption I did which works:
int main(void)
{
char x = 0;
int i;
while(x != EOF)
{
x = getchar();
for(i = 0; i < 8; i++)
{
putchar((x & (1 << i)) ? '1' : '0');
}
putchar('\n');
}
return 0;
}
I should also mention that I am getting an error with my array as it says "may be used uninitialized in this function." What I really don't understand is how to read the file 8 bits at a time, translate them into decimal, and then into ASCII.