凯撒加密
来源:互联网 发布:seo必备工具 编辑:程序博客网 时间:2024/04/28 23:29
凯撒加密是一种最简单且最广为人知的加密技术。它是一种替换加密技术,明文中所有的字母都在字母表上向前或向后按照一个固定数目进行偏移后被替换成密文。例如,当偏移量是3的时候,所有的字母A被替换成D,B变成E,以此类推。
下面我是用C++实现的凯撒加密。
#include<iostream>#include<string.h>using namespace std;char encrypt(string &ch,int n){/*加密函数,把字符向右循环移位n*/ for(int i=0;i<ch.length();i++){ if(ch[i]>='A'&&ch[i]<='Z') ch[i]='A'+(ch[i]-'A'+n)%26; if(ch[i]>='a'&&ch[i]<='z') ch[i]='a'+(ch[i]-'a'+n)%26; } cout<<"加密后为:"; for(int j=0;j<ch.length();j++){ cout<<ch[j]<<" "; } cout<<endl;} char exEncrypt(string &ch1,int n1){/*解密函数,把字符向左循环移位n*/ for(int i=0;i<ch1.length();i++){ if(ch1[i]>='A'&&ch1[i]<='Z') ch1[i]='A'+(ch1[i]-'A'-n1)%26; if(ch1[i]>='a'&&ch1[i]<='z') ch1[i]='a'+(ch1[i]-'a'-n1)%26; } cout<<"解密后为:"; for(int j=0;j<ch1.length();j++){ cout<<ch1[j]<<" "; } cout<<endl;} int main(){ string a; int n; cin>>a>>n; encrypt(a,n); exEncrypt(a,n); return 0;}
运行结果如图:
阅读全文
0 0
- 凯撒加密
- 凯撒加密
- 凯撒加密
- 凯撒加密
- 凯撒加密
- 凯撒加密
- 凯撒密码,凯撒加密解密.
- 凯撒 加密 解密
- 凯撒的加密术
- 凯撒加密器
- 凯撒加密实现
- python实现凯撒加密
- 凯撒加密caesar
- c++ 凯撒加密
- IDF凯撒加密
- C语言凯撒加密
- 凯撒加密问题
- HDU1048 凯撒加密
- Spring IOC容器初始化过程解析
- (H)Dynamic Programming:312. Burst Balloons
- HDU1827 Summer Holiday 解题报告【tarjan/强连通分量+缩点】
- 微信支付SDK “支付验证签名失败”,怎么也找不到原因?
- php 单引号和双引号的区别
- 凯撒加密
- Java Activiti(9)--网关
- java while循环写99乘法表
- 构造函数(方法)
- python网络爬虫实战笔记(一)
- C 数组名取地址
- C语言题目五
- Nginx平滑升级源码分析
- 购物车的实现思想