Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

비밀키/황재선: Difference between revisions

From ZeroWiki
imported>Unknown
No edit summary
 
(Repair batch-0005 pages from live compare)
 
Line 12: Line 12:
  int i;
  int i;
   
   
  char data[100] = {'0', };
  char data[100] = {'0', };
 
 
  int count = 0;
  int count = 0;
Line 22: Line 22:
  break;
  break;
  cout << input;
  cout << input;
  data[count] = input;
  data[count] = input;
  count++;
  count++;
  }
  }
  data[count] = NULL;
  data[count] = NULL;
  cout << endl;
  cout << endl;
   
   
Line 34: Line 34:
 
 
  cout << "암호화" << endl;
  cout << "암호화" << endl;
  for (i = 0; data[i] != NULL ;i++)
  for (i = 0; data[i] != NULL ;i++)
  {
  {
  data[i] += key;
  data[i] += key;
  fout << char(data[i]);
  fout << char(data[i]);
  cout << char(data[i]);
  cout << char(data[i]);
  }
  }
  cout << endl;
  cout << endl;
  fout << endl;
  fout << endl;
  cout << "복호화" << endl;
  cout << "복호화" << endl;
  for (i = 0; data[i] != NULL ;i++)
  for (i = 0; data[i] != NULL ;i++)
  {
  {
  data[i] -= key;
  data[i] -= key;
  fout << char(data[i]);
  fout << char(data[i]);
  cout << char(data[i]);
  cout << char(data[i]);
  }
  }
  cout << endl;
  cout << endl;
Line 54: Line 54:
  }
  }
----
----
[[암호화실습]], [[데블스캠프2004/목요일]]
[[암호화실습]], 데블스캠프2004/목요일
 

Latest revision as of 00:44, 27 March 2026

비밀키

#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;
}

암호화실습, 데블스캠프2004/목요일