0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonでシーザー暗号プログラム

0
Last updated at Posted at 2020-11-29

この記事では、Pythonのでメッセージをシーザー暗号に暗号化。
また、シーザー暗号を解読するプログラムを紹介します。
とは言っても、皆さんが知っているようなパパっと2、3行!ではなく、内部の仕組みがわかりやすいように書いてみました。

プログラム本文(Win10で動作確認済み)

シーザー暗号.py
from time import sleep

print("this is a softwear for decoding or coding a code(ascii.ver)")
code_type = input("please select (decoding:d,coding:c)")

counter_C = 0
counter_D = 0
key_counter_C = 0
key_counter_d = 0
# letters = "abcdefghijklmnopqrstuvwxyz"
coded_code = "the code is "
answer = "the messege is "

if code_type == "c":                  
    code_C = input("INPUT STRING(please input a string in big letters):")           
    key_num_C = input("INPUT CODING KEY(please input a coding_key in a big letter):")     
    key_counter_C = ord(key_num_C)-65         
    print(key_counter_C)
    
    while counter_C < len(code_C):            
        coded_code = coded_code + chr(ord(code_C[counter_C])+key_counter_C)
        print(coded_code)
        sleep(0.1)
        counter_C = counter_C + 1
    
    print("CODING COMPLEAT")
    print("CODE:"+coded_code)
    print("this tab will close in 10sec")
    sleep(10)

if code_type == "d":                  
    code_D = input("INPUT CODE:")           
    key_num_D = input("INPUT CODING KEY:")     
    key_counter_D = ord(key_num_D)-65         
    print(key_counter_D)
    
    while counter_D < len(code_D):            
        answer = answer + chr(ord(code_D[counter_D])-key_counter_D)
        print(answer)
        sleep(0.1)
        counter_D = counter_D + 1
    
    print("DECODING COMPLEAT")
    print("MESSEGE:"+answer)
    print("this tab will close in 10sec")
    sleep(10)

※プログラムの余分な箇所はコメントアウトしました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?