current position：Home>Implementation of Morse cipher translator using Python program
Implementation of Morse cipher translator using Python program
2022-02-01 18:09:39 【aikutwo】
Morse code is a text message as a series of on-off tones 、 Method of light or click transmission , No special equipment required , A familiar little partner can translate directly . It was invented by the telegraph Samuel F. B. Morse Name of .
The algorithm is very simple . Every character in English is a series of “ spot ” and “ Dashes ” Instead of , Or sometimes just singular “ spot ” or “ Dashes ”, vice versa .
1. In the case of encryption , We extract each character from the word one at a time （ If it's not a space ）, And match it with the corresponding Morse password stored in any data structure we choose （ If you use python code , Dictionaries can become very useful in this case ）
2. Store the Morse password in a variable , This variable will contain the string we encoded , Then we add a space to the string containing the result .
3. When encoding with Morse code , We need to add... Between each character 1 A space , Add... Between each word 2 Consecutive spaces .
4. If the character is a space , Add another space to the variable containing the result . We repeat the process , Until we traverse the entire string
1. In the case of decryption , We first add a space at the end of the string to be decoded （ This will be explained later ）.
2. Now let's continue to extract characters from the string , Until we don't have any space .
3. Once we get a space , We will extract the character sequence （ Or our Morse code ） Find the corresponding English characters in , And add it to the variable that will store the result .
4. please remember , Trace space is the most important part of this decryption process . Once we get 2 Consecutive spaces , We will add another space to the variable containing the decoded string .
5. The last space at the end of the string will help us identify the last sequence of Morse code characters （ Because spaces act as checks to extract characters and start decoding them ）.
Python Provides a data structure called a dictionary , It stores information in the form of key value pairs , This is very convenient for implementing passwords such as Morse code . We can save the Morse code table in the dictionary , among （ Key value pair ）=>（ English characters - Morse code ） . Plaintext （ English characters ） Replace the key , Ciphertext （ Morse code ） Form the value of the corresponding key . The value of the key can be accessed from the dictionary , Just as we access the value of an array through an index , vice versa .
Morse code comparison table
Students interested in learning more new programming skills Video link Keep learning ~
The above is the whole content of this article , You can learn more about programming and Morse code through this program , Welcome everyone to actively interact and exchange , Learn together and make progress together ~
author[aikutwo],Please bring the original link to reprint, thank you.
The sidebar is recommended
- Python learning notes - the fifth bullet * class & object oriented
- Python learning notes - the fourth bullet IO operation
- Python crawler actual combat: crawl all the pictures in the answer
- Quick reference manual of common regular expressions, necessary for Python text processing
- [Python] the characteristics of dictionaries and collections and the hash table behind them
- Python crawler - fund information storage
- Python crawler actual combat, pyteseract module, python realizes the visualization of boos direct employment & hook post data
- Pit filling summary: Python memory leak troubleshooting tips
- Python code reading (Chapter 61): delaying function calls
- Through the for loop, compare the differences between Python and Ruby Programming ideas
guess what you like
leetcode 1606. Find Servers That Handled Most Number of Requests（python）
leetcode 1611. Minimum One Bit Operations to Make Integers Zero（python）
06python learning notes - reading external text data
[Python] functions, higher-order functions, anonymous functions and function attributes
Python Networkx practice social network visualization
Data analysis starts from scratch, and pandas reads and writes CSV data
Python review (format string)
[pandas learning notes 01] powerful tool set for analyzing structured data
leetcode 147. Insertion Sort List（python）
apache2. 4 + windows deployment Django (multi site)
- Python data analysis - linear regression selection fund
- How to make a python SDK and upload and download private servers
- Python from 0 to 1 (day 20) - basic concepts of Python dictionary
- Django -- closure decorator regular expression
- Implementation of home page and back end of Vue + Django tourism network project
- Easy to use scaffold in Python
- [Python actual combat sharing] I wrote a GIF generation tool, which is really TM simple (Douluo continent, did you see it?)
- [Python] function decorators and common decorators
- Explain the python streamlit framework in detail, which is used to build a beautiful data visualization web app, and practice making a garbage classification app
- Construction of the first Django project
- Python crawler actual combat, pyecharts module, python realizes the visualization of river review data
- Python series -- web crawler
- Plotly + pandas + sklearn: shoot the first shot of kaggle
- How to learn Python systematically?
- Analysis on several implementations of Python crawler data De duplication
- leetcode 1616. Split Two Strings to Make Palindrome （python）
- Python Matplotlib drawing violin diagram
- Python crawls a large number of beautiful pictures with 10 lines of code
- [tool] integrated use of firebase push function in Python project
- How to use Python to statistically analyze access logs?
- How IOS developers learn Python Programming 22 - Supplement 1
- Python can meet any API you need
- Python 3 process control statement
- The 20th of 120 Python crawlers, 1637. All the way business opportunity network joined in data collection
- Datetime of pandas time series preamble
- How to send payslips in Python
- [Python] closure and scope
- Application of Python Matplotlib color
- leetcode 1627. Graph Connectivity With Threshold （python）
- Python thread 08 uses queues to transform the transfer scenario
- Python: simple single player strange game (text)
- Daily python, chapter 27, Django template
- TCP / UDP communication based on Python socket
- Use of pandas timestamp index
- leetcode 148. Sort List（python）
- Confucius old book network data collection, take one anti three learning crawler, python crawler 120 cases, the 21st case
- [HTB] cap (datagram analysis, setuid capability: Python)
- How IOS developers learn Python Programming 23 - Supplement 2
- How to automatically identify n + 1 queries in Django applications (2)?
- Data analysis starts from scratch. Pandas reads HTML pages + data processing and analysis