More actions
imported>Unknown No edit summary |
(Repair batch-0004 pages from live compare) |
||
| Line 105: | Line 105: | ||
return 0; | return 0; | ||
} | } | ||
Latest revision as of 00:37, 27 March 2026
공개키 : 182
류주영
암호화
#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;
}
복호화
#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;
}