
import hashlib

def commit(key, msg):
    m = hashlib.sha256()
    m.update(key)
    m.update(msg)
    return {
        "hash": m.hexdigest(),
        "key": key
    }

def verify(com, key, msg):
    v = hashlib.sha256()
    v.update(key)
    v.update(msg)
    try:
        assert v.hexdigest() == com
        return "Message has been verified"
    except:
        raise

sealed_msg = 'there'

msg = commit('hey', sealed_msg)

public_msg = msg.get('hash')

print(verify(public_msg, msg.get('key'), sealed_msg))

import hashlib

def commit(key, msg):
    m = hashlib.sha256()
    m.update(key)
    m.update(msg)
    return {
        "hash": m.hexdigest(),
        "key": key
    }

def verify(com, key, msg):
    v = hashlib.sha256()
    v.update(key)
    v.update(msg)
    try:
        assert v.hexdigest() == com
        return "Message has been verified"
    except:
        raise

sealed_msg = 'there'

key = hashlib.sha256().hexdigest()

msg = commit(key, sealed_msg)

public_msg = msg.get('hash')

print(verify(public_msg, msg.get('key'), sealed_msg))
Make the key 'more secure'
Make the key 'more secure'

  
  import hashlib
  
  def commit(key, msg):
      m = hashlib.sha256()
      m.update(key)
      m.update(msg)
      return {
          "hash": m.hexdigest(),
          "key": key
      }
  
  def verify(com, key, msg):
      v = hashlib.sha256()
      v.update(key)
      v.update(msg)
      try:
          assert v.hexdigest() == com
          return "Message has been verified"
      except:
          raise
  
  sealed_msg = 'there'
  
+ key = hashlib.sha256().hexdigest()
+ 
- msg = commit('hey', sealed_msg)
+ msg = commit(key, sealed_msg)
  
  public_msg = msg.get('hash')
  
  print(verify(public_msg, msg.get('key'), sealed_msg))
Make the key 'more secure'
## Code Before:

import hashlib

def commit(key, msg):
    m = hashlib.sha256()
    m.update(key)
    m.update(msg)
    return {
        "hash": m.hexdigest(),
        "key": key
    }

def verify(com, key, msg):
    v = hashlib.sha256()
    v.update(key)
    v.update(msg)
    try:
        assert v.hexdigest() == com
        return "Message has been verified"
    except:
        raise

sealed_msg = 'there'

msg = commit('hey', sealed_msg)

public_msg = msg.get('hash')

print(verify(public_msg, msg.get('key'), sealed_msg))
## Instruction:
Make the key 'more secure'
## Code After:

import hashlib

def commit(key, msg):
    m = hashlib.sha256()
    m.update(key)
    m.update(msg)
    return {
        "hash": m.hexdigest(),
        "key": key
    }

def verify(com, key, msg):
    v = hashlib.sha256()
    v.update(key)
    v.update(msg)
    try:
        assert v.hexdigest() == com
        return "Message has been verified"
    except:
        raise

sealed_msg = 'there'

key = hashlib.sha256().hexdigest()

msg = commit(key, sealed_msg)

public_msg = msg.get('hash')

print(verify(public_msg, msg.get('key'), sealed_msg))