This commit is contained in:
bluepython508
2024-01-22 10:56:12 +00:00
parent d320a956f8
commit dc42625cf1
20 changed files with 293 additions and 10 deletions

View File

@@ -0,0 +1,17 @@
from hashlib import sha256
from itertools import cycle
import base64
def crypt(msg: bytes, key: str) -> bytes:
key_h = sha256()
key_h.update(key.encode('utf8'))
key = key_h.digest()
return bytes(p ^ k for (p, k) in zip(msg, cycle(key)))
def encrypt(msg: str, key: str) -> str:
return base64.b64encode(crypt(bytes(msg, 'utf8'), key)).decode('utf8')
def decrypt(msg: str, key: str) -> str:
return crypt(base64.b64decode(msg), key).decode('utf8')