def check_CP(): data = loadCP() if data['hesh'] == '1': H = SHA.sha256(data['message']) elif data['hesh'] == '2': H = SHA.sha512(data['message']) elif data['hesh'] == '3': H = stibog.Main(data['message'], 256) elif data['hesh'] == '4': H = stibog.Main(data['message'], 512) R_test = (int( fun.obrat(pow(data['U'] * data['L'], data['L'], data['p']), data['p'])) * pow(data['a'], data['S'], data['p'])) % data['p'] kon = data['message'] + str(R_test) + str(data['U']) if data['hesh'] == '1': E_test = SHA.sha256(kon) elif data['hesh'] == '2': E_test = SHA.sha512(kon) elif data['hesh'] == '3': E_test = Stibog.Main(kon, 256) elif data['hesh'] == '4': E_test = Stibog.Main(kon, 512) if data['E'] == E_test: print(True) else: print(False)
def FBI_OPEN_UP(): cp_list = [] with open("ЦП.txt", "r") as prifile: gamma, delta = (prifile.read().split()) with open("Cp_Document.txt", "r") as pubfile: cp_list = pubfile.read().split('\n') hm = cp_list[1] alpha, beta, p = cp_list[3].split() mes = cp_list[13] alpha, beta, p, gamma, delta = int(alpha), int(beta), int(p), int( gamma), int(delta) if PKCS_7[1] == hm: hesh = int(SHA.sha256(mes), base=16) elif PKCS_7[1] == hm: hesh = int(SHA.sha512(mes), base=16) elif PKCS_7[1] == hm: hesh = int(STR.Stribog(mes, 256), base=16) elif PKCS_7[1] == hm: hesh = int(STR.Stribog(mes, 512), base=16) print( pow(beta, gamma, p) * pow(gamma, delta, p) % p, '==', pow(alpha, hesh, p)) if pow(beta, gamma, p) * pow(gamma, delta, p) % p == pow(alpha, hesh, p): print("true") else: print("false")
def hesh_message(message: str, type_hesh: int): if type_hesh == 1: H = SHA.sha256(message) elif type_hesh == 2: H = SHA.sha512(message) elif type_hesh == 3: H = Stribog.Stribog(message, 256) elif type_hesh == 4: H = Stribog.Stribog(message, 512) else: H = '0' return H
def hesh_choose(message, type): if type == '1': H = SHA.sha256(message) return H elif type == '2': H = SHA.sha512(message) return H elif type == '3': H = Stibog.Main(message, 256) return H elif type == '4': H = Stibog.Main(message, 512) return H else: print('Error') return 0
def LEAD_3(p, q, a, R_l: list, M, U, type): T = random.randint(2, q - 1) R_lead = pow(a, T, p) R = 1 for i in range(len(R_l)): R = R * R_l[i] R = R_lead * (R % p) E = M + str(R) + str(U) if type == '1': E = SHA.sha256(E) return E, T # Лидер отправляет каждому пользователю E, лидер T не передаёт, но тут передаёт elif type == '2': E = SHA.sha512(E) return E, T elif type == '3': E = Stibog.Main(E, 256) return E, T elif type == '4': E = Stibog.Main(E, 512) return E, T
def FBI_OPEN_UP(): flag = True PKCS_7 = "" sor = "" while flag: task = input("Pleas enter file with cp with .txt\n>> ") try: with open(task, "r") as cp_file: PKCS_7 = cp_file.read().split("\n") with open("ЦП.txt", "r") as cp_file: sor = cp_file.read() flag = False break except FileNotFoundError: print("cant find file, please try new name write\n") mes = PKCS_7[13] s = int(PKCS_7[10], 16) e = PKCS_7[3].split() n = e[1] e = e[0] if PKCS_7[1] == "SHA256": hm = SHA.sha256(mes) elif PKCS_7[1] == "SHA512": hm = SHA.sha512(mes) elif PKCS_7[1] == "STR256": hm = STR.Stribog(mes, 256) elif PKCS_7[1] == "STR512": hm = STR.Stribog(mes, 512) hmshtrix = pow(s, int(e), int(n)) print("\nResult - " + "None\n" + "Algorithm hash - " + PKCS_7[2] + "\nAlgoritm CP - " + PKCS_7[9] + "\nAuthor - " + PKCS_7[6] + "\nTime create CP - " + PKCS_7[11] + "\n") print("ЦП = " + str(sor)) print("Cp_s = " + str(s)) # print("NC = "+str(hex(int(hmshtrix)))) print("NC = " + str(int(hmshtrix)))
with open("publick.txt", "r") as pub_k: Bi = pub_k.read().split("\n") n = Bi[1] Bi = Bi[0].split() PKCS_7[3] = str(n) except FileNotFoundError: print("Need generate keys. Please, do it and try later\n") break print("\nstart cp\priv") cp = Cp(Bi,n,Ai,mes) PKCS_7[6] = input("Enter you Name and Fname pleas ( Name Fname)\n>> ") SignVal = hex(int(cp)) PKCS_7[10] = SignVal[2:] PKCS_7[11] = date.today() if PKCS_7[1] == "SHA256": PKCS_7[12] = SHA.sha256(mes + cp) elif PKCS_7[1] == "SHA512": PKCS_7[12] = SHA.sha512(mes + cp) elif PKCS_7[1] == "STR256": PKCS_7[12] = STR.Stribog(mes + cp, 256) elif PKCS_7[1] == "STR512": PKCS_7[12] = STR.Stribog(mes + cp, 512) with open("Cp_Document.txt", "w") as doc: for i in PKCS_7: stri = "" stri = stri + str(i) + "\n" doc.write(stri) doc.write(mes) elif point == "4": FBI_OPEN_UP() elif point == "5":