No older revisions available
No older revisions available
암호화 ¶
~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;
}