U E D R , A S I H C RSS

개인키,공개키/류주영,문보창

공개키 : 182

류주영

암호화

~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;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:40
Processing time 0.0054 sec