Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 AES 进行对称加密 , 顺便加了个命令行操作(没测试) #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions enc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
from Crypto.Cipher import AES
from PIL import Image
import math
import sys
import os


iv = b'1234567812345678' # iv偏移量,bytes类型

def help():
print("提供 Novel_In_Image 命令的帮助信息。")
print()
print("enc [fileName]")
print()
print("\t fileName - 写出该文件对应的图片。")
def encode(text):
str_len = len(text)
width = math.ceil(str_len**0.5)
Expand All @@ -17,15 +29,22 @@ def encode(text):
else:
x += 1
return im

def AES(text,key)
aes = AES.new(key,AES.MODE_ECB)
en_text = aes.encrypt(text) #AES加密
return en_text.decode("utf-8")
def main(filename: str):
t = bytes(input("请输入Key"), encoding='utf-8')
with open(filename, encoding="utf-8") as f:
all_text = f.read()

all_text = AES(f.read(),t)
im = encode(all_text)
im.save("{}_layout.bmp".format('.'.join(filename.split('.')[:-1])))

if __name__ == '__main__':
main('三体全集.txt')
os.system("color 3e") #背景蓝色 字体黄色(字体挺像我(划掉
if sys.argv[1] == 0:
help()
else:
main(str(sys.argv[1]))

#(index & 0xFF0000) >> 16