全新加密算法

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll DecToBin(int dec){
	ll ans = 0;
	ll rem,coe = 1;
	while(dec != 0){
		rem = dec % 2;
		ans += coe * rem;
		coe *= 10;
		dec /= 2;
	}
	return ans;
}
string LonglongToString(ll longlongcode){
	ostringstream os;
	os<<longlongcode;
	string ans;
	istringstream is(os.str());
	is>>ans;
	return ans;
}
string BinStrToHexStr(string str){
	string str_Hex = "";
	string temp_Hex = "";
	int iHex = 0;
	if (str.size() % 4 != 0){
		int num = 4 - (str.size() % 4);
		for (int i = 0; i < num; i++){
			str = "0" + str;
		}
	}
	for (int i = 0; i < str.size(); i += 4){
		iHex = (str[i] - '0') * 8 + (str[i + 1] - '0') * 4 + (str[i + 2] - '0') * 2 + (str[i + 3] - '0') * 1;
		if (iHex >= 10){
			int left = iHex % 16;
			temp_Hex = 'A' + left - 10;
		}
		else{
			temp_Hex = to_string(iHex);
		}
		str_Hex += temp_Hex;
	}
	return str_Hex;
}
int main(){
	cout<<"Input the passage that you need to encrypt it:";
	cout<<endl;
    string incode;
    getline(cin,incode);
    ll codelen = incode.length();
    cout<<"This is the code you want:";
    cout<<endl;
    for(ll i = 0;i < codelen;i++){
    	if(incode[i] >= 'a' && incode[i] <= 'z'){
    		int code = int(incode[i]);
    	    string hex = BinStrToHexStr(LonglongToString(DecToBin(code)));
    	    cout<<hex.c_str()<<" ";
		}
		else if(incode[i] >= 'A' && incode[i] <= 'Z'){
    		int code = int(incode[i]);
    	    string hex = BinStrToHexStr(LonglongToString(DecToBin(code)));
    	    cout<<hex.c_str()<<" ";
		}
		else if(incode[i] == ' '){
			cout<<"  ";
		}
		else{
			cout<<" "<<incode[i]<<"  ";
		}
	}
	return 0;
}

有想开发解密算法的人可以关注我!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值