forked from ucsd-cse30-fall-2016/lab03-starter-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoder.h
More file actions
76 lines (71 loc) · 3.15 KB
/
encoder.h
File metadata and controls
76 lines (71 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* DO NOT MODIFY THIS FILE. IT WILL NOT BE COLLECTED
*/
#pragma once
#include <stdio.h>
#include <limits.h>
/**
*
* This function takes a char c as input and returns a (6 character) array
* that represents the 6 digit code for that character. This code is simply
* the index of the char in the MAPPING array (represented in binary).
* You should use the REVERSE\_MAPPING array in this function to get
* the binary code for the character. REVERSE\_MAPPING array MUST be
* initialized with createReverseMapping(), prior to calling this function.
*
* @param c The input character to encode
* @returns a six character array which encodes the index into ASCII binary
*/
char* encodeChar(char c);
/**
* Takes a char c and int bit (should be either 0 or 1) and int index as input.
* Sets the bit at input index of c to be the input bit and returns the result.
* The 0 index refers to the LSB, so for example, index 2 should
* set the 3rd least significant bit.
*
* @param c the char to implant a bit into
* @param bit the bit value to implant (0 or 1)
* @param index the index to insert the bit into (0 is LSB)
* @returns the char with bit b implanted into the input index
*/
char implantBit(char c, int bit, int index);
/**
* Takes a FILE handle in as input (corresponding to a regular ASCII
* text file) and reads the file, char by char. Encodes each char into
* a 6 character "binary" char array (by calling encodeChar). The
* resulting character arrays should be written to the output file
* handle out
*
* @param in The input text file to read
* @param out The output file, in ASCII encoded "binary"
*/
void textToBinary(FILE *in, FILE *out);
/**
* Takes a FILE handle in as input (corresponding to a
* "binary" encoded file) and reads the file 1 char at a time. Each
* char read will be an ASCII '0' or ASCII '1', and either 0 or 1
* will be implanted into randomized chars generated by rand()%256.
*
* If ASCII '0', then implant 0 into the bit at the input index
* of a randomized char . If ASCII '1', then implant 1 into the bit at
* the input index of the randomized char (by calling implantBit).
* Write the result into the output file handle out
* (Note: The least significant bit is in index 0)
*
* @param in The input file handle to read (ASCII encoded binary)
* @param out The output file to write to
* @param index The index of the bit into which binary values should be implanted (0 is LSB)
*/
void binaryToCode(FILE *in, FILE *out, int index);
/**
* Reads in a file from the specified input path and outputs a a binary encoding to
* specified bin path and a fully encoded version to specified output path.
* This should simply open the necessary files and call the above helper
* functions in the correct sequence, and close the necessary files.
*
* @param input the path to the input file
* @param bin the path to the encoded ASCII binary output file
* @param output the path to the encoded output file
* @param index The index of the bit into which binary values should be implanted (0 is LSB)
*/
void encodeFile(char* input, char* bin, char* output, int index);