[Pratice]递归形式的暴力破解。

本文探讨了编码与解码算法的基本概念,并通过一个简单的C++实现案例来演示如何将字母编码为特定的字符序列,重点突出了解码过程及其应用。
#include <iostream>
#include <cstring>
using namespace std;

//decode into the key
class Decode
{
public:
	Decode(const char ch[])
	{	
		count = 0;
		memset(key, 0, 128);
		Decode_helper(ch);
	}
	friend ostream& operator<<(ostream& o, Decode& m);
private:
	int count;
	char key[128];
	void Decode_helper(const char str[]);
};

//pratice, only consider alphabet
void Decode::Decode_helper(const char str[])
{
	if (!(str[0]))	return;
	for (int i = 0; i < 26; ++i)
	{
		if (str[0] == 'a' + i || str[0] == 'A' + i)
		{
			key[count] = 'a' + i;
			++count;
			Decode::Decode_helper(str + 1);
			return;
		}
	}	
}

//print
ostream& operator<<(ostream& o, Decode& m)
{
	for (int i = 0; i < m.count; ++i)
		o << m.key[i];
	return o;
}

int main(int argc, char const *argv[])
{
	char ch[128] = {0};
	cout << "Please enter your key : " << endl;
	cin >> ch;

	Decode work(ch);
	cout << work << endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值