#!/usr/bin/env python

from aesmix import mixencrypt, mixdecrypt, t_mixencrypt, t_mixdecrypt, slice


def test_single_thread():
    print("\n\nTest single thread")
    key = b"k" * 16
    iv = b"i" * 16

    plaintext = b"d" * 4096
    print(b"plaintext: " + plaintext[:64] + b" ... " + plaintext[-64:])

    ciphertext = mixencrypt(plaintext, key, iv, to_string=True)
    print(b"ciphertext: " + ciphertext[:64] + b" ... " + ciphertext[-64:])

    decrypted = mixdecrypt(ciphertext, key, iv, to_string=True)
    print(b"decrypted: " + decrypted[:64] + b" ... " + decrypted[-64:])


def test_multi_thread():
    print("\n\nTest multi thread")
    key = b"k" * 16
    iv = b"i" * 16
    threads = 8

    plaintext = b"d" * (2 ** 30)  # 1 GiB
    print(b"plaintext: " + plaintext[:64] + b" ... " + plaintext[-64:])

    ciphertext = t_mixencrypt(plaintext, key, iv, threads, to_string=True)
    print(b"ciphertext: " + ciphertext[:64] + b" ... " + ciphertext[-64:])

    decrypted = t_mixdecrypt(ciphertext, key, iv, threads, to_string=False)
    print(b"decrypted: " + decrypted[:64] + b" ... " + decrypted[-64:])


def test_slice():
    mini_size = 4
    macro_size = 16
    num_macros = 4
    data = b"0123456789ABCDEF" * num_macros
    print("data: %s" % data)
    print("fragments: %s" % slice(data, mini_size, macro_size))


if __name__ == "__main__":
    test_single_thread()
    test_multi_thread()
    test_slice()

@@ -92,17 +92,51 @@
 t, slice
+, mix_and_slice, unslice_and_unmix
 %0A
-
 %0A%0Adef te
@@ -759,18 +759,26 @@
  ** 
-30)  # 1 G
+20) * 128  # 128 M
 iB%0A 
@@ -1164,24 +1164,52 @@
 st_slice():%0A
+    print(%22%5Cn%5CnTest slice%22)%0A
     mini_siz
@@ -1392,16 +1392,460 @@
 ize))%0A%0A%0A
+def test_mix_and_slice():%0A    print(%22%5Cn%5CnTest mix and slice%22)%0A    key = b%22k%22 * 16%0A    iv = b%22i%22 * 16%0A%0A    plaintext = b%22d%22 * (2 ** 20)  # 1 MiB%0A    print(b%22plaintext: %22 + plaintext%5B:64%5D + b%22 ... %22 + plaintext%5B-64:%5D)%0A%0A    fragments = mix_and_slice(plaintext, key, iv)%0A    print(%22num fragments: %25s%22 %25 len(fragments))%0A%0A    decrypted = unslice_and_unmix(fragments, key, iv)%0A    print(b%22decrypted: %22 + decrypted%5B:64%5D + b%22 ... %22 + decrypted%5B-64:%5D)%0A%0A%0A
 if __nam
@@ -1904,32 +1904,32 @@
 _multi_thread()%0A
-
     test_slice()
@@ -1929,8 +1929,33 @@
 slice()%0A
+    test_mix_and_slice()%0A

add mix and slice example