Example #1
0
 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𑫂i𖘺s堦_pl𑫂i𖘺_R惊褏'
     )
     message = decrypt((47751, 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𔨝is摭_pl𔨝i_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!")
Example #3
0
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
Example #4
0
    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(
Example #5
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


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))
Example #6
0
 def test_solution(self):
     message = decrypt((14599, n), CIPHER)
     self.assertTrue(message.startswith('h'))
     self.assertEqual(message, PLAINTEXT)
Example #7
0
 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'))