공개 : 182 ¶
¶
~cpp #include <iostream> #include <fstream> #include<string> using namespace std; int main() { ifstream fin("source.txt"); // fin과 input.txt 결 ofstream fout("source_enc.txt"); // fout과 output.txt 결 string input; int key = 74; //cout << " 값 : "; //cin >> key; char ch; while(!fin.eof()) { fin.get(ch); if(fin.eof()) break; if((int(ch) + key) < 256) { if(ch!=' ') { for(int j=0;j<key;j++) ch++; } } else { if(ch!=' ') { for(int j=0;j<((int(ch) + key)%256);j++) ch++; } } fout << ch; } return 0; }
¶
~cpp #include <iostream> #include <fstream> #include<string> using namespace std; int main() { ifstream fin("source_enc.txt"); // fin과 input.txt 결 ofstream fout("source_enc2.txt"); // fout과 output.txt 결 string input; int key; cout << "공개 : "; cin >> key; char ch; while(!fin.eof()) { fin.get(ch); if(fin.eof()) break; if((int(ch) + key) < 256) { if(ch!=' ') { for(int j=0;j<key;j++) ch++; } } else { if(ch!=' ') { for(int j=0;j<((int(ch) + key)%256);j++) ch++; } } fout << ch; } return 0; }