I made a garbled generator that encodes favorite sentences from UTF-8 to Shift-JIS (cp932) in Python

Thank Hello everyone. It's getting hot lately, I'm also very hot. When it's hot like that, I'm making software that I don't understand, but I'd like to explain it this time as well as understanding such software.

Model you are using

The personal computer is a model called "dynabook R734" from Toshiba.

The specs aren't that high, but it's quite comfortable, and thanks to the SSD, it starts up very quickly.

Environment you are using

I used to use Atom before, but when I changed it to VS Code, it was really easy to use.

code

mojigene.py


import jaconv #Load jaconv
import tkinter as tk #Read tkinter as tk
import pyperclip #Load pyperclip
import sys #Read sys

root = tk.Tk() #Create a window called root
root.title("Chong language encryption system") #Window title
root.geometry("700x200") #Window size
root.resizable(width=False, height=False) #Fixed window size


def btn_click(): #Dedicate your life function when you press the button
    kekka.delete(0, tk.END) #Clean the contents of kekka
    fukugen.delete(0, tk.END) #Clean the contents of fukugen
    moji = txt.get() #To get the contents of txt is defined as moji

    result = moji.encode("utf-8") #UTF to moji-Encoding to 8 is defined as result
    henkan = result.decode("cp932", errors="ignore") 
        #Decoding the characters encoded from result to cp932 is defined as henkan
        #At this time, even if an error occurs, it will be ignored.(errors="ignore")With the argument
        #Here utf decoded by cp932-8 comes out
        #I can not understand

    fukugenhenkan = henkan.encode("cp932") 
    #Encoding the information coming out of henkan to cp932 is defined as fukugenhenkan
    #Say goodbye to letters here

    kekkafukugen = fukugenhenkan.decode("utf-8", errors="ignore")
    #utf the information that came out from fukugenhenkan-Decode to 8 and define this as kekkafukugen
    #This will bring up the visible characters converted by cp932

    kekka.insert(0, henkan) #Substitute the resulting henkan in the kekka textbox
    fukugen.insert(0, kekkafukugen) #Substitute the resulting kekka fukugen in the text box called fukugen
    pyperclip.copy(henkan) #Copy the contents of henkan to the clipboard

def copyfukugen(): #A function that copies the contents of fukugen
    fukugennaiyou = fukugen.get() #To get the contents of fukugen is defined as fukugennaiyou
    pyperclip.copy(fukugennaiyou) #Copy the contents of fukugennaiyou to the clipboard

def fukugensuru():
    fukugen.delete(0, tk.END)
    fukugensurunari = kekka.get()
    fukugensimasu = fukugensurunari.encode("cp932")
    fukugen_dekimasita = fukugensimasu.decode("utf-8", errors="ignore")
    fukugen.insert(0, fukugen_dekimasita)



def clearboxing(): #Function to clean the box
    txt.delete(0, tk.END) #Delete the contents of the txt text box
    kekka.delete(0, tk.END) #Delete the contents of the kekka textbox
    fukugen.delete(0, tk.END) #Delete the contents of the text box called fukugen


def exityamete(): #Don't stop
    sys.exit(0) #Exit the software

label = tk.Label(text="Mysterious language you want to create") #Label label
label.place(x=100, y=40) #label position
txt = tk.Entry(width=50) #label text box"txt"
txt.place(x=230, y=40) #Position of txt

label2 = tk.Label(text="The mysterious language that came out") #Label 2
label2.place(x=100, y=70) #Position of label2
kekka = tk.Entry(width=50) #label2 textbox"kekka"
kekka.place(x=230, y=70) #position of kekka

label3 = tk.Label(text="Restored mysterious language") #Label 3
label3.place(x=100, y=100) #Position of label3
fukugen = tk.Entry(width=50) #label3 textbox"fukguen"
fukugen.place(x=230, y=100) #location of fukugen


btn = tk.Button(root, text='Give your life', command=btn_click) #Button called btn
                                                            #Press btn_click is executed
btn.place(x=0, y=0) #Position of btn

fukugenbutton = tk.Button(root, text="Restore", command=fukugensuru)
fukugenbutton.place(x=0, y=40)

clearbox = tk.Button(root, text="Erase existence", command=clearboxing) #Button called clearbox
                                                                   #Press to execute clear boxing
clearbox.place(x=97, y=0) #position of clearbox

exitbutton = tk.Button(root, text="Don't push", command=exityamete) #A button called exit button
                                                                      #Press to run exityamete
exitbutton.place(x=0, y=160) #Exit button position

fukugencopy = tk.Button(root, text="Restore copy", command=copyfukugen) #Button called fukugencopy
                                                                      #Press to run copyfukugen
fukugencopy.place(x=197, y=0) #Position of fukugencopy

lookeverytimes = tk.Label(root, text="Darkness to privacy without worrying about electromagnetic wave attacks")
lookeverytimes.place(x=230, y=150)

donotalive = tk.Label(root, text="All copyright belongs to King Chong") #Label donota live
donotalive.place(x=250, y=170) #Position of donota live

versions = tk.Label(root, text="ver 1.0.1") #Version notation
versions.place(x=630, y=170) #Position of versions

root.mainloop() #Infinite loop with tkinter, without this, buttons are not displayed even if the window is displayed

Contents

As you can see, ** it's just unilaterally running from top to bottom **. ~~ (I don't understand the text is my hobby) ~~ The definition name is so appropriate that I may not understand it myself, so I will make it more specific the next time I assemble ... Since it is written in the comment out how it works, there is no particular explanation, but if you write one, the tkinter button etc. will not be displayed unless there is ** root.mainloop () ** at the bottom .. If I remember this much, I feel like I don't need it anymore. 〆 Thanks to this, it is useful when garbled long sentences. Only I seem to be in demand for such a program. So, good night.

Quote

https://qiita.com/mocha_xx/items/07465240d4212d946148 https://qiita.com/CyberRex/items/90eb450310f1697d03e9 https://qiita.com/mocha_xx/items/07465240d4212d946148 Thank you very much!!!

Recommended Posts

I made a garbled generator that encodes favorite sentences from UTF-8 to Shift-JIS (cp932) in Python
I made a web application in Python that converts Markdown to HTML
In Python, I made a LINE Bot that sends pollen information from location information.
I made a program to collect images in tweets that I liked on twitter with Python
I tried to make a generator that generates a C # container class from CSV with Python
I made a library that adds docstring to a Python stub file.
I made a payroll program in Python!
I made a plugin to generate Markdown table from csv in Vim
[Python] I made a decorator that doesn't seem to have any use.
I made a Discord bot in Python that translates when it reacts
I tried to develop a Formatter that outputs Python logs in JSON
I made a script in python to convert .md files to Scrapbox format
[IOS] I made a widget that displays Qiita trends in Pythonista3. [Python]
I made a program to check the size of a file in Python
A memo that I wrote a quicksort in Python
I want to create a window in Python
I made a Caesar cryptographic program in Python.
I tried to create a class that can easily serialize Json in Python
I made a Line Bot that uses Python to retrieve unread Gmail emails!
I made a Docker image that can call FBX SDK Python from Node.js
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
A story that I was addicted to when I made SFTP communication with python
I was soberly addicted to calling awscli from a Python 2.7 script registered in crontab
I want to embed a variable in a Python string
I want to easily implement a timeout in python
I made a prime number generation program in Python
I made a library to separate Japanese sentences nicely
[Python] I made a system to introduce "recipes I really want" from the recipe site!
I made a VM that runs OpenCV for Python
I tried to implement a pseudo pachislot in Python
I want to work with a robot in python.
I made a prime number generation program in Python 2
I can't sleep until I build a server !! (Introduction to Python server made in one day)
I made a python library to do rolling rank
A mechanism to call a Ruby method from Python that can be done in 200 lines
I made a program in Python that changes the 1-minute data of FX to an arbitrary time frame (1 hour frame, etc.)
I made a toolsver that spits out OS, Python, modules and tool versions to Markdown
I made a script in Python to convert a text file for JSON (for vscode user snippet)
I made a server with Python socket and ssl and tried to access it from a browser
I also tried to imitate the function monad and State monad with a generator in Python
[Python] I started Poetry & Impression that I moved from Pipenv to poetry
I tried to create API list.csv in Python from swagger.yaml
I tried to implement a one-dimensional cellular automaton in Python
How to slice a block multiple array from a multiple array in Python
Loop through a generator that returns a date iterator in Python
I made a package to filter time series with python
python Condition extraction from a list that I often forget
I want to start a lot of processes from python
I made a quick feed reader using feedparser in Python
I made a command to generate a table comment in Django
I made a tool to create a word cloud from wikipedia
I tried "a program that removes duplicate statements in Python"
I tried "How to get a method decorated in Python"
I want to send a message from Python to LINE Bot
I made a puzzle game (like) with Tkinter in Python
I tried to make a stopwatch using tkinter in python
I want to make input () a nice complement in python
I made you to execute a command from a web browser
I made a neural network generator that runs on FPGA
[Python] Convert Shift_JIS to UTF-8