当前位置:网站首页>It's the Caesar code. (*‘▽‘*)*
It's the Caesar code. (*‘▽‘*)*
2022-06-13 04:30:00 【VioletWill】
Catalog
introduction
Through the ages , People never stop Access to information And Protection of information ( encryption ). And in history , There is a well-known encryption method ; This encryption method also gave rise to the later encryption methods 、 Development provides a useful reference .“ What is this encryption method ? yes , Caesar code .”
“ that , What is the Caesar code ? How do we understand it ? In this post , Maybe , You'll find out .”
The story
……
Caesar: "V'z fbeel gb urne gung lbh'ir pnhtug n pbyq, Pvpreb."
A few days later.
Cicero: "Nsgre erfg n srj qnlf, V sryy zhpu orggre, abj."
……
After watching the dialogue between Caesar and Cicero , Do you think it's cloudy ? Feeling , Full of the feeling of Martian ……“ That's because Caesar and Cicero encrypted the contents of the letter .”
that , Is there any way we can crack their letter ( although , This is a bit immoral .)?
……
Thought analysis
- The core idea of Caesar's code , yes , According to the alphabet , Change the order of letters , So as to realize the encryption of text .
- Let's start with letters “A” For example .
- We know , The English alphabet has a total of 26 Letters , that , You know , remove “A” after , There is still left 25 Letters .
- such , It will be easy for us to understand —— When will “A” The position of moves to the right 26 When a , We are back to our original position “A”.
- “ reflection , If we only move 13 Who? ?”
- Alphabet “A” To the right 13 position , Find letter “N”( Did you find , Letter “N” And then to the right 13 position , We get the letters “A” What about it ?).
- Naturally , With 13 For the key , We can achieve letters “A” And letters “N” Mutual reference to .
Code implementation
# -*- coding: utf-8 -*-
# Created by Violet. All rights reserved!
#%%
# Call function library .
import time as t
#%%
# Create the alphabet .
Alp = dict()
for y in (65,97): # Unicode In the encoding "A"&"a" The coding .
for x in range(26): # Traverse 26 Letters .
Alp[chr(x + y)] = chr(((x + 13) % 26) + y)
#print(Alp)
#%%
# Import text , encryption / Decrypt .
while True:
Txt = input("Encrypt or decrypt?")
t.sleep(0.3)
print("")
print("".join(Alp.get(txt,txt) for txt in Txt))
t.sleep(0.4)
# continue ?
print("\nPress Q/q to exit. (*'▽'*)*")
t.sleep(0.4)
Ans = input('Que: Shall we continue?')
if Ans in {"Q","q"}:
break
else:
print("")
pass
#%%
# To be continued.Analysis of the code
- ……
- Since you want to encrypt the text / Decrypt , So first of all , We need an alphabet ( For translation ).“ therefore , In encryption / Before decryption , We have to make such an alphabet first .”
- stay “Unicode code ” in ——“A” The code of is “65”;“a” The code of is “97”.
- “chr() function ”: Find the string corresponding to the encoding ;“ord() function ”: Find the encoding corresponding to the string .
- “ reflection , Such a question .”
- The alphabet is used for translation , The format for “A” Express “N”, And so on. . that , What kind of ( Tuples ? list ? aggregate ? Dictionaries ?) To make this alphabet ? Dictionaries !
- “ Teaching a man to fish is better than giving him a fish .” therefore , Understanding of the code that created the alphabet , I hope the readers will come down and think .
- ……
- Alp.get(txt,txt) for txt in Txt It means —— Traverse “Txt character string ” Each of them “txt character ”, use “get() function ” From the alphabet “Alp” Find the corresponding value in , If there is , Return the corresponding value , If not, return to the original “txt” value .
- "".join(Alp.get(txt,txt) for txt in Txt) It means , Connect the translated characters ( As for why there are no spaces in quotation marks , because , There are already spaces in the text you entered , When translating, the blank space is also reserved , therefore , There is no need to add any more space .)
- ……
- When we have to translate many texts , Press again and again “F5 key ” Would it be too much trouble ? trouble .“ therefore , We used one While loop , however , Remember to set the exit path .”
- then , When we try to run the program , Find out , The display speed is a little fast , It's weird ,, that , Let's use “ Time bank time” Come and help us (t.sleep()).
- To be continued.
- ……
Letter
that , What did Caesar and Cicero say ?
……
Caesar: " I'm sorry to hear that you've caught a cold, Cicero."
Cicero: "After rest a few days, I feel much better, now."
……
( Beep warning , It's a bad habit to pry into other people's privacy .)
Write it at the end
- “ Cuddle wood , Born in the end . Platform on the ninth floor , From tired soil . A journey , Begins with a single step .”
- I want to go to the north pole to see the aurora , I want to take a walk in the Sahara desert , I want to dive in the Great Barrier Reef , I want to go to Hawaii , I want to punch in the statue of liberty ……“ You also have many places you want to go ? that , Let's make up our minds to be better .”
边栏推荐
- Interpretation and implementation of proxy mode
- Manage PC startup items
- Lenovo notebook computer uses the insert key. When the mouse becomes a small square, how to solve it
- Applet version update
- [flutter problem Series Chapter 67] the Solution to the problem of Routing cannot be jumped again in in dialog popup Using get plug - in in flutter
- [notes] summarize common horizontal and vertical centering methods
- 重读经典:《End-to-End Object Detection with Transformers》
- 一款开源的Markdown转富文本编辑器的实现原理剖析
- Forgotten fleeting years
- 2022 ICML | Pocket2Mol: Efficient Molecular Sampling Based on 3D Protein Pockets
猜你喜欢

Filter and listener

knife4j aggregation 2.0.9支持路由文档自动刷新

Reread the classic: end to end object detection with transformers

小程序基础入门(黑马学习笔记)

2022 ICLR | CONTRASTIVE LEARNING OF IMAGE- AND STRUCTURE BASED REPRESENTATIONS IN DRUG DISCOVERY

Alipay native components (hotel time selection)

第007天:go语言字符串

VGA display based on de2-115 platform

Principle, composition and functions of sensors of Dajiang UAV flight control system

Unity shader learning 004 shader debugging platform difference third-party debugging tools
随机推荐
7-289 tag count (300 points)
Small program imitating Taobao Jiugong grid sliding effect
120. 三角形最小路径和-动态规划
第007天:go语言字符串
[sword finger offer] interview question 25 Merge two ordered linked lists
Data analysis report
SQL advanced challenge (1 - 5)
Billions of data to determine whether the element exists
Sword finger offer II 022 Entry node of a link in a linked list
Milliards de données pour déterminer si un élément existe
Manage PC startup items
Redis
[kubernetes series] pod chapter actual operation
Redis hyperloglog cardinality statistics algorithm
Filter and listener
The problem that ionic3 cannot automatically install the APK package
建模杂谈系列143 数据处理、分析与决策系统开发的梳理
Introduction to RFM analysis
[notes] summarize common horizontal and vertical centering methods
1-72 convert string to decimal integer