Friday, February 15, 2008

'uʍop əpısdn sı ʇsod sıɥ⊥

Some code:


#include <cstdlib>
#include <iostream>
#include <fstream>

#define BUFFERLENGTH 500

using namespace std;

// character map for upside down characters
char* charactermap[] = { "¡", ",,", "#", "$", "%", "&", ",", //33-39
")", "(", "*", "+", "´", "-", "'", "/", // 40-47
"0", "1", "&#9761;", "&#400;", "&#4281;", "S", "9", "L", "8", "6", // 48-57
":", ";", ">", "=", "<", "¿", "@", // 58-64
"&#8704;", "&#666;", "&#390;", "p", "&#8707;", "&#8498;", "&#1508;", // A-G
"H", "I", "&#383;", "&#65276;", "&#1498;", "W", "N", "O", "d", "&#8184;", // H-Q
"&#641;", "S", "&#8869;", "&#8745;", "&#923;", "M", "X", "&#411;", "Z", // R-Z
"]", "\\", "[", "^", "¯", ".", // 91-96
"&#592;", "q", "&#596;", "p", "&#601;", "&#607;", "&#387;", "&#613;", // a-h
"&#305;", "&#1360;", "&#670;", "&#1503;", "&#623;", "u", "o", "d", "b", "&#633;", // i-r
"s", "&#647;", "n", "&#652;", "&#653;", "x", "&#654;", "z", // s-z
"}", "|", "{", "~" // 123-126
};

// returns length of word
int getLength(const char* word)
{
int len = 0;
while (word[len] != 0 && len < BUFFERLENGTH)
len++;

if (len == BUFFERLENGTH)
len = 0;

return len-1;
}

// writes upside down character sequence into stream
void writeConvertedChar(ofstream& stream, char c)
{
if (c < 33 || c > 126)
stream << c;
else
stream << charactermap[c-33];
}

int main (int argc, char** argv)
{
// open input file
ifstream fin;

if (argc >= 2)
fin.open(argv[1]);
else
fin.open("data.txt");

if ( !fin )
return 1;

// open output file
ofstream fout("upsidedown.html");
if ( !fout )
return 2;

// go through input file, iterate through each line backwards,
// and call writeConvertedChar to put the upside down version of each
// character in
char buffer[BUFFERLENGTH];
while ( fin.getline(buffer, BUFFERLENGTH) )
{
cout << buffer << endl;

for (int i = getLength(buffer); i >= 0; i--)
writeConvertedChar( fout, buffer[i] );

fout << endl;
}

fin.close();
fout.close();

return 0;
}


This extremely exciting program allows me to be a prankster on message boards and post entire messages uʍop əpısdn.

No comments: