def decrypt(): # 初始化解碼資料 # s = time.time() try: # 嘗試 dict1 = json.loads(request.get_data()) data = dict1['data'] data = eval(data) temp_Um = dict1['Um'] temp_Um = temp_Um[1:-1].split(", ") use_key = hashlib.sha256(dict1['key'].encode('utf-8')).digest() use_key = list(use_key) # 加密Um for i in range(len(temp_Um)): use_key[i] = float(use_key[i]) temp_Um[i] = float(temp_Um[i]) temp_Um[i] -= use_key[i] except: print("has error") pass # print(len(data)) # 開始同步 async_flag = False # 同步旗標 times = 0 # 同步失敗次數 while async_flag is False: Y = [random.random(), random.random(), random.random()] client = Chaos() chck = 0 for i in range(len(temp_Um) - 1, -1, -1): Y = client.runSlave(2, Y, temp_Um[i]) if i == 1: chck = client.createUs(Y) # 判斷有沒有同步 if round(temp_Um[0] + chck, 6): # print(temp_X, Y[0], client.createUs(Y), temp_Um[0] + chck) async_flag = False if times > 12: break times += 1 print(round(temp_Um[0] + chck, 6)) else: async_flag = True # 解密 aes = AEScharp() getData = aes.decrypt(data, Y[0]) # json 檔製作 getData = {'decrypt_text': str(getData), 'flag': str(async_flag)} # e = time.time() # print(e - s) return json.dumps(getData)
def sync_Key(self): async_flag = False # 同步旗標 times = 0 # 同步失敗次數 while async_flag is False: client = Chaos() US = 0 for i in range(len(self.temp_Um) - 1, -1, -1): self.Y = client.runSlave(2, self.Y, self.temp_Um[i]) if i == 1: US = client.createUs(self.Y) # 判斷有沒有同步 if round(self.temp_Um[0] + US, 6): # 計算UK 若是0表示同步 反知 async_flag = False if times > 12: # 嘗試同步最高次數 break times += 1 else: # 同步成功 async_flag = True
def chaos(): # 渾沌模組 # 初始化 準備Um buff sys_chaos = Chaos() global X, Um X = [random.random(), random.random(), random.random()] Um = [] for i in range(32): Um.append(0) Um[0] = sys_chaos.createUm(X) X = sys_chaos.runMaster(0, X) # 進入迴圈開始跑渾沌 while 1: for i in range(31, 0, -1): Um[i] = Um[i - 1] Um[0] = sys_chaos.createUm(X) X = sys_chaos.runMaster(1, X) time.sleep(0.001)
from HENMAP_chaos_model import Chaos from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np A = Chaos() X = [0.12345, 0.23456, 0.34567] last = [] for i in range(2000): X = A.runMaster(i, X) last.append(X) last = np.array(last) ax = plt.subplot(111, projection='3d') ax.scatter(last[:, 0], last[:, 1], last[:, 2], c='y') ax.set_zlabel('X3') ax.set_ylabel('X2') ax.set_xlabel('X1') plt.show()
#import from lib sys.path.append(sys.path[0] + '/mods/') from AESmod import AEScharp from HENMAP_chaos_model import Chaos from flask_cors import CORS from all_mod_main import chaos_decrypt_mod, Do_json, chaos_encrypt_mod # local modules X = [] # 混沌亂數 Y = [] sid_Y = {} send_key = {} Um = 0 sr_chaos = Chaos() pc_flage = 0 app = Flask(__name__, template_folder='./') app.config['SECRET_KEY'] = 'secret!' # CORS(app) socketio = SocketIO(app, path="chaos", pingTimeout=120) # 副程式 def floor(num, t): if num < 0: return str(num)[:3 + t] else: return str(num)[:2 + t]
import asyncio import time import cv2 import numpy as np from AESmod import AEScharp from functools import reduce import struct import multiprocessing as mp from HENMAP_chaos_model import Chaos from numba import jit, autojit import random X = [0.12345, 0.23456, 0.34567] Y = [0.222222, 0.111111, 0.333333] a = Chaos() b = Chaos() aes = AEScharp() # 讀圖 img = cv2.imread('im.png') stringData = img.tostring() def en_cbc(data): global X minx = X _16BitList = [] key = [] en_data = b'' num = 16 #定義每组包含的元素個数