From 0827b14ff2fc64683c540b742d46e4846e2e5c6e Mon Sep 17 00:00:00 2001 From: sangge-redmi <2251250136@qq.com> Date: Mon, 15 Apr 2024 16:54:35 +0800 Subject: [PATCH] add present files --- line_present.py | 23 +++++++++++++++++++++++ mem_present.py | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 line_present.py create mode 100644 mem_present.py diff --git a/line_present.py b/line_present.py new file mode 100644 index 0000000..7c34041 --- /dev/null +++ b/line_present.py @@ -0,0 +1,23 @@ +import CoreAlgorithm as paillier +from line_profiler import profile + +# kernprof -l line_present.py + +@profile +def main(): + Public_Key, Private_Key = paillier.generate_paillier_keypair() # 随机生成1024长的公钥和私钥 + x = 90000.23 + y = 90 + z = 0.5 + x_encrypted = Public_Key.encrypt(x) # 加密后的x + y_encrypted = Public_Key.encrypt(y) # 加密后的y + z_encrypted = Public_Key.encrypt(z) # 加密后的z + t_encrypted = ( + x_encrypted + y_encrypted * 0.5 + ) + + print(f"x + y * 0.5的结果是:{Private_Key.decrypt(t_encrypted)}") # 打印出t + + +if __name__ == "__main__": # 主函数 + main() diff --git a/mem_present.py b/mem_present.py new file mode 100644 index 0000000..12eb22f --- /dev/null +++ b/mem_present.py @@ -0,0 +1,23 @@ +import CoreAlgorithm as paillier +from memory_profiler import profile + +# python -m memory_profiler mem_present.py + +@profile +def main(): + Public_Key, Private_Key = ( + paillier.generate_paillier_keypair() + ) # 随机生成1024长的公钥和私钥 + x = 90000.23 + y = 90 + z = 0.5 + x_encrypted = Public_Key.encrypt(x) # 加密后的x + y_encrypted = Public_Key.encrypt(y) # 加密后的y + z_encrypted = Public_Key.encrypt(z) # 加密后的z + t_encrypted = x_encrypted + y_encrypted * 0.5 + + print(f"x + y * 0.5的结果是:{Private_Key.decrypt(t_encrypted)}") # 打印出t + + +if __name__ == "__main__": # 主函数 + main()