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.
31 lines
868 B
31 lines
868 B
import hashlib
|
|
import io
|
|
import logging
|
|
|
|
# Size of the buffer to read files with
|
|
BUF_SIZE = 4096
|
|
|
|
LOG = logging.getLogger("acm.utility")
|
|
|
|
|
|
def get_string_sha256sum(content: str, encoding='utf-8') -> str:
|
|
sha256sum = hashlib.sha256()
|
|
with io.BytesIO(content.encode(encoding)) as c:
|
|
for byte_block in iter(lambda: c.read(BUF_SIZE), b''):
|
|
sha256sum.update(byte_block)
|
|
return sha256sum.hexdigest()
|
|
|
|
|
|
def get_string_hex(content: str) -> hex:
|
|
return hex(int(content, base=16))
|
|
|
|
|
|
def get_hex_xor(first: hex, second: hex) -> hex:
|
|
return hex(int(first, base=16) ^ int(second, base=16))
|
|
|
|
|
|
def get_string_xor(first: str, second: str, *extra: str) -> str:
|
|
result = get_hex_xor(get_string_hex(first), get_string_hex(second))
|
|
for next_hex in extra:
|
|
result = get_hex_xor(result, get_string_hex(next_hex))
|
|
return str(result)
|