I made a Caesar cryptographic program in Python.

Greeting

Do you know Atsuhiko Nakata's Youtube University? Recently, I got a desire to watch smart videos, I often see it, but among the many videos, about "encryption" There was something that was being taught.

If you haven't seen it yet, I highly recommend it. I enjoyed watching it even though I had no knowledge of cryptography. You can see it from the link below. https://www.youtube.com/watch?v=7dSVR_zuJJs&t=694s

So, in that video, there was a word that really impressed me. so! There was ** "Caesar Cryptography"! It was the word ** w

As far as I can tell, the alphabetical order is shifted by a few minutes to make a sentence. I found out that this is a cryptographic rule.

For example When the word apple is applied to the Caesar code, it becomes "fuuqj".

When I was listening to this story, my brain intuitively thought that it would be difficult to decipher. I was issuing an alert, but for the time being, I am also an engineer.

I was wondering how to do it if I wrote it with this encryption actual program, so I actually made it. It was easier than I expected. .. ..

After doing that, I noticed that the alphabet is There are 27 in total. In other words, there are only 26 patterns that can be used for encryption. There are 52 ways including left and right. I realized that this encryption method is quite low level. .. .. ..

There seems to be a more complicated Caesar encryption method, The cryptographic method that simply shifts the order of the alphabet by N I found it better to stop.

I have never used it, In the future, I will use it for my relatives. w

code

import string


#######################################
#Caesar crypto complex
def decrypt_caesar(encrypt_text, gap=1):
    decrypt_text = ''
    for c in encrypt_text:
        number = string.ascii_lowercase.index(c)
        decrypt_text += string.ascii_lowercase[number - gap]
    return decrypt_text


encrypt_text = 'fuuqj'
for i in range(len(string.ascii_lowercase)):
    text = decrypt_caesar(encrypt_text, i)
    print(text)


#######################################
#Caesar cipher
def encrypt_caesar(decrypt_text, gap=1):
    encrypt_text = ''
    for c in decrypt_text:
        number = string.ascii_lowercase.index(c)
        search_text = string.ascii_lowercase*2
        encrypt_text += search_text[number + gap]
    return encrypt_text


#Caesar cipher
print(encrypt_caesar('apple', 5))

Recommended Posts

I made a Caesar cryptographic program in Python.
I made a payroll program in Python!
I made a prime number generation program in Python
I made a prime number generation program in Python 2
Write a Caesar cipher program in Python
I made a program to check the size of a file in Python
I made a Line-bot using Python!
I made a daemon with Python
When writing a program in Python
I made a simple typing game with tkinter in Python
I made a quick feed reader using feedparser in Python
I tried "a program that removes duplicate statements in Python"
I made a puzzle game (like) with Tkinter in Python
I made a character counter with Python
I made a Hex map with Python
After studying Python3, I made a Slackbot
I created a password tool in Python.
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a neuron simulator with Python
I made a program that solves the spot the difference in seconds
I made a prime number table output program in various languages
I made a program to collect images in tweets that I liked on twitter with Python
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
〇✕ I made a game
A memo that I wrote a quicksort in Python
I made a GUI application with Python + PyQt5
I want to create a window in Python
I tried playing a typing game in Python
I made a Twitter fujoshi blocker with Python ①
A program that removes duplicate statements in Python
[Python] I made a Youtube Downloader with Tkinter.
[Memo] I tried a pivot table in Python
I made a script in python to convert .md files to Scrapbox format
I tried adding a Python3 module in C
[IOS] I made a widget that displays Qiita trends in Pythonista3. [Python]
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made a Python Qiita API wrapper "qiipy"
I made a familiar function that can be used in statistics with Python
I made a module in C language to filter images loaded by Python
In Python, I made a LINE Bot that sends pollen information from location information.
Python program is slow! I want to speed up! In such a case ...
I want to easily implement a timeout in python
I made a Twitter BOT with GAE (python) (with a reference)
Write a super simple molecular dynamics program in python
I made a login / logout process using Python Bottle.
Receive dictionary data from a Python program in AppleScript
I want to write in Python! (2) Let's write a test
I made a net news notification app with Python
I made a VM that runs OpenCV for Python
I made a script to put a snippet in README.md
I tried to implement a pseudo pachislot in Python
I made a Python module to translate comment outs
I made a Python3 environment on Ubuntu with direnv.
I want to randomly sample a file in Python
I want to work with a robot in python.
I made a LINE BOT with Python and Heroku
[Python] I made a classifier for irises [Machine learning]