?? main.cpp
字號:
#include <iostream>
#include "time.h"
#include "stdlib.h"
#include "fstream.h"
#include "string.h"
using std::endl;
int wrap(int num) //wraps around a number
{
if (num > 255)
{
num = num - 256;
} //end if
if (num < 0)
{
num = num + 257;
} //end if
return(num);
} //end wrap()
void encode(char *line, int key) //encodes a string of text
{
for (int i = 0; i < static_cast<int> (strlen(line)); i++)
{
line[i] = static_cast<char> (wrap((static_cast<int>(line[i])) + key));
} //end for
} //end encode()
void decode(char *line, int key) //decodes a string of text
{
for(int i = 0; i < static_cast<int>(strlen(line)); i++)
{
line[i] = static_cast<char>(wrap((static_cast<int>(line[i])) - key));
} //end for
} //end decode()
char* back(char *line) //reverses a string of text
{
char temp[200];
int length = static_cast<int>(strlen(line));
for(int i = 0; i < length; i++)
{
temp[i] = line[length - i];
} //end for
temp[i] = static_cast<char>(0);
return(temp);
} //end back()
int main() //main body
{
//set variables
char file_name[100],file_out[100],buffer[200];
ofstream fout;
ifstream fin;
int choose,key = 0;
//get input
cout << "Encode (1) or decode (2) a file? ";
cin >> choose;
cout << "Choose file to input: ";
cin >> file_name;
fin.open(file_name);
cout << "Choose file to output to: ";
cin >> file_out;
fout.open(file_out);
//do preliminary setup
if (choose == 1)
{
while (key == 0)
{
key = time(NULL) % 11;
} //end while
fout << (3*key) << endl;
} //end if
if (choose == 2)
{
cout << "\n";
fin >> key;
key = static_cast<int>(key/3);
} //end if
//end line and do operation
while(!fin.eof())
{
fin.getline(buffer,200,'\n');
if (choose == 1)
{
encode(back(buffer),key);
} //end if
if (choose == 2)
{
decode(back(buffer),key);
} //end if
fout << buffer << endl;
} //end while
//do finishing steps
fout.close();
fin.close();
cout << "Operation Complete";
cin >> buffer;
return(1);
} //end main()
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -