def test_other_solutions(self): message = decrypt((31175, n), CIPHER) self.assertTrue(message.startswith('h')) self.assertEqual( message, 'h堦堦psⰓ녔녔鸿𗉁wi𒿘ip鸿֧i𑫂𗉁oֵg녔wi𒿘i녔R惊褏_员ֵ儧p堦os儧s堦鸿𘉉)䧍褏堦堦𑫂𒿘s_𑫂g𑫂is堦_pl𑫂i_R惊褏' ) message = decrypt((47751, n), CIPHER) self.assertTrue(message.startswith('h')) self.assertEqual( message, 'h摭摭ps莺莺㢅wi𒎑ip㢅틜io멜g莺wi𒎑i莺R镨貑_멜抱p摭os抱s摭㢅춢)𐀵貑摭摭𒎑s_gis摭_pli_R镨貑' )
def decrypt(self): message = self.txt_encrypt.get("1.0", tk.END) key = self.entry_private_key.get().split(' ') if (key and len(message) > 1): self.render_text(self.txt_decrypt, rsa.decrypt(message, key)) else: self.render_text(self.txt_decrypt, "Error!")
def brute_force(public_key, ciphertext, start_char, start=14000, stop=15000): start_cipher = [ciphertext[0]] _, n = public_key # tested 1313, 99999 # forgot to print what brute_force() returned for i in range(start, stop): if decrypt((i, n), start_cipher) == start_char: #if decrypt((i, n), ciphertext).startswith(start_char): yield i return -1
start: float = time.perf_counter() for i in range(64): #Keys public, private = rsa.generate_new_keys() #Errors error = False #Test for j in range(1, 65): #Encryption-Decryption message = generate_random_word() encrypted = rsa.encrypt(message, public) decrypted = rsa.decrypt(encrypted, private) tests += 1 #Error checking error = (decrypted != message) if (error): break if (error): break #Execution finish: float = time.perf_counter() #Log print(
_, n = public_key # tested 1313, 99999 # forgot to print what brute_force() returned for i in range(start, stop): if decrypt((i, n), start_cipher) == start_char: #if decrypt((i, n), ciphertext).startswith(start_char): yield i return -1 if __name__ == '__main__': CIPHER = [ 84620, 66174, 66174, 5926, 9175, 87925, 54744, 54744, 65916, 79243, 39613, 9932, 70186, 85020, 70186, 5926, 65916, 72060, 70186, 21706, 39613, 11245, 34694, 13934, 54744, 9932, 70186, 85020, 70186, 54744, 81444, 32170, 53121, 81327, 82327, 92023, 34694, 54896, 5926, 66174, 11245, 9175, 54896, 9175, 66174, 65916, 43579, 64029, 34496, 53121, 66174, 66174, 21706, 92023, 85020, 9175, 81327, 21706, 13934, 21706, 70186, 79243, 9175, 66174, 81327, 5926, 74450, 21706, 70186, 79243, 81327, 81444, 32170, 53121 ] n = 100127 # current solutions for pk in [14599, 31175, 47751]: print(pk, '-->', decrypt((pk, n), CIPHER)) for pk in brute_force((29815, n), CIPHER, 'h', 1, 99999): print(pk) print(decrypt((pk, n), CIPHER))
def test_solution(self): message = decrypt((14599, n), CIPHER) self.assertTrue(message.startswith('h')) self.assertEqual(message, PLAINTEXT)
def test_actual(self): # brute force the thing [pk] = list(brute_force((29815, n), CIPHER, 'h')) message = decrypt((pk, n), CIPHER) self.assertTrue(message.startswith('h'))