文字加密
Encryption是目前電腦科學中最熱的主題之一,在此介紹它基本的概念並利用XOR來實現。
在未經過任何加工加密的訊息或文字稱它為plain text,經過加密(encrypt)轉換成所謂的
cipher text,可避免在傳送的過程中遭受到未經授權人的擷取並加以利用成功,在接收端
必須做解密(decrypt)的動作,將cipher text轉回原本的plain text!!!詳細的過程可參考
http://www.pgpi.org/

接著以一個C++的程式來實作這個過程

範例:
::::::::::::::::::::::::::::::::::::::::::::::
#include<iostream>
using namespace std;

void main()
{
	const int KEY = 123;	//1 ~ 255之間任意取
	char str[] = "James";
	int len = sizeof(str);
	int index;

	cout<<"Before encrypting:"<<str<<endl;

	//encryption
	for(index=0;index<len;++index)
		str[index] = str[index] ^ KEY;

	cout<<"After encrypting:"<<str<<endl;

	//decryption
	for(index=0;index<len;++index)
		str[index] = str[index] ^ KEY;

	cout<<"After decrypting:"<<str<<endl;
	
}
::::::::::::::::::::::::::::::::::::::::::::::
那有個疑問為什麼要用XOR呢?你發現了嗎?
XOR處理二次就跟沒做是一樣的!!!就可以回復到原本的資料!!!
但其實沒有容易的,這只是簡單的範例!!!
回目錄
Written By James On 2004/02/08 

 

Hosted by www.Geocities.ws

1