From b3b2f763bf8c7ab12640eca17b7c940793760358 Mon Sep 17 00:00:00 2001 From: sangge <2251250136@qq.com> Date: Fri, 25 Aug 2023 02:47:59 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=98=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crypto/easy_caesar/encrypt.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 crypto/easy_caesar/encrypt.py diff --git a/crypto/easy_caesar/encrypt.py b/crypto/easy_caesar/encrypt.py new file mode 100644 index 0000000..863eaf1 --- /dev/null +++ b/crypto/easy_caesar/encrypt.py @@ -0,0 +1,19 @@ +with open("plain_text.txt") as f: + plain = f.readline() + + +def caesar_encrypt(text, shift = 3): + encrypted_text = "" + for char in text: + if char.isalpha(): + ascii_offset = ord('A') if char.isupper() else ord('a') + encrypted_char = chr((ord(char) - ascii_offset + shift) % 26 + ascii_offset) + encrypted_text += encrypted_char + else: + encrypted_text += char + return encrypted_text + +cipher = caesar_encrypt(plain) + +with open("cipher_text.txt","w") as f: + f.write(cipher) \ No newline at end of file