Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.3 kB
5
Indexable
Never
#!/usr/bin/env python3
from Crypto.Util.number import long_to_bytes
from PohligHellman import PohligHellmanModP

# Helper functions
def xor(byte_str1, byte_str2):
    if len(byte_str1) != len(byte_str2):
        raise ValueError("Byte strings must have the same length")
    result = bytes([a ^ b for a, b in zip(byte_str1, byte_str2)])
    return result

def Flag_DECRYPT(FLAG, key):
    secret = xor(FLAG, long_to_bytes(key)[:len(FLAG)])
    return secret

# These never change
HEX_g = "0x9548eb32699a51b9f708d15a0ba3f1632d40e040731599cab3a69c5ca92a144633358c19519ec6b9dbb6226ceadc0d6a438d8e96de50387879c0b24aee457eea4a8ecf79c07d72ec95e97df070dc1426110eab2d777f7e97c66f57c15d58dd999561e4946a2a8321af05f0ed1d622f19eac4785700cd4e793316c58baeceb88e"
HEX_p = "0xa74b335873bfa02db1dbb49115d7d94eaf2fd3ba782544784a47920a50059ad21d9849f027c8c1c28d79b39576eb0b1eb8821824c9e299408907cbecddbf611db2ee74b2ddbd2cbd51b926a7ec627e29b162f5f6a8586610c2227c62ee5c9c956588ca4619ed8f3563631b12a0248e780315313cca10df176ca4ffe6240ed47b"


# Step 1: Input these values
Intercepted_A = "" # --------------------------FILL_THIS_VALUE--------------------------
Intercepted_B = "" # --------------------------FILL_THIS_VALUE--------------------------
Intercepted_Ciphertext = "" # --------------------------FILL_THIS_VALUE--------------------------

A = int(Intercepted_A, 16)
B = int(Intercepted_B, 16)
g = int(HEX_g, 16)
p = int(HEX_p, 16)
FLAG_CIPHER = int(Intercepted_Ciphertext, 16)


# Step 2: The program will ask for params p, g, A. Input these:
p_new = 114716744356612507316999045073389402599012283426882872392666560252284100596201560071080830222643699372385269439917392589041247779556195089353359758632946162211384376815413307543570672045801277356134099000536952854616020444289608445375698297697384692351561673510412909169796876353107904350336995341216652157727
g_new = 2
A_new = 1 # A value doesn't matter.

# Step 3: You will receive a value named 'Here is my public key stranger'. Input it below:
PUBLIC_KEY = "" # --------------------------FILL_THIS_VALUE--------------------------
NEW_B = int(PUBLIC_KEY, 16)

BOB_PRIV = PohligHellmanModP(NEW_B, g_new, p_new) 
shared = pow(A, BOB_PRIV, p)

print(Flag_DECRYPT(long_to_bytes(FLAG_CIPHER), shared))
print(Flag_DECRYPT(long_to_bytes(FLAG_CIPHER), shared).decode())
Leave a Comment