跳到正文

个人记录

解密和加密函数

xiaoke2021约 3 分钟
原文
文章信息与版本

文章信息

发布
2024年12月31日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 3 分钟

版本

  1. v1当前

cipher 为密钥,为 64 位的字符串,最好是 SHA256 加密的内容。

C++
void Encryption(vector<string> &Ciphertext,string cipher){
	for(auto it=cipher.begin();it!=cipher.end();it++) (*it)-=32;
	for(auto it=Ciphertext.begin();it!=Ciphertext.end();it++){
		string ciphertext=*it;
		for(auto it2=ciphertext.begin();it2!=ciphertext.end();it2++) (*it2)-=32;
		//x%96+32
		while(ciphertext.size()<64) ciphertext.push_back(0);
		for(int i=0;i<=32;i++){
			for(int j=0;j<32;j++){
				ciphertext[i+j]=(ciphertext[i+j]+cipher[i+j])%96;
				cipher=cipher.back()+cipher.substr(0,63);
			}
		}
		for(auto it2=ciphertext.begin();it2!=ciphertext.end();it2++) (*it2)+=32;
		(*it)=ciphertext.substr(0,(int)(*it).size());
	}
}
void Decryption(vector<string> &Enphertext,string cipher){
	for(auto it=cipher.begin();it!=cipher.end();it++) (*it)-=32;
	for(auto it=Enphertext.begin();it!=Enphertext.end();it++){
		string enphertext=*it;
		for(auto it2=enphertext.begin();it2!=enphertext.end();it2++) (*it2)-=32;
		//x%96+32
		while(enphertext.size()<64) enphertext.push_back(0);
		for(int i=0;i<=32;i++){
			for(int j=0;j<32;j++){
				enphertext[i+j]=(enphertext[i+j]+96-cipher[i+j])%96;
				cipher=cipher.back()+cipher.substr(0,63);
			}
		}
		for(auto it2=enphertext.begin();it2!=enphertext.end();it2++) (*it2)+=32;
		(*it)=enphertext.substr(0,(int)(*it).size());
	}
}
原文