查看: 630|回复: 3

[原创] 使用凯撒密码加密信息

[复制链接]

0

技术

9

魅力

1

原创

版主

禁止访问

Rank: 7Rank: 7Rank: 7

积分
7757
人气
176
分享
52

最佳新人活跃会员

发表于 2023-4-19 18:58:14 | 显示全部楼层 |阅读模式
本帖最后由 蒟蒻 于 2023-4-19 19:06 编辑

【前言】
论坛坛友们大家好,我是练习时长
几个月的个人练习生蒟蒻
今天给大家带来凯撒密码的使用教程
(本来想做个软件的,结果老是卡bug,也懒得去修,就shift+delete了)
【什么是凯撒密码】
凯撒密码是一种简单,但是些许不安全的加密算法
一个密码学家,及时没有获取到密钥,也可以推算出原内容(因为原理简单)
【凯撒密码加密原理】

凯撒密码的加密原理如下:
例如,明文是
I'm a real ikun and a real homo

密钥是5
那么加密后的密文就是
N'r f wjfq npzs fsi f wjfq mtrt

原理就是把每个字母的ANSI码都加上5,就得到了密文
【新制作的凯撒密码加密器】
花五分钟写的答辩,将就着看吧
[C++] 纯文本查看 复制代码
/**
* JRCaeser Project
* Copyright (c) 2023 Storm Lab.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author Github JuRuoqwq
**/

#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstring>

char * EncryptData(char* Source, size_t StrSize, int key)
{
	for (int i = 0; i < StrSize; i++) {
		Source[i] = Source[i + key];
	}
	return Source;
}

char * DecryptData(char* Source, size_t StrSize, int key)
{
	char dekey = key - (key * 2); //key的负数
	for (int i = 0; i < StrSize; i++) {
		Source[i] = Source[i + dekey];
	}
	return Source;
}

int main(void)
{
	printf("Mode(1.Encrypt,2.Decrypt) $ ");
	int mode;
	int scan = scanf("%d", &mode);
	printf("Key(> -128 && < 127) $ ");
	int key;
	int scan1 = scanf("%d", &key);
	printf("Data(Use underline links in spaces) $ ");
	char* data = new char[1000];
	int scan2 = scanf("%s", data);
	data = strcat(data, "\0");
	if (mode == 1) {
		printf("Data is %s\n", EncryptData(data, strlen(data), key));
		delete[] data;
	}
	else if (mode == 2) {
		printf("Data is %s\n", DecryptData(data, strlen(data), key));
		delete[] data;
	}
	else {
		printf("Error Mode!");
		return -1;
	}
	return 0;
}

评分

参与人数 1经验 +30 人气 +5 分享 +3 收起 理由
hjz713 + 30 + 5 + 3 教程区发帖满4或以上(原创)奖励.

查看全部评分

小菜鸡一枚~
Gitee主页:https://gitee.com/juruoqwq

1

技术

7

魅力

2

原创

管理员

Rank: 9Rank: 9Rank: 9

积分
6976
人气
211
分享
49

灌水之王论坛元老优秀版主活跃会员

发表于 2023-4-30 17:17:37 | 显示全部楼层
我怎么记得是加上3
论坛事务联系邮箱 henry217@x64bbs.cn

0

技术

9

魅力

1

原创

版主

禁止访问

Rank: 7Rank: 7Rank: 7

积分
7757
人气
176
分享
52

最佳新人活跃会员

 楼主| 发表于 2023-5-2 12:33:48 | 显示全部楼层
henry217 发表于 2023-4-30 17:17
我怎么记得是加上3

本来确实是的,但是我想自定义密钥
(其实理论上讲,加上及都可以~)
小菜鸡一枚~
Gitee主页:https://gitee.com/juruoqwq

3

技术

3

魅力

5

原创

略有小成

Rank: 4

积分
2953
人气
102
分享
31
发表于 2023-5-2 14:02:07 | 显示全部楼层
不知道用Python写一个需要多少行
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表