Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyDream01 authored Feb 6, 2024
1 parent 5d6d416 commit 12e8b81
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions RSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ def verify_signature(message, signature_bytes, public_key_bytes):
),
hashes.SHA256()
)
print("Signature is valid.")
print("\nSignature is valid.")
return True
except Exception as e:
print("Signature is invalid:", str(e))
print("\nSignature is invalid:", str(e))
return False


Expand Down Expand Up @@ -106,8 +106,8 @@ def start_private_key():
if not (private_key_name== None):
private_key =load_private_key(search_config("private_key_name"))
else:
print("找不到密钥,现在创建密钥")
key_name = input("请输入密钥名称:")
print("Cannot find the key, now create the key")
key_name = input("Please enter the key name:")
private_key = load_private_key(key_name)
save_config("private_key_name", key_name)
return private_key
2 changes: 1 addition & 1 deletion Tearlaments.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from main import *
from main import main


if __name__ == '__main__':
Expand Down
11 changes: 2 additions & 9 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
|| ||| | || |
| ||| | || | | ||
||| ||||| ||| |||| || ||| || || || ||||| |||||| ||||| |||
||| |||||| || || |||||| || || || ||||||||||| |||||| ||| || || | || |
||| || || || || |||||| || || || ||||||||||| || || ||| || || | || |
||| ||||||| || || || || || || || || || ||||||| || || || ||
||| || | ||| || || | ||| || || || || || || || ||||
||| || |||| || || |||| || || || || || || || |||
Expand All @@ -19,13 +19,6 @@
|||| ||| ||||||| ||||| ||||| ||||||| |||||||| |||| ||| |||| |||| ||| |||
|||||||
Version:0.1.5
Version : 0.2.0
"""
tip_list=(["请选择操作:","Please select an action:"],
["1.加密图片","1.Encrypt Images"],
["2.解密图片","2.Decrypt the picture"],
["请输入选项:","Please enter an option:"],
)


30 changes: 18 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def load_img():
if file.endswith(".png") or file.endswith(".jpg") or file.endswith(".jpeg") or file.endswith(".bmp") or file.endswith(".tif"):
img_list.append(file)

print("可选的图片:")
print("\nOptional pictures:")
for n, img in enumerate(img_list):
print(f"{n+1} : {img}")
selection = int(input("请选择要加载的图片:"))
selection = int(input("Please select the image to load:"))
return img_list[selection-1]


Expand All @@ -39,18 +39,18 @@ def load_public_key_name():
if file.endswith("public_key.pem"):
public_key_list.append(file)

print("可选的公钥:")
print("\nOptional public key:")
for n, public_key in enumerate(public_key_list):
print(f"{n+1} : {public_key}")
selection = int(input("请选择要加载的公钥:"))
selection = int(input("Please select the public key to load:"))
return public_key_list[selection-1]


def encode_message2img(private_key, public_key):
image_name = load_img()
encrypted_image = ImageProcessor(image_name)

message = input("请输入要加密的信息:")
message = input("\nPlease enter the information you want to encrypt:\n")
encrypted_message = encrypt_with_public_key(message, public_key)
sign = sign_message(message, private_key)

Expand All @@ -59,6 +59,11 @@ def encode_message2img(private_key, public_key):
binary_message = encode_massage(encrypted_message)
binary_sign = encode_massage(sign)

if binary_ends.size < len(binary_message) + len(binary_sign) + 16 + 64:
print("The image capacity is insufficient. Please select another image")
standing_by()
os._exit(0)

binary_ends = overwrite_binary(binary_ends, binary_message, binary_sign)

encrypted_image.image_encode(binary_ends)
Expand All @@ -76,29 +81,30 @@ def decode_img2message(private_key, public_key):
sign = decode_massage(binary_sign)
decrypted_message = decrypt_with_private_key(encrypted_message, private_key)
verify_signature(decrypted_message, sign, public_key)
print("\nThe encrypted message is:")
print(decrypted_message)


def OptionMenu():
private_key = start_private_key()
print("请选择操作:")
print("1.加密图片")
print("2.解密图片")
option = int(input("请输入选项:"))
print("\nPlease select an action:")
print("1. Encrypt the picture")
print("2. Decrypt the picture")
option = int(input("Please enter options:"))
if option == 1:
public_key_name = load_public_key_name()
public_key = load_public_key(public_key_name)
encode_message2img(private_key, public_key)
print("图片保存在output文件夹")
print("The pictures are saved in the 'output' folder")
elif option == 2:
public_key_name = load_public_key_name()
public_key = load_public_key(public_key_name)
decode_img2message(private_key, public_key)
else:
print("无效的选项")
print("Invalid option")

def standing_by():
input("按下任意键结束程序...")
input("\nPress any key to continue...")

def main():
start_folder_check()
Expand Down
1 change: 1 addition & 0 deletions message.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def decode_massage(binary_ends):
def overwrite_binary(binary_ends, binary_message, binary_sign):
message_length = len(binary_message)
sign_length = len(binary_sign)

binary_message_length = bin(message_length)[2:].zfill(64)
binary_sign_length = bin(sign_length)[2:].zfill(16)

Expand Down

0 comments on commit 12e8b81

Please sign in to comment.