0% found this document useful (0 votes)
2 views3 pages

Pqs

The document contains a Python script that processes hexadecimal signatures and computes a new signature using SHA-256 hashing. It defines functions for digesting digits from hexadecimal messages, cleaning input, and performing hashing operations. The script takes two signature inputs, processes them, and outputs a new hexadecimal signature based on predefined constants and calculations.

Uploaded by

gimdubu9
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Pqs

The document contains a Python script that processes hexadecimal signatures and computes a new signature using SHA-256 hashing. It defines functions for digesting digits from hexadecimal messages, cleaning input, and performing hashing operations. The script takes two signature inputs, processes them, and outputs a new hexadecimal signature based on predefined constants and calculations.

Uploaded by

gimdubu9
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

pqs

import hashlib, re

W,N,T = 256,32,2
CHAIN_COUNT = N+T
CHUNK=32
SIG_HEX_LEN = CHAIN_COUNT*CHUNK*2 # 2176

M1_HEX="03f8cb7d2ea8c46ef36a8e5c44a6d1b0"
M2_HEX="2504218a7549e2928170e584e0e8b4c6"
M3_HEX="645906c8947cc6ad182e7f14d0027ee5000000000000b89a"

def sha256n(x: bytes, n: int) -> bytes:


for _ in range(n):
x = hashlib.sha256(x).digest()
return x

def digest_digits(msg_hex: str):


m = hashlib.sha256([Link](msg_hex)).digest()
digits = list(m)
cs = sum((W-1-d) for d in digits)
for _ in range(T):
[Link](cs % W); cs//=W
return digits

def clean_hex_take_exact(s: str, n: int) -> str:


# 문자열에서 만 모아서 정확히 자리만 반환
hex n
only = [Link](r'[^0-9a-fA-F]', '', s)
if len(only) < n:
가 자보다 짧음: {len(only)}")
raise SystemExit(f"hex {n}
return only[:n]

if __name__ == "__main__":
sig1_raw = input("paste sig1 line/output here:\n")
sig2_raw = input("paste sig2 line/output here:\n")

pqs 1
sig1_hex = clean_hex_take_exact(sig1_raw, SIG_HEX_LEN)
sig2_hex = clean_hex_take_exact(sig2_raw, SIG_HEX_LEN)

sig1 = [Link](sig1_hex)
sig2 = [Link](sig2_hex)

d1 = digest_digits(M1_HEX)
d2 = digest_digits(M2_HEX)
d3 = digest_digits(M3_HEX)

out = bytearray()
for i in range(CHAIN_COUNT):
c1 = sig1[i*CHUNK:(i+1)*CHUNK]
c2 = sig2[i*CHUNK:(i+1)*CHUNK]
a1,a2,b = d1[i],d2[i],d3[i]
if a1>=b:
[Link](sha256n(c1, a1-b))
elif a2>=b:
[Link](sha256n(c2, a2-b))
else:
raise SystemExit(f"chain {i}: no source with a>=b")
print("\n=== sig3 hex ===")
print(bytes(out).hex())

pqs 2
hspace{15398c41921c577a779cfac0e5af4ee1}

pqs 3

You might also like