This commit is contained in:
JISAUAY committed 2025-10-27 14:32:30 -05:00
commit ec14efb417
7 files changed
+182

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
import hmac
import hashlib
import secrets
# Generate and write shared key
shared_secret: bytes = secrets.token_bytes(16)
with open('k', 'wb') as file:
file.write(shared_secret)
# Take in message and compute hmac
m = input("Message: ").encode()
hmac_object: hmac.HMAC = hmac.new(shared_secret, m, hashlib.sha256)
m_hash = hmac_object.digest()
print(f'HMAC: {m_hash}')
# Write hmac digest and message
with open('mactext', 'wb') as file:
file.write(m + m_hash)
+29
View File
@@ -0,0 +1,29 @@
import hmac
import hashlib
# Import shared secret
with open('k', 'rb') as file:
shared_key = file.read()
# Compute hmac
with open('mactext', 'rb') as file:
data = file.read()
m = data[:18]
m_hash = data[18:]
hmac_oject: hmac.HMAC = hmac.new(shared_key, m, hashlib.sha256)
derived_hmac = hmac_oject.digest()
print(f'Derived HMAC: {hmac_oject.digest()}')
if derived_hmac == m_hash:
print("HMAC matches message")
else:
print("HMAC does not match message")