python凯撒密码实现

Before we start let’s some basic terminology...

在开始之前,让我们先介绍一些基本术语...

The art and science to achieve security by encoding messages to make them unreadable are known as Cryptography. That’s what the whole article is going about.

通过对消息进行编码以使其不可读来实现安全性的技术和科学称为密码术 。 这就是整篇文章的内容。

The technique to decode an unreadable code to readable again without knowing how they were initially converted from readable to unreadable is Cryptanalysis. That’s what we’ll do in our later articles.

密码分析是一种将不可读代码再次解码为可读的技术,而无需知道它们最初是如何从可读转换为不可读的。 这就是我们在以后的文章中要做的。

Thus, Cryptology = Cryptography + Cryptanalysis.

因此, 密码学=密码术+密码分析

Cryptography is used since ages performed by manual techniques but the basic framework has always remained less or more the same, definitely, there were a lot of improvements. While this article is all theory but no need be disheartened we’ll cover them too.

自从使用手动技术执行密码以来,就开始使用密码术,但是基本框架始终或多或少保持不变,当然,已经有了很多改进。 虽然本文只是理论而已,但不必灰心,我们也将介绍它们。

We have two types of text:

我们有两种类型的文本:

  1. Plain (or clear) text: Which is an actual message that both sender and receiver can understand also by anyone else who gets an access to that message.

    纯文本(或纯文本):这是发送者和接收者都可以访问的其他人也可以理解的实际消息。

  2. Cipher text: When any plain text is codified using a suitable scheme and the resulting message is a cipher text.

    密文:使用合适的方案将任何纯文本编码后,得到的消息就是密文。

There are two ways by which we can primarily change plain text to cipher text by Substitution and Transposition.

我们可以通过两种方式主要通过替换换位将纯文本更改为密文。

1)替代技术 (1) Substitution Techniques)

凯撒密码 (Caesar Cipher)

This Scheme was first proposed by Julius Caesar, cryptography is used since that time.

该方案最初由Julius Caesar提出,从那时开始使用加密技术。

In this Substitution cipher technique, each character of the plaintext message will be replaced by another character, symbol or number.

在这种替换密码技术中,纯文本消息的每个字符将被另一个字符,符号或数字代替。

Caesar cipher is another example of a substitution cipher where it replaces each alphabet from the message to an alphabet 3 places down the line.

凯撒密码是替换密码的另一个示例,其中它将消息中的每个字母替换为下一行的3个字母。

Python编码 (Python Encoding)

string = input("Enter a string\n")
string= str.upper(string)
for x in string:
if(x==' '):
print(' ',end='')
elif(ord(x)-ord('A')+3 >= 26 ):
print(chr(ord(x)-26+3), end='')
else:
print (chr(ord(x)+3), end='')

Python解码 (Python Decoding)

string = input('Enter Decode text: ')
string = str.upper(string)
for x in string:
if(x==' '):
print(' ',end='')
elif(ord(x)-ord('A')-3<0):
print(chr(ord(x)-3+26), end='')
else:
print(chr(ord(x)-3), end='')

Just to make an attacker’s life more difficult we generalized the Caesar Cipher by not necessarily change original alphabet by a third place down the line but instead it can be any place down the line.

只是为了使攻击者的生活更加困难,我们对Caesar Cipher进行了概括,其方式不一定是将原始字母下移第三位,而是可以将其下移到任何位置。

.minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } } .minHeight{ min-height: 250px; } @media (min-width: 1025px){ .minHeight{ min-height: 90px; } }

凯撒密码的修改版 (Modified Version of Caesar Cipher )

Just to make an attacker’s life more difficult we generalized the Caesar Cipher by not necessarily change original alphabet by a third place down the line but instead it can be any place down the line.

只是为了使攻击者的生活更加困难,我们对Caesar Cipher进行了概括,其方式不一定是将原始字母下移第三位,而是可以将其下移到任何位置。

In modified Version, and alphabet can be changed with any other alphabet but once the replacement scheme is decided then it would be constant and will use for all other alphabets in that message.

在修改后的版本中,字母可以与任何其他字母一起更改,但是一旦决定了替换方案,它将保持不变,并将用于该消息中的所有其他字母。

Since English has 26 alphabets then there are 25 possible replacement schemes (replacement of an alphabet with itself is senseless).

由于英语有26个字母,因此有25种可能的替换方案(用自身替换字母是没有意义的)。

Example:

例:

RWLUDMNQNUY RB JFNBXVN

RWLUDMNQNUY RB JFNBXVN

To change above Cipher Text into the plain text we need to use brute-force (trying all available options) thus we got 25 results.

要将上方的密文更改为纯文本,我们需要使用蛮力(尝试所有可用的选项),因此我们得到了25个结果。

    1. QVKTCLMPMTX QA IEMAWUM
2.  PUJSBKLOLSW PZ HDLZVTL
3.  OTIRAJKNKRV OY GCKYUSK
4.  NSHQZIJMJQU NX FBJXTRJ
5.  MRGPYHILIPT MW EAIWSQI
6.  LQFOXGHKHOS LV DZHVRPH
7.  KPENWFGJGNR KU CYGUQOG
8.  JODMVEFIFMQ JT BXFTPNF
9. INCLUDEHELP IS AWESOME
10. HMBKTCDGDKO HR ZVDRNLD
11. GLAJSBCFCJN GQ YUCQMKC
12. FKZIRABEBIM FP XTBPLJB
13. EJYHQZADAHL EO WSAOKIA
14. DIXGPYZCZGK DN VRZNJHZ
15. CHWFOXYBYFJ CM UQYMIGY
16. BGVENWXAXEI BL TPXLHFX
17. AFUDMVWZWDH AK SOWKGEW
18. ZETCLUVYVCG ZJ RNVJFDV
19. YDSBKTUXUBF YI QMUIECU
20. XCRAJSTWTAE XH PLTHDBT
21. WBQZIRSVSZD WG OKSGCAS
22. VAPYHQRURYC VF NJRFBZR
23. UZOXGPQTQXB UE MIQEAYQ
24. TYNWFOPSPWA TD LHPDZXP
25. SXMVENOROVZ SC KGOCYWO

Here we tried all possible outcomes and the 9th one was our message.

在这里,我们尝试了所有可能的结果和 9一个是我们的消息。

凯撒编码的修改版 (A modified version of Caesar Encoding)

string = input('Enter Input: ')
key = int(input('Enter a KEY (1-25): '))
string= str.upper(string)
for x in string:
if(x==' '):
print(' ',end='')
elif(ord(x)-ord('A')+key >= 26 ):
print(chr(ord(x)-26+key), end='')
else:
print (chr(ord(x)+key), end='')

凯撒解码的修改版本 (A modified version of Caesar Decoding)

string = input('Enter Decode text: ')
string = str.upper(string)
for key in range(1,26):
for x in string:
if(x==' '):
print(' ',end='')
elif(ord(x)-ord('A')-key<0):
print(chr(ord(x)-key+26), end='')
else:
print(chr(ord(x)-key), end='')
print(' ')

翻译自: https://www.includehelp.com/cryptography/cryptography-caesar-cipher-and-its-python-implementations.aspx

python凯撒密码实现

python凯撒密码实现_密码:凯撒密码及其Python实现相关推荐

  1. python配置文件密码管理_用户配置文件和密码配置文件,用户组管理和用户管理...

    1 用户配置文件 /etc/passwd 是用户配置文件,每创建一个用户,该配置文件相应增加一行. [root@localhost ~]# cat /etc/passwd root:x:0:0:roo ...

  2. mac忘了密码怎么办_如果忘记Mac密码该怎么办

    mac忘了密码怎么办 Can't remember your Mac's password? Don't worry. With the default settings, you can simpl ...

  3. python链接mysql系统结构设计_第11章:使用Python打造MySQL专家系统

    1.Python语言高级特性 1).深入浅出Python生成器 1).生成器函数:与普通函数定义类似,使用yield语句而不是return语句返回结果.yield语句一次返回一个结果,在每个结果中间挂 ...

  4. python创建类统计属性_轻松创建统计数据的Python包

    python创建类统计属性 介绍 (Introduction) Sometimes you may need a distribution figure for your slide or class ...

  5. python就业需要的技能_教你如何快速掌握Python就业技能

    -人生苦短,为什么要学Python? 简单易学 应用广泛 大厂青睐 (油管大神评选的2020最值得学就业语言-Python) 因为以上的种种理由,无论是国外还是国内, Python都荣登2020最值得 ...

  6. python怎么复数乘方开方_运维必须掌握的 Python 宝典:值得每天复习一遍

    前言 本文旨在更好地总结 Python 基础知识,力求简明扼要,以供实战演练时能够快速查询遗忘的知识点. 学一门语言贵在坚持用它,不用就淡忘了,而记录下一篇文章也有助于日后快速回忆.全文分为两大部分, ...

  7. python人生的不同阶段_从入门到入土的Python自学教程,用改变你的人生轨迹

    Python在近几年越来越受追捧,很多童鞋或者职场小伙伴想要提升技能-学习Python. 这是非常好的事情,但问题在于很多人不知道学Python做什么,所以什么零碎细末.艰难晦涩.长篇大论的都去看,很 ...

  8. 学会python怎么赚钱 贴吧_我月薪5000,靠Python搞副业月入3万

    被压垮的打工人,你还好吗? 房贷车贷,上老下小,日常开销, 但你的收入有多少??? 所以你不敢生病,甚至不敢回家! 就为了每个月那么点死工资,还得天天加班. 然而忙忙忙,却变成了"穷忙族&q ...

  9. python循环输入若干成绩_完美解决在oj中Python的循环输入问题

    完美解决在oj中Python的循环输入问题 这几天做题被python的循环输入问题给烦死了,好好查了一下,记录在此. while True: t= sys.stdin.readline().strip ...

  10. 做python项目需要知道什么_一文带你了解python是什么?能做什么?为什么要学?(文末附学习资源)...

    什么是 Python? Python 是一门流行的编程语言.它由 Guido van Rossum 创建,于 1991 年发布. 它用于:1.Web 开发(服务器端) 2.软件开发 3.数学 4.系统 ...

最新文章

  1. 108.将有序数组转换为二叉搜索树
  2. 工作中发现的相对布局中的一个小技巧
  3. mysql的索引的作用_数据库索引的作用,优点和缺点
  4. Git笔记(23) 不同角色的贡献
  5. open一个绝对路径地址 python_实例15:用Python批量转换doc文件为docx文件
  6. 鸿蒙os 2.0跑分,预装鸿蒙 OS 2.0!华为 MatePad Pro2 跑分曝光:麒麟 9000、8GB 内存
  7. Linux module 添加到bashrc 和临时ifort编译器 以及python2和3的配置
  8. 用turtle实现动态汉诺塔
  9. Amoeba Architecture
  10. 海康VisionMaster算法平台介绍
  11. 计算机页面的工具,魔兽窗口化工具
  12. 机器学习模型的保存与调用
  13. kubernetes面试题汇总
  14. 码农十分钟的音律概述 纯律 五度相生律 十二平均律
  15. c语言数组文曲星猜数游戏编程,关于文曲星上猜数字游戏的c编程方法
  16. CentOS 7 安装osquery监控系统
  17. 用于自然语言理解的多任务深度神经网络
  18. Stata: 面板 Granger 因果检验
  19. 记一次线上报错{“exception“:“Illegal pattern component: XXX}
  20. python数据分析及可视化

热门文章

  1. linux /proc 详解
  2. linux串口缓冲区的大小,linux-----------串口设置缓冲器的大小
  3. react同步请求_React中setState同步更新策略
  4. pythonsql注入_python使用mysql,sql注入问题
  5. 东北大学c语言及程序设计,东大20秋学期《C语言及程序设计》在线平时作业1参考...
  6. vue 怎么全局到入常量_Vue 中如何定义全局的变量和常量(转)
  7. scala通过JDBC进行数据库操作
  8. 华尔街顶级大师胡立阳名言
  9. 算法导论2nd 10.1-7
  10. 关于JAVA中的synchronized,一段不错的解释...