def kalyna_decrypt(ct_, key): key = BitArray(key.to_bytes(16, sys.byteorder)) key_ = np.uint64(np.array(key.unpack('uintle:64, uintle:64'))) plain = [] for i in range(0, len(ct_), 2): k = Kalyna() k.kalyna_key_expand(key_) if i == len(ct_) - 1: ct_s = np.uint64(np.array([ct_[i], 0x0])) else: ct_s = np.uint64(np.array([ct_[i], ct_[i + 1]])) plain.extend(k.kalyna_decipher(ct_s)) result = bytes(np.uint64(np.array(plain))).decode('utf-8') return result.split(' ')[:4]
def kalyna_encrypt(pt, key): key = BitArray(key.to_bytes(16, sys.byteorder)) key_ = np.uint64(np.array(key.unpack('uintle:64, uintle:64'))) pt = BitArray(bytearray(pt, encoding='utf-8')) fm = ", ".join(['uintle:64'] * (pt.len // 64)) pt_ = np.uint64(np.array(pt.unpack(fm))) cipher = [] for i in range(0, len(pt_), 2): k = Kalyna() k.kalyna_key_expand(key_) if i == len(pt_) - 1: pt_s = np.uint64(np.array([pt_[i], 0x0])) else: pt_s = np.uint64(np.array([pt_[i], pt_[i + 1]])) cipher.extend(k.kalyna_encipher(pt_s)) return cipher