注释都加了,看不懂拖出去突突了

annn
vernuser 8 months ago
parent 533611cf14
commit b6a3c192d3

@ -4,7 +4,11 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="b490c3d2-83ec-4ee0-b2e3-44d7951d4337" name="更改" comment="加了ui" />
<list default="true" id="b490c3d2-83ec-4ee0-b2e3-44d7951d4337" name="更改" comment="加了ui">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/encryption_utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/encryption_utils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ui.py" beforeDir="false" afterPath="$PROJECT_DIR$/ui.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -59,30 +63,30 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;Python.client.executor&quot;: &quot;Run&quot;,
&quot;Python.encryption_utils.executor&quot;: &quot;Run&quot;,
&quot;Python.file_transfer.executor&quot;: &quot;Run&quot;,
&quot;Python.generate_key.executor&quot;: &quot;Run&quot;,
&quot;Python.generate_keys.executor&quot;: &quot;Run&quot;,
&quot;Python.receiver.executor&quot;: &quot;Run&quot;,
&quot;Python.sender.executor&quot;: &quot;Run&quot;,
&quot;Python.server.executor&quot;: &quot;Run&quot;,
&quot;Python.ui.executor&quot;: &quot;Run&quot;,
&quot;Python.utils.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;annn&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/Asus/Desktop/烽台校园实习/交接资料/实验室仿真台攻击脚本/实验室仿真台攻击脚本/仿真台攻击脚本11.22&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Python.client.executor": "Run",
"Python.encryption_utils.executor": "Run",
"Python.file_transfer.executor": "Run",
"Python.generate_key.executor": "Run",
"Python.generate_keys.executor": "Run",
"Python.receiver.executor": "Run",
"Python.sender.executor": "Run",
"Python.server.executor": "Run",
"Python.ui.executor": "Run",
"Python.utils.executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.git.unshallow": "true",
"git-widget-placeholder": "annn",
"last_opened_file_path": "D:/college/大三/应用密码学课设",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"vue.rearranger.settings.migration": "true"
}
}</component>
}]]></component>
<component name="RunManager" selected="Python.ui">
<configuration name="generate_key" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="应用密码学课设" />
@ -235,6 +239,8 @@
<workItem from="1734607228597" duration="4000" />
<workItem from="1734770663055" duration="28000" />
<workItem from="1734779266249" duration="2556000" />
<workItem from="1734782609505" duration="86000" />
<workItem from="1735107821817" duration="149000" />
</task>
<task id="LOCAL-00001" summary="加了互传">
<option name="closed" value="true" />
@ -292,7 +298,23 @@
<option name="project" value="LOCAL" />
<updated>1734782367798</updated>
</task>
<option name="localTasksCounter" value="8" />
<task id="LOCAL-00008" summary="加了ui">
<option name="closed" value="true" />
<created>1734782673140</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1734782673140</updated>
</task>
<task id="LOCAL-00009" summary="加了ui">
<option name="closed" value="true" />
<created>1734782691683</created>
<option name="number" value="00009" />
<option name="presentableId" value="LOCAL-00009" />
<option name="project" value="LOCAL" />
<updated>1734782691683</updated>
</task>
<option name="localTasksCounter" value="10" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">

@ -6,28 +6,35 @@ from Crypto.Hash import SHA256
class AsymmetricEncryption:
def __init__(self):
# 生成2048位的RSA密钥对
self.key_pair = RSA.generate(2048)
def get_public_key(self):
# 返回公钥
return self.key_pair.publickey()
def get_private_key(self):
# 返回私钥
return self.key_pair
def encrypt_with_public_key(self, data, public_key):
# 使用公钥加密数据
cipher_rsa = PKCS1_OAEP.new(public_key)
return cipher_rsa.encrypt(data)
def decrypt_with_private_key(self, encrypted_data):
# 使用私钥解密数据
cipher_rsa = PKCS1_OAEP.new(self.key_pair)
return cipher_rsa.decrypt(encrypted_data)
def sign_data(self, data):
# 对数据进行SHA256哈希然后使用私钥生成签名
h = SHA256.new(data)
signature = pkcs1_15.new(self.key_pair).sign(h)
return signature
def verify_signature(self, data, signature, public_key):
# 对数据进行SHA256哈希然后使用公钥验证签名
h = SHA256.new(data)
try:
pkcs1_15.new(public_key).verify(h, signature)
@ -37,11 +44,13 @@ class AsymmetricEncryption:
class SymmetricEncryption:
def encrypt(self, data, key):
# 使用AES-GCM模式加密数据
cipher_aes = AES.new(key, AES.MODE_GCM)
nonce = cipher_aes.nonce
ciphertext, tag = cipher_aes.encrypt_and_digest(data)
return nonce, ciphertext, tag
def decrypt(self, nonce, ciphertext, tag, key):
# 使用AES-GCM模式解密数据并验证
cipher_aes = AES.new(key, AES.MODE_GCM, nonce=nonce)
return cipher_aes.decrypt_and_verify(ciphertext, tag)

@ -10,7 +10,7 @@ class FileTransferApp:
def __init__(self, root):
self.root = root
self.root.title("文件传输系统")
self.root.geometry("800x900") # 增大窗口尺寸
self.root.geometry("800x900") # 窗口大小
self.root.resizable(False, False) # 禁止调整窗口大小
# 设置窗口背景色
@ -21,7 +21,6 @@ class FileTransferApp:
self.receiver_public_key = load_key('receiver_public.pem')
self.receiver_private_key = load_key('receiver_private.pem')
self.sender_public_key = load_key('sender_public.pem')
# 创建UI
self.create_main_frame()

Loading…
Cancel
Save