Tooling for managing asset compression, storage, and retrieval
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
868 B

  1. import hashlib
  2. import io
  3. import logging
  4. # Size of the buffer to read files with
  5. BUF_SIZE = 4096
  6. LOG = logging.getLogger("acm.utility")
  7. def get_string_sha256sum(content: str, encoding='utf-8') -> str:
  8. sha256sum = hashlib.sha256()
  9. with io.BytesIO(content.encode(encoding)) as c:
  10. for byte_block in iter(lambda: c.read(BUF_SIZE), b''):
  11. sha256sum.update(byte_block)
  12. return sha256sum.hexdigest()
  13. def get_string_hex(content: str) -> hex:
  14. return hex(int(content, base=16))
  15. def get_hex_xor(first: hex, second: hex) -> hex:
  16. return hex(int(first, base=16) ^ int(second, base=16))
  17. def get_string_xor(first: str, second: str, *extra: str) -> str:
  18. result = get_hex_xor(get_string_hex(first), get_string_hex(second))
  19. for next_hex in extra:
  20. result = get_hex_xor(result, get_string_hex(next_hex))
  21. return str(result)