Create and decrypt Caesar cipher with python

# substitute PLAIN the letter
PLAIN = "EBG KVVV vf n fvzcyr yrggre fhofgvghgvba pvcure gung ercynprf n yrggre jvgu gur yrggre KVVV yrggref nsgre vg va gur nycunorg. EBG KVVV vf na rknzcyr bs gur Pnrfne pvcure, qrirybcrq va napvrag Ebzr. Synt vf SYNTFjmtkOWFNZdjkkNH. Vafreg na haqrefpber vzzrqvngryl nsgre SYNT."

for i in range(26):
    KEY = i
    enc = ""

    for char in list(PLAIN):
        ASCII = ord(char)
        if (ASCII == 32):                   # if ASCII is SPC, make space.
            enc += " "
            continue
        if (122 >= ASCII and ASCII >= 97):  # if ASCII is lower
            num = ASCII - 97
            num = (num + KEY) % 26
            ASCII = num + 97
            enc += chr(ASCII)
        elif (90 >= ASCII and ASCII >= 65): # if ASCII is upper
            num = ASCII - 65
            num = (num + KEY) % 26
            ASCII = num + 65
            enc += chr(ASCII)
        else :                              # if ASCII is symbol
            enc += chr(ASCII)

    print(f"--------- Shifted {i} character ---------")
    print(enc)
    print("")

If you want to use it, copy this code and save it with a suitable name. Don't forget to extend it to ".py" (eg test.py)

Then change the contents of the PLAIN variable at the top of the code to the characters you want to encrypt or decrypt. (Example, PLAIN = "hogehoge")

Save it in that state and execute it.

# python test.py

Then, the character string shifted by 1 to 25 characters will be displayed. (The alphabet is 26 characters in total.)

Recommended Posts

Create and decrypt Caesar cipher with python
Encrypt with Ruby (Rails) and decrypt with Python
Programming with Python and Tkinter
Encryption and decryption with Python
Python and hardware-Using RS232C with Python-
Create 3d gif with python3
python with pyenv and venv
Create a directory with python
Works with Python and R
Create youtube ad auto skip tool with python and OCR
Communicate with FX-5204PS with Python and PyUSB
Robot running with Arduino and python
Install Python 2.7.9 and Python 3.4.x with pip.
Create Awaitable with Python / C API
Neural network with OpenCV 3 and Python 3
AM modulation and demodulation with python
[Python] font family and font with matplotlib
Scraping with Node, Ruby and Python
Caesar cipher (including kanji) in Python
Create folders from '01' to '12' with python
Scraping with Python, Selenium and Chromedriver
Create a virtual environment with Python!
Create an Excel file with Python3
Decrypt files encrypted with OpenSSL with Python 3
JSON encoding and decoding with python
Hadoop introduction and MapReduce with Python
[GUI with Python] PyQt5-Drag and drop-
Reading and writing NetCDF with Python
I played with PyQt5 and Python3
Reading and writing CSV with Python
Multiple integrals with Python and Sympy
Coexistence of Python2 and 3 with CircleCI (1.0)
Easy modeling with Blender and Python
Sugoroku game and addition game with python
FM modulation and demodulation with Python
Create and read messagepacks in Python
Create AtCoder Contest appointments on Google Calendar with Python and GAS
Create a striped illusion with gamma correction for Python3 and openCV3
Create a C ++ and Python execution environment with WSL2 + Docker + VSCode
Create a simple Python development environment with VS Code and Docker
Data pipeline construction with Python and Luigi
Calculate and display standard weight with python
Create a Python function decorator with Class
Create wordcloud from your tweet with python3
Build a blockchain with Python ① Create a class
FM modulation and demodulation with Python Part 3
[Automation] Manipulate mouse and keyboard with Python
Create a dummy image with Python + PIL.
Passwordless authentication with RDS and IAM (Python)
Python installation and package management with pip
Using Python and MeCab with Azure Databricks
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
POST variously with Python and receive with Flask
Quickly create an excel file with Python #python
Capturing images with Pupil, python and OpenCV
Fractal to make and play with Python
A memo with Python2.7 and Python3 on CentOS
Decrypt files encrypted with openssl from python with openssl
Create Python + uWSGI + Nginx environment with Docker
Write a Caesar cipher program in Python