Created
May 7, 2014 09:54
-
-
Save theoremoon/9bfb32d6b496d21ba549 to your computer and use it in GitHub Desktop.
CaesarEncodeProgram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include "head/ReadFile.h" | |
using namespace std; | |
void decode(const char *filepath){ | |
std::string file = ReadFile(filepath); | |
unsigned int size = file.length(); | |
for(int i = 0; i < size; ++i){ | |
file.at(i) -= 10; | |
} | |
fstream fs("decoded.txt", std::ios::out); | |
if(!fs){ | |
cout << "ERROR" << endl; | |
} | |
fs << file << endl; | |
return; | |
} | |
int main(int argc, char *argv[]){ | |
if(argc <= 1){ | |
cout << "Finish." << endl; | |
return 0; | |
} | |
if(strcmp(argv[1], "decode") == 0){ | |
decode(argv[2]); | |
return 0; | |
} | |
string file; | |
file = ReadFile(argv[argc-1]); | |
unsigned int size = file.length(); | |
for(int i = 0; i < size; ++i){ | |
file.at(i) += 10; | |
} | |
fstream fs("encoded.txt", std::ios::out); | |
if(!fs){ | |
cout << "ERROR" << endl; | |
} | |
fs << file << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <fstream> | |
#include <string> | |
void ReadFile( const char* FileName, char* StrBuf ){ | |
std::ifstream ifs( FileName, std::ifstream::binary ); | |
int len; | |
ifs.seekg( 0, ifs.end ); | |
len = static_cast< int >( ifs.tellg() ); | |
ifs.seekg( 0, ifs.beg ); | |
StrBuf = new char[ len ]; | |
ifs.read( StrBuf, len ); | |
return; | |
} | |
std::string ReadFile( const char* FileName ){ | |
std::ifstream ifs( FileName, std::ifstream::binary ); | |
int len; | |
char* StrBuf; | |
std::string str; | |
ifs.seekg( 0, ifs.end ); | |
len = static_cast< int >( ifs.tellg() ); | |
ifs.seekg( 0, ifs.beg ); | |
StrBuf = new char[ len ]; | |
ifs.read( StrBuf, len ); | |
str = StrBuf; | |
delete[] StrBuf; | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment