비밀키

~cpp 
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
	ifstream fin("source.txt");
	ofstream fout("source_enc.txt");

	char input;
	int i;

	char data[100] = {'0', };
	
	int count = 0;
	cout << "원본값" << endl;
	while(true)
	{
		fin.get(input);		
		if (fin.eof())
			break;
		cout << input;
		data[count] = input;
		count++;
	}
	data[count] = NULL;
	cout << endl;


	int key;
	cout << "Key 입력 :  ";
	cin >> key;
	
	cout << "암호화" << endl;
	for (i = 0; data[i] != NULL ;i++)
	{
		data[i] += key;
		fout << char(data[i]);
		cout << char(data[i]);
	}
	cout << endl;
	fout << endl;
	cout << "복호화" << endl;
	for (i = 0; data[i] != NULL ;i++)
	{
		data[i] -= key;
		fout << char(data[i]);
		cout << char(data[i]);
	}
	cout << endl;

	return 0;
}
Retrieved from http://wiki.zeropage.org/wiki.php/비밀키/황재선
last modified 2021-02-07 05:29:37