RC4密码算法实现

#include
#include
using namespace std;

void swap(int&, int&);

int main(){
	int bit;//这个bit实际是二的这个次方才对,为了避免引入算2的n次方就直接用了吧 
	cout << "请输入元素个数: ";cin >> bit;
	int* S = new int[bit];
	int* T = new int[bit];
	int* key = new int[bit];
	//连续临时向量 
	int start,end;
	cout << "请输入连续临时向量范围: ";	cin >> start >> end;
	for(int i=0,j=start; i>times;
	for(int i=0,j=0,time=1,t,k ; time<=times ; time++){
		i=(i+1)%bit;
		j= (j+S[i])%bit;
		swap(S[i] , S[j]);
		t = (S[i]+S[j])%bit;
		k = S[t];
		cout << k << endl;
	} 
	
	delete key;
	delete T;
	delete S;
	return 0;
} 
void swap (int &a, int &b){
	int c;
	c=a;
	a=b;
	b=c;
}


 
 

你可能感兴趣的:(算法)