// Code Color in C v1.0 // 19/04/06 // Mabus // Current stage is complete with encoding message, write new program to decode #include #include #include using namespace std; //Octet is used with characterconvert, stores two hex digits //Color is used with threeconvert, takes three octets and makes a colorcode //Input is used with main, it's the text the user inputs //Message is where all of the encoded data is stored before being written to file string strOctet, strColor, strInput,strMessage; //function prototypes /*This function is basic in that it takes a value of 0-15 from character convert and it converts it into a hex digit, 0-F, and sends it back*/ char singleconvert(int intDigit); /*threeconvert calls this function to turn one character into one octet, ie: two hex characters, ranging from 00-FF. The function in turn calls singleconvert to convert each of the two digits into hex values, this function assembles them and sends them back to threeconvert */ void characterconvert (char chrInput); /*threeconvert is sent the string strThree from the spindle, and it calls upon the characterconvert function three times. It is in this function that the color codes are actually generated, and returned to spindle*/ void threeconvert(string strThree); /*called by main, this function splits up the strInput it is given into threes, and sends each segment to threeconvert, which in turn uses the other converts to get color codes. After each color code is found, it is sent to the spool. This function calls the filewriter after strInput is completely traversed through, and the spool is ready to be written to file*/ void spindle(string strInput); /*Color codes are sent to the spool via strHexValue from the spindle. This function generates the HTML necessary to display one line of text in the color given to it by the spindle, calculated by threeconvert. The generated line is appended to the end of the file*/ void spool(string strHexValue); /*Once the spindle has completed using the other processes to turn strInput (user input) into strMessage (the html with messages encoded in color), spindle calls on this to take strMessage and write it to index.html*/ void filewriter(string strToBeWritten); int main() { cout << "Enter message to be encoded." << endl; cin >> strInput; spindle(strInput); return 0; //exit out of main() succcessfully } void spool(string strHexValue) //storage of to be written { strMessage.append("fuck
"); } void filewriter(string strToBeWritten) //writes the message accumulated in spool to file { ofstream target("index.html"); //opens html file if (! target) //tests for file open { cout << "Error opening file!" << endl; } target << strToBeWritten << endl; target.close(); //close file } void spindle(string strInput) //takes a string and divides it up into 3s, distributes { string strThree; //string to get shot at threeconvert while( (strInput.size()%3) != 0 )//if it's not divisible by three, make it so { strInput.append(" "); } int i = 0; int j; while(i < strInput.size()) //traverses through the string { strThree = ""; //clear string before preparation for (j = i; j < (i + 3); j++) //does an action to three of em { strThree = strThree + strInput.at(j); } threeconvert(strThree); //sends three letters to be encoded to strColor spool(strColor); //sends the current 3 encoded chars to spool i = i + 3; } filewriter(strMessage); //sends spooled message to be written } void threeconvert (string strThree) //takes 3 chars, converts to a color code { char chrCurrentChar; //character to be converted strColor = ""; //clears color int i; //counter variable for (i = 0; i < 3; i++) //loop runs through three times, for three octets { chrCurrentChar = strThree.at(i); characterconvert(chrCurrentChar); //gives a char to be converted strColor = strColor + strOctet; //adds octet to the character } } void characterconvert (char chrInput) //turns given character into octet { strOctet = ""; //clear variable int intAscii, intFirstDigit, intSecondDigit; intAscii = (int) chrInput; //put in integer value for division intFirstDigit = intAscii / 16; intSecondDigit = intAscii % 16; // following line sends 2 digits to convert to hex digits, then combines to form octet (strOctet += singleconvert(intFirstDigit)) += singleconvert(intSecondDigit); } char singleconvert(int intDigit) //turns given digit into hex character { char chrReturn; switch (intDigit) { case 0: chrReturn = '0'; break; case 1: chrReturn = '1'; break; case 2: chrReturn = '2'; break; case 3: chrReturn = '3'; break; case 4: chrReturn = '4'; break; case 5: chrReturn = '5'; break; case 6: chrReturn = '6'; break; case 7: chrReturn = '7'; break; case 8: chrReturn = '8'; break; case 9: chrReturn = '9'; break; case 10: chrReturn = 'A'; break; case 11: chrReturn = 'B'; break; case 12: chrReturn = 'C'; break; case 13: chrReturn = 'D'; break; case 14: chrReturn = 'E'; break; case 15: chrReturn = 'F'; break; } return chrReturn; //return the value determined }