Python Notes: Hex-key-hack

  1. The information presented here is intended for educational use.
  2. The information presented here is provided free of charge, as-is, with no warranty of any kind.
  3. Edit: 2026-11-11

Overview

test-program-1: hard coded

#!/usr/bin/python3
# =================================================
# title  : hex-key-hack-100.py
# author : Neil Rieck
# created: 2026-10-30
# command: ./hex-key-hack-100.py
# purpose: prove that the product of 2 primes (from
#          an OpenSSL display) yield a public key
# =================================================

def hexToInt(h):
    h = h.replace(":", "")
    i = int(h, 16)
    return i

def main():
    hex1 = ("00:dd:6a:f4:62:99:eb:33:a8:d9:1a:33:65:88:dd:"
            "05:6e:2a:b0:90:41:c5:c4:98:e6:b5:7c:4a:f6:a2:"
            "ad:8f:23")
    int1 = hexToInt(hex1)
    print(f"1: {int1}")
    hex2 = ("00:da:ae:3d:8a:06:45:3f:cf:5e:7a:f8:42:12:52:"
            "25:0e:4e:6e:71:99:55:f0:d0:23:b7:6a:4d:66:df:"
            "d9:0d:3f")
    int2 = hexToInt(hex2)
    print(f"2: {int2}")
    hex3 = ("00:bd:23:c8:07:ef:66:8a:6d:c5:43:74:f7:52:19:"
            "66:7f:5f:5b:b4:61:17:ac:32:c8:08:44:7e:85:01:"
            "39:67:0a:6c:20:10:a2:f0:c5:4a:19:82:6d:52:a9:"
            "09:8c:b5:ba:2e:78:d1:ae:57:1e:ef:d1:aa:dc:9c:"
            "b4:aa:a6:00:9d")
    int3 = hexToInt(hex3)
    print(f"3: {int3}")
    int9 = int1 * int2
    print(f"T: {int1 * int2}")
    if int3 == int9:
        print("-i-public key matches computation")
    else:
        print("-e-public key does not match computation")
    print("adios.")
#
#   catch-all
#
if __name__ == '__main__':
    main()
#

test-program-2: soft coded

#!/usr/bin/python3
# =================================================
# title  : hex-key-hack-101.py
# author : Neil Rieck
# created: 2026-11-03
# command: ./hex-key-hack-101.py
# purpose: prove that the product of 2 primes (from
#          an OpenSSL dump) yields a public key
# =================================================
tmp = [0, 0, 0, 0]
label = ["", "prime 1", "prime 2", "public key"]

def hexToNum(line9):
    tmp0 = line9
    tmp1 = tmp0.replace(":", "").replace("\t", "").replace("\n", "")
    tmp2 = int(tmp1, 16)
    return tmp2

def main():
    global tmp
    print("note: the first two items are the smaller primes")
    print("      the third item is the larger public key")
    for i in range(1, 4):
        print(f"item: {i} ({label[i]})")
        line9 = ""
        while True:
            print("enter hex string data (blank line to exit):")
            line1 = input()
            if (line1 != ""):
                line9 += line1
                print("append")
            else:
                break
        tmp[i] = hexToNum(line9)
    for i in range(1, 4):
        print(f"-i-item {i}: {tmp[i]}")
    calc = tmp[1] * tmp[2]
    print(f"-i-calc  : {calc}")
    if tmp[3] == calc:
        print("-i-the test passed (calc = item-3)")
    else:
        print("-e-the test failed (calc <> item-3)")
#
#   catch-all
#
if __name__ == '__main__':
    main()
#
#   adios...
#

External Links


Back to Home
 Neil Rieck
 Waterloo, Ontario, Canada.