简单加密算法

main()中接收需要加密的字符串,加密时,字符指针+1,Encrpy参数为字符指针, 解密时-1,Decrpy参数也是字符指针

#include <iostream>
#include<cstring>
#include<cmath>
using namespace std;

void Encrpy(char *p){
	int n=strlen(p);
	for(int i=0;i<n;i++){
		//cout<<strlen(p)<<endl;
		*p=*p+1;
		p++;
	}
}

void Decrpy(char *p){
	int n=strlen(p);
	for(int i=0;i<n;i++){
		*p=*p-1;
		p++;
	}
}

int main()
{
	char str[20];
	char *p;
	cout<<"输入字符串:"; 
	cin>>str;
	p=str;
	//cout<<"源字符串:"<<p<<endl;

	Encrpy(p);
	cout<<"加密结果:"<<p<<endl;
	Decrpy(p);
	cout<<"解密结果:"<<p<<endl;
	return 0;
}

发布了25 篇原创文章 · 获赞 8 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/natures66/article/details/88122873