More actions
imported>Unknown No edit summary |
(Repair batch-0005 pages from live compare) |
||
| Line 7: | Line 7: | ||
int main(){ | int main(){ | ||
char secret | char secret[30]; | ||
cout << "암호화할 텍스트를 입력하세요 : "; | cout << "암호화할 텍스트를 입력하세요 : "; | ||
cin >> secret; | cin >> secret; | ||
| Line 42: | Line 42: | ||
char unsecret | char unsecret[30]; | ||
cout << "복호화할 텍스트를 입력하세요 : "; | cout << "복호화할 텍스트를 입력하세요 : "; | ||
| Line 85: | Line 85: | ||
int main(){ | int main(){ | ||
char secret | char secret[30]; | ||
cout << "암호화할 텍스트를 입력하세요 : "; | cout << "암호화할 텍스트를 입력하세요 : "; | ||
cin >> secret; | cin >> secret; | ||
| Line 104: | Line 104: | ||
int i = 0; | int i = 0; | ||
while (!fin.eof()){ | while (!fin.eof()){ | ||
ch = text | ch = text[i] + key; | ||
if (text | if (text[i] == '\0') { | ||
i = 0; | i = 0; | ||
cout << endl; | cout << endl; | ||
| Line 123: | Line 123: | ||
} | } | ||
[[암호화실습]] | [[암호화실습]] | ||
Latest revision as of 00:44, 27 March 2026
비밀키/권정욱
string 비이용
#include <iostream>
#include <fstream>
using namespace std;
int main(){
char secret[30];
cout << "암호화할 텍스트를 입력하세요 : ";
cin >> secret;
ifstream fin(secret);
ofstream fout("source_enc.txt");
int key1, key2;
char ch;
char text;
cout << "암호키를 입력하세요 : ";
cin >> key1;
fin.get(text);
cout << "암호화를 실행합니다.\n";
while (!fin.eof()){
ch = text + key1;
if (text == '\n') {
cout << endl;
fout << endl;
}
else{
cout << ch;
fout << ch;
}
fin.get(text);
}
fin.close();
fout.close();
char unsecret[30];
cout << "복호화할 텍스트를 입력하세요 : ";
cin >> unsecret;
ifstream ffin(unsecret);
ofstream ffout("resource_enc.txt");
cout << "암호키를 입력하세요 : ";
cin >> key2;
if (key1 != key2) {
cout << "키가 틀립니다.\n";
return 0;
}
ffin.get(text);
cout << "복호화를 실행합니다.\n";
while (!ffin.eof()){
ch = text - key2;
if (text == '\n') {
cout << endl;
ffout << endl;
}
else{
cout << ch;
ffout << ch;
}
ffin.get(text);
}
return 0;
}
string 이용
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
char secret[30];
cout << "암호화할 텍스트를 입력하세요 : ";
cin >> secret;
ifstream fin(secret);
ofstream fout("source_enc.txt");
int key;
string text;
char ch;
cout << "암호키를 입력하세요 : ";
cin >> key;
fin >> text;
cout << "암호화를 실행합니다.\n";
int i = 0;
while (!fin.eof()){
ch = text[i] + key;
if (text[i] == '\0') {
i = 0;
cout << endl;
fout << endl;
fin >> text;
}
else{
cout << ch;
fout << ch;
i++;
}
}
cout << endl;
cout << "키값은 : " << key << "입니다.\n";
fout << "키값은 : " << key << "입니다.\n";
return 0;
}