大二(上) Windows 加密与解密

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;

//原码:Trvdizrrvj
//译码:GSOOWFASOq

int main() {
	char *a = (char*)malloc(sizeof(char) * 1000);
	char *b = (char*)malloc(sizeof(char) * 1000);
	printf("待解密字符串为:");
	cin >> a;

	//1.大小写反转 
	int i = 0;
	while (a[i])
	{
		if (a[i] - 65 >= 0 && a[i] - 65 <= 25)
		{
			a[i] = a[i] + 32;
		}
		else if (a[i] - 97 >= 0 && a[i] - 97 <= 25)
		{
			a[i] = a[i] - 32;
		}
		i++;
	}
	

	//2.逆序存储
	int i2 = 0,  length = 0;
	i = 0;
	while (a[i])
	{
		length++;
		i++;
	}
	for (i = length - 1; i >= 0; i--)
	{
		b[i2] = a[i];
		i2++;
	}
	b[i2] = '\0';

	//3.字符左移三个位置 
	for (int i1 = 0; i1 < 3; i1++) {
		for (int i = 0; b[i] != '\0'; i++)
		{
			if (b[i] - 97 >= 0 && b[i] - 97 <= 25)
			{
				b[i] = (b[i] - 'a' + 1 + 26) % 26 + 'a';
			}
			if (b[i] - 65 >= 0 && b[i] - 65 <= 25)
			{
				b[i] = (b[i] - 'A' + 1 + 26) % 26 + 'A';
			}
		}
	}

	printf("解密的字符串为:%s\n", b);
	system("pause");
}
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;

int main() {
	char *a = (char*)malloc(sizeof(char) * 1000);
	char *b = (char*)malloc(sizeof(char) * 1000);
	printf("待加密字符串为:");
	cin >> a;

	//1.字符左移三个位置 
	for (int i1 = 0; i1 < 3; i1++) {
		for (int i = 0; a[i] != '\0'; i++)
		{
			if (a[i] - 97 >= 0 && a[i] - 97 <= 25)
			{
				a[i] = (a[i] - 'a' - 1 + 26) % 26 + 'a';
			}
			if (a[i] - 65 >= 0 && a[i] - 65 <= 25)
			{
				a[i] = (a[i] - 'A' - 1 + 26) % 26 + 'A';
			}
		}
	}

	//2.逆序存储
	int i2 = 0, i = 0, length = 0;
	while (a[i])
	{
		length++;
		i++;
	}
	for (i = length - 1; i >= 0; i--)
	{
		b[i2] = a[i];
		i2++;
	}
	b[i2] = '\0';

	//3.大小写反转 
	i = 0;
	while (b[i])
	{
		if (b[i] - 65 >= 0 && b[i] - 65 <= 25)
		{
			b[i] = b[i] + 32;
		}
		else if (b[i] - 97 >= 0 && b[i] - 97 <= 25)
		{
			b[i] = b[i] - 32;
		}
		i++;
	}
	printf("加密的字符串为:%s\n", b);
	system("pause");
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值