From 4736e0696493dd39b2f679e6aeac5fc7afc2929d Mon Sep 17 00:00:00 2001 From: Abhisek Kumar Jha Date: Fri, 31 May 2024 17:02:42 -0500 Subject: [PATCH] final commit with all the changes --- README.md | 2 +- data/input/E1.bin | Bin 0 -> 4176 bytes data/input/E2.bin | Bin 0 -> 4176 bytes data/input/E3.bin | Bin 0 -> 4176 bytes sample_test.py | 55 --------------- src/__pycache__/decryption.cpython-312.pyc | Bin 770 -> 770 bytes .../key_management.cpython-312.pyc | Bin 871 -> 861 bytes src/key_management.py | 10 +-- tests/test_decryption.py | 63 +++++++++++++---- tests/test_encryption.py | 58 +++++++++------- tests/test_file_utils.py | 0 .../test_key_generation.py | 0 tests/test_key_management.py | 0 tests/test_main.py | 65 ++++++++++++++++++ tests/test_pqc_multipath.py | 52 ++++++++++++++ tests/test_pqcrypto.py | 18 ----- 16 files changed, 204 insertions(+), 119 deletions(-) create mode 100644 data/input/E1.bin create mode 100644 data/input/E2.bin create mode 100644 data/input/E3.bin delete mode 100644 sample_test.py delete mode 100644 tests/test_file_utils.py rename src/key_generation.py => tests/test_key_generation.py (100%) delete mode 100644 tests/test_key_management.py create mode 100644 tests/test_main.py create mode 100644 tests/test_pqc_multipath.py delete mode 100644 tests/test_pqcrypto.py diff --git a/README.md b/README.md index 1cf63c2..926c813 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ source venv/bin/activate 2. Set the PYTHONPATH to include the current directory and the pyky directory: ``` -export PYTHONPATH=$PYTHONPATH:/path/to/pqc_aes_multipath:/path/to/pqc_aes_multipath/pyky +echo $PYTHONPATH /Users/abhisekjha/Multipath_Research/PQC/pqc_aes_multipath:/Users/abhisekjha/Multipath_Research/PQC/pqc_aes_multipath/pyky ``` 3. To Verify PYTHONPATH diff --git a/data/input/E1.bin b/data/input/E1.bin new file mode 100644 index 0000000000000000000000000000000000000000..81e976c2449836ccea80024d4ea6b87ba63ea57e GIT binary patch literal 4176 zcmb`>F>V7<5W`UC{+CYSyoP`%pkk31RmsK?dYk#~{5*!y~R zy^Q)#(Yxqf`Qq~RPw6|$x0m(p?N`2h`=WR4a@k$R`m!DW+Pf?Ju3f*#TXbh{zIr>l zM?JQ0UY;JWJA3K=DSI#XUcboi-d--RJG(piQ@q~2cK@SZGY{<-`HSwK?tFZDSI>P} zubJPznYUQK+1=`|-QDum&M*1p^4iP2m%Gcz!`0g_x<~%X`bGC8zrAcP?HAqEYcH4A zU3b|#&F#Bi`M39c^nPi_|L%Qf<<&p^{&m0h_WfRS{gvB$XZ79d$)!8&F0Xy{z2kiY Dr|1C@ literal 0 HcmV?d00001 diff --git a/data/input/E2.bin b/data/input/E2.bin new file mode 100644 index 0000000000000000000000000000000000000000..3b6952725faa87c91b324cd404a83d8b489b321b GIT binary patch literal 4176 zcmb`>F>V7<5W~>;{+CYm3NsjJZNv>B4fWTrpZDMEJ^o4S-T}Ylt-fBfy&nIo_uiuK zAzv=t%jNan>^*&Rd-p{<wRVWr|f%ndTcM_^4xLlmUr#jdk1^} yHrwI#etZ66cg@}RE??|ke(LkOlP}sW+Vh&*U-x=4+Li8$c0BpwQ_r4{?SBDa00992 literal 0 HcmV?d00001 diff --git a/data/input/E3.bin b/data/input/E3.bin new file mode 100644 index 0000000000000000000000000000000000000000..43c5087633b1cb9da869f3ce2d257ab531521d1d GIT binary patch literal 4176 zcmbu&F-`?R5Cc)T|D_4wB_&xsUu;scT|N8#_4|GQv1l(}^bSwP)!WPe`tH&Da%sP~ z?%H43f9mPc-n{z%dfvsp*UUrvA`f3ZK3;crKI%*RV*Tdc+1oes%6f7=dF`w3-K*zr zvF|jy)0g&(?v`iAdawQRyw_bu9_mq#deoP8v^VR^<*nYmy|kB?*IoYfoy+$w@@3SQ z_KWW7>G5^vm+sqtn){B7-fLccy=Hgiryd{Id-hlM9eLfq?!3kI{_4GBf6evWFY=MM z@@wxMTz7V?r$;;LQIGBAl3()l&F$^w^7M<|>E2#0dw1pD%kG->7u_LWzQ|v6f9>^T zbT60olGk3gm-a>e+V#uRkO^S+^QE?R3|Glt&L+7Jy4@Ur@KX%x!yt#dh*LCM`CQz9PZN sa?G+i!ayd-;9@Bt@qw909Nol5C8xG delta 300 zcmcc1_MDCPG%qg~0}%KLhNWGY$Q!7`o1K~)pPgEno|N2;=1s0Xbl1%Glg@B^mAZY=( zwDbiv>&x6W7g%g2KVj1H2N_TVQdR^q2J9@bb-y@la`RJ4b5iY!M1T^EKwK;ZBt9@R dGBVz0aK6ak{E3B$QTh`H6Qk;9AYlvE3joPjPj3JK diff --git a/src/key_management.py b/src/key_management.py index 58ebf78..d81906f 100644 --- a/src/key_management.py +++ b/src/key_management.py @@ -1,13 +1,13 @@ -from pyky.ccakem import kem_keygen512, kem_encaps512, kem_decaps512 +from pyky.ccakem import kem_keygen1024, kem_encaps1024, kem_decaps1024 def generate_kyber_keypair(): """Generate a Kyber key pair.""" - return kem_keygen512() + return kem_keygen1024() -def encrypt_session_key(public_key, session_key): +def encrypt_session_key(public_key): """Encrypt a session key using Kyber.""" - return kem_encaps512(public_key) + return kem_encaps1024(public_key) def decrypt_session_key(private_key, encrypted_session_key): """Decrypt a session key using Kyber.""" - return kem_decaps512(private_key, encrypted_session_key) + return kem_decaps1024(private_key, encrypted_session_key) diff --git a/tests/test_decryption.py b/tests/test_decryption.py index b65d554..f33fdbd 100644 --- a/tests/test_decryption.py +++ b/tests/test_decryption.py @@ -1,19 +1,52 @@ -#Test case for decryption.py -import os -import unittest +import time +from tqdm import tqdm +from Crypto.Cipher import AES +from Crypto.Util.Padding import pad, unpad +from pyky.ccakem import kem_keygen1024, kem_encaps1024, kem_decaps1024 +from src.encryption import generate_aes_key, aes_encrypt from src.decryption import aes_decrypt -class TestDecryption(unittest.TestCase): - def test_aes_decrypt(self): - # Arrange - message= b'Hello, World!' - encrypted_message = b'\x' - session_key = os.urandom(32) - # Act +def generate_kyber_keypair(): + """Generate a Kyber key pair.""" + return kem_keygen1024() - decrypted_message = aes_decrypt(encrypted_message, session_key) - # Assert - self.assertEqual(decrypted_message, message) +# Convert list of signed integers to bytes +def convert_to_bytes(signed_int_list): + return bytes([x & 0xFF for x in signed_int_list]) -if __name__ == '__main__': - unittest.main() \ No newline at end of file +def loading_message(message, duration=0.1): + """Simulate a loading process with a message and duration.""" + print(message) + for _ in tqdm(range(100), desc=message, ncols=100, ascii=True, bar_format='{l_bar}{bar} | {percentage:3.0f}%'): + time.sleep(duration / 100) + print() + +def test_decryption(): + # Generaate Kyber key pair + loading_message("Getting key pair...", duration=0.1) + + message= b'Hello, this is a test message!' + encrypted_message= b'\xea\x91,\xac@\xc1,{EB\x02*\xfb>\x97\xae\x97O\xe5^{@\x87\r\xc8}7Z\xa2p\x9eEz\xd1\x14.\xf8\xaa\xf2\x01**\xb7k&\xa9Z\xb5' + priv_key = [-58, -4, -86, 73, -7, -121, -127, -71, 34, -40, -25, 29, -73, 117, -120, 108, 75, -111, -37, -78, -109, -110, -86, -120, 29, -7, -62, 103, 80, 46, 72, -27, -78, 53, -63, -76, 73, -101, 62, -72, -105, 124, -64, -31, 79, 123, 7, -100, 45, -42, 127, -65, -92, 74, -117, -11, -96, -58, 122, 6, 108, 23, 21, -53, -118, 66, -56, -112, 56, 41, -4, -82, -26, -47, -72, -109, 28, -53, 30, 80, -105, 106, 24, 64, 3, 80, 92, 4, 1, -102, 40, 54, 19, -51, 18, 19, 74, -13, -82, -125, -41, 58, -111, -56, 56, 94, 115, 20, 122, 4, 67, -95, -96, 4, 99, -73, 41, 5, 41, 65, 44, 66, -95, -23, 50, 95, -2, -119, -64, -103, 81, 114, 14, 60, 94, -83, 2, -77, 23, -64, 55, 80, -5, 74, 26, -71, 29, -26, 51, 99, 86, -37, -107, -120, 52, -80, 94, 35, 11, 126, -76, 105, 73, -122, 75, 26, 113, -49, 98, 55, 68, -43, -91, -67, 114, 7, 13, 32, -104, 27, -79, -71, 100, 56, -59, 112, -17, -74, 59, -4, 66, 79, 20, 91, 79, -89, -40, 29, 107, 122, 11, 91, 66, 35, -32, 9, 105, -24, 17, 118, 78, -80, -79, -60, 20, -94, -12, -120, -98, -64, -91, -113, 72, -70, 0, 114, -62, 0, 34, -112, 21, -22, 69, 119, 17, -126, 86, -121, 98, 53, 32, -73, 14, -44, -12, -54, -121, 84, 119, 104, 52, -79, -86, 121, 120, 107, 96, 43, 109, -89, 51, -77, 9, 56, -90, 22, 3, -115, 12, 35, -122, -14, 19, 4, -5, 96, 9, 70, -118, -112, -27, 61, 70, 69, 54, 14, -91, 119, 102, -24, -115, -6, -75, -125, -5, -27, 106, -127, -127, 64, -51, 1, 11, 26, 57, 55, -87, 19, -79, -9, 21, 12, 45, -29, 127, -21, -21, 19, -37, -72, 109, 84, 27, 55, 90, 112, 21, 40, -86, 87, -112, -47, 70, -13, 91, -119, 102, 17, -82, -6, -72, 77, -13, 40, -94, 118, -21, -65, -52, -128, 91, -85, 66, -75, 112, -92, -122, 22, 9, 48, -63, -58, -66, 24, -53, 1, -85, 18, -111, 55, 100, 101, -15, 80, 87, -16, 120, 18, -88, -80, 3, 117, -14, 10, -102, -15, -100, -12, 96, -78, -4, -39, -65, -33, 65, -93, -123, 5, -76, -5, -95, -118, -8, 21, 39, -7, -74, 7, -35, -59, 78, -32, -47, 0, -53, 122, 114, -75, -6, 98, 74, 37, 35, 11, -106, 27, 124, 100, -80, 16, 3, 71, 107, 89, 102, 1, -87, -78, -15, -48, -89, 70, -104, -62, 114, -77, -113, 25, 115, 117, -108, 75, -71, 12, 35, 0, 85, -95, -92, 47, -94, 32, -65, 85, -79, -127, 87, 55, -37, 122, 11, 35, -41, 96, 6, 26, 52, 113, 101, -107, -115, 73, 9, -18, -11, -89, 9, -84, 28, 126, -52, -70, 28, -88, 46, 55, -122, 44, -66, 3, 41, -24, 89, -98, -60, 59, -56, 97, -76, -53, 28, -110, -111, 51, 11, 50, 104, 82, -115, 41, -119, 38, -51, 48, -60, -80, -26, 13, -97, -106, 96, -12, -74, 82, 15, -116, 86, 121, 106, 91, 3, 103, 33, 6, -57, -107, 107, -111, -63, -67, -100, 14, -9, 120, 95, -5, 39, -83, -102, -127, 65, -110, 27, 16, -20, 59, 52, -31, 71, -97, 93, -111, -125, -14, 27, 48, 28, -60, 102, -72, -5, 75, 111, -123, -70, -51, 92, 5, 79, -78, -90, 31, -70, -74, -44, -104, -65, 85, -96, -64, -15, -105, 113, 34, -84, -103, -43, -8, 41, 1, 2, 33, -87, 48, -128, -85, -101, -52, 71, 81, -102, 44, -119, 20, 120, 12, 9, 87, 58, 110, -115, -64, 83, -76, 51, -75, -47, -90, -112, 66, -14, 85, -27, 39, 15, -97, -53, -94, -39, 101, 43, 65, -52, 69, -81, 96, 39, -46, 123, -77, -98, -117, -68, 20, 105, 113, -74, -30, 24, -121, -105, 121, -91, -41, 21, -107, 40, 124, 8, -5, -55, -11, 114, -53, -52, 101, 13, 49, 86, 117, 6, 74, 66, 73, -44, 111, -1, 37, 62, -17, 56, 39, -114, -32, -99, 28, -109, 50, -86, 73, 57, 27, -41, -88, -108, -95, 60, 11, -103, -123, 11, -7, -56, 33, -70, 87, -86, -30, -50, 67, 105, 127, 74, -109, 18, -45, -109, 55, -17, -84, 2, -21, -128, -102, 98, 51, -53, 92, 117, 48, 124, 101, -82, 63, 120, 52, -92, -75, 30, -65, -128, -52, 80, -68, 31, -3, 9, -114, -43, -68, 1, 74, -60, -115, 91, 9, 11, 15, 3, -78, -118, -21, 119, -65, -123, 65, 42, -15, 44, -117, -116, -109, 92, -22, -62, -33, -15, 108, 19, -6, -89, 119, -92, -54, 72, 97, 68, -67, -6, -54, -49, -110, -116, -78, -121, 19, 43, -42, -111, -67, -63, -89, -48, -91, -111, -33, -22, 30, -24, -91, -95, -30, 16, 122, -87, 36, 23, 23, 33, 80, -74, -62, 115, -27, -103, 45, 28, 53, -93, -63, 124, -61, -28, -123, -77, -11, -30, 65, -98, -69, -104, -1, -71, 48, 71, -88, -105, -114, -13, 67, -116, 81, -103, -119, -110, -71, 112, 76, -120, 19, -128, 55, -40, 33, -127, -74, 97, 117, 47, -64, -50, 84, -20, -65, 46, -89, 13, -104, 75, 51, 77, 38, -100, 104, -72, 107, 10, -103, 67, -46, -12, 36, 14, 38, 109, 0, 66, 11, -128, -24, -110, -44, 81, -63, 63, 16, 48, 121, 107, 38, -103, -11, 4, -68, 113, -110, -17, -21, -87, -98, -63, -49, -19, -126, -56, 55, -128, 58, -39, -122, -70, -114, 50, 23, -122, 20, -75, -5, 85, 22, 12, 83, -127, 87, -101, 34, 118, 33, 63, 108, 56, -106, 79, -118, 58, -17, 92, -57, -45, 49, -102, 37, -26, 12, -89, 67, -106, 39, 115, -62, -56, 112, -92, -71, 52, 20, -59, -128, -51, -51, 1, 44, 114, -55, -95, 11, 86, -71, 81, 32, -51, -93, -55, 82, 89, -63, -71, -46, -9, 1, -27, -68, 78, -109, 21, 52, -37, 44, 107, 76, 36, 89, -77, 10, 13, 77, 85, 114, 0, -30, -122, -19, -69, -50, -31, 86, -84, 82, -9, -128, 112, 43, 8, 63, 68, 31, 84, 52, 57, -107, 12, -89, -103, -111, 3, 2, 86, 5, -79, -70, 125, -35, -47, -80, -12, -6, 20, -51, 19, 48, 47, 91, -56, 92, 57, -66, -7, -46, 12, 121, -77, -73, -125, -104, -89, -74, 51, 19, 53, -121, -111, 2, -118, -120, 60, 32, 32, -3, 5, 66, -74, 44, 123, 106, 121, 54, -60, 52, 46, -51, 43, -103, 59, -39, -58, -110, -61, 51, 107, -53, 73, -62, 75, 11, 75, -71, -128, 120, 85, 121, -75, -39, -52, -108, -38, 126, -80, -31, -93, -70, -91, -93, -61, 123, 101, -39, 25, 78, -21, -21, 2, 45, -94, 94, 10, 90, -69, -82, -55, 29, -37, -6, -108, 80, -38, 30, -75, 24, -98, 125, 28, 91, 46, -96, 60, 4, -64, 7, -80, 37, 44, 64, 21, -77, -6, 106, 115, 124, -41, 90, 0, 76, -87, -11, 0, -86, 61, -36, 105, -1, -94, 33, -60, 64, 95, -42, 35, -115, -21, -64, 97, -76, -110, -97, -3, -58, 11, 116, 97, 22, 109, 6, -61, -44, -80, 127, 124, 88, 68, -72, 19, 49, 111, -100, -52, -64, -59, -122, -97, 22, -120, -91, 38, -90, -16, 83, 103, -26, 19, -99, 82, -96, 1, -119, -16, 121, 3, -127, 84, 44, 124, -50, 99, -101, 73, 77, -5, 4, 37, 71, 99, 100, 86, 57, -48, -14, 47, 1, 55, 76, -96, -78, 105, -96, 43, -99, -44, -73, 2, -114, -100, 42, 24, -24, -56, 13, 108, 84, -98, -4, -86, -81, -89, 2, -89, -101, -121, 38, 91, -119, 103, -25, -105, -56, -36, -115, 61, 44, -81, 43, 54, 35, 30, -91, -59, 44, -43, -67, -123, -77, -118, 111, 90, 37, -6, -116, 78, -25, -105, 33, 41, 100, 80, -2, 99, -57, 7, 55, 44, 95, 41, 30, -74, -53, 115, 108, -58, -57, -27, -116, 26, -30, 119, 0, 84, 72, -100, 85, 115, -100, 38, -43, 31, -82, 115, -116, -5, 23, 59, 105, -8, 118, 39, -103, -81, 42, -55, -66, -20, -72, 105, -57, -46, 44, 75, 65, 110, -65, 19, 55, -113, -27, 126, -1, 118, 122, 10, 112, 44, 76, -20, 76, 54, -4, 53, 81, -123, 99, -20, -11, 43, 63, -36, 104, 24, -21, 52, 63, 118, 26, -119, 50, -55, 7, -39, 77, 5, 113, 43, -119, -10, 100, 105, -29, -71, -12, 101, 115, 78, -88, -114, 55, -47, -119, -116, -29, 38, 94, 74, 18, -12, -71, -82, -35, -56, 103, 59, -46, 74, 99, 117, 23, -21, 82, -73, -93, 116, 120, -93, 48, 113, -43, 48, 81, -74, 84, 6, -2, -68, 112, 116, 26, -85, -45, 49, -107, 109, -93, 23, -86, 55, -53, -4, -59, -126, -10, -75, 86, 67, 105, 93, 15, -117, 3, 42, -43, 38, 54, 74, 85, 40, 50, 100, -113, -122, -70, -61, 57, 103, 99, -111, 94, -33, 12, -113, 32, -27, 117, -123, -57, 111, -30, 66, -98, -78, 115, 86, -85, -75, 86, -2, 26, 24, -67, -28, -93, -8, 67, -122, 67, 123, 30, 101, -39, 54, -28, 16, 122, 113, -28, 18, 2, -56, 43, 65, 122, 116, -13, -29, 85, 49, 98, 108, 126, -22, 112, 31, 18, -56, -100, 56, -64, 53, -59, 48, -67, 40, -104, -128, -31, 23, -95, 99, -60, 103, 19, 11, 115, -95, 101, -48, -13, 69, -103, -107, -52, -120, 24, -83, -72, -44, -127, 64, -90, 96, -87, 119, 104, 60, 59, 95, -71, -120, -73, -19, 117, -105, 15, -46, -69, -75, -12, 51, 110, 90, 96, 67, 35, 118, 67, -100, 20, -4, 124, -69, 122, 73, -67, -73, -28, 28, 26, -106, -80, -42, 67, 74, 74, 1, 113, 30, 67, 5, -49, 54, 102, 83, 85, 22, -49, 16, 19, -6, -11, 37, 50, -61, 98, 100, -58, 4, 48, -63, -120, -97, 105, 21, 93, -42, -49, -63, 90, 44, 49, -107, 108, 84, 37, 3, 47, -60, 15, 22, -70, -74, -19, 74, -106, -64, 48, -71, -62, 5, 92, -8, -94, -101, -3, 60, -63, 9, 82, 89, 33, 123, 33, -117, 124, -104, 0, -84, -98, 73, -59, 44, 76, 53, -52, 82, -94, 76, -49, -36, 107, 69, 119, 83, -110, 1, -59, -6, 41, -104, -7, 103, -115, -94, 32, 87, 47, 82, 5, -61, 65, 84, -28, 96, 101, 123, -95, 101, -121, -84, 53, -19, 122, -76, -32, -6, -80, 10, -110, 21, -92, 40, 98, 115, -109, 78, -49, -5, 20, -122, -100, 4, -33, -60, -119, -43, -108, -74, 90, -90, 113, 19, -94, 96, -68, 43, 5, 24, -70, 69, -49, 122, -90, -117, -23, 28, 64, 60, -57, -26, 91, 78, -94, -120, -106, -39, -91, 110, -106, 67, 13, 56, -74, -114, 22, 114, -58, -37, 90, -79, -28, 23, 56, -76, -30, 100, -102, -112, 90, 37, -111, 61, 52, -79, -112, -66, -36, -95, 57, -110, 123, 54, 36, 81, 33, 99, 11, -33, 113, -101, 39, 112, 23, -101, 102, 49, 107, -45, -124, -85, 27, 95, 19, 1, -101, -105, -73, 90, -110, -62, 87, -80, -13, 17, -127, 119, 89, -66, 75, 10, 24, -38, 119, -120, -27, 108, -70, 21, 72, 67, -89, 29, 9, 116, 104, -44, 68, -102, -98, -87, 99, 111, -61, 49, 41, 90, -86, 90, -20, 102, 27, 124, 68, 93, -87, 30, 127, -10, 65, 11, -7, -61, 127, 5, -50, 107, 27, 67, 84, 43, 81, 22, 123, -111, 20, -121, 109, -17, 98, -111, -101, -100, -66, -59, 107, 39, -103, 22, 39, -44, 101, 2, 101, -58, 39, -69, 4, 42, 119, 60, 106, -75, -70, 92, -34, -5, -121, -2, 101, -124, 11, 65, 40, 88, 83, -88, -63, -54, 47, 120, 72, -54, -51, -48, -119, -33, 103, 79, -1, -24, -70, -15, -7, 48, 39, 104, -85, -30, -55, 85, -104, -46, 41, -39, -46, 36, -114, -128, 33, -72, -72, 51, -95, -120, 76, -95, 40, -78, -116, -12, -100, 119, 101, 90, 3, -91, 103, 71, -76, -118, 81, -106, -98, 99, -59, -80, -13, 118, -123, -63, -72, -102, -118, 1, 64, -122, 108, 46, -101, -127, 92, 69, 36, 23, -106, -25, 44, -48, 84, 119, -2, 35, 32, -103, 76, 119, -24, 117, -77, 101, -52, 75, -82, 70, 6, -124, -59, -119, -69, 16, -111, 115, -46, -67, 28, 90, -65, -107, -106, -70, -69, -111, 112, 47, -58, 106, 28, -40, 67, -90, 97, 5, 110, 33, 79, 45, -58, 40, -21, 80, 108, -57, -5, -69, 66, -107, -80, 50, -41, -87, -65, 36, 25, -85, -38, 7, 105, -8, 110, -62, 58, 100, -45, 32, -78, 69, -117, -99, 102, -21, 80, -56, -14, 64, -78, 36, 127, 5, 113, -113, 29, 44, -119, -38, -62, 126, 20, 101, 66, -125, 28, 35, 108, -84, 99, 99, 28, -69, -56, 86, 62, -91, 103, 86, 56, -112, 49, 70, -11, -64, -104, -126, 96, -126, -53, 20, 15, 24, -93, -39, 10, -81, 99, 11, 8, -84, -57, -61, 45, 57, 56, -128, 85, -100, 5, 52, -55, 35, 4, 127, 44, 56, 98, -56, -15, 87, 99, 87, -57, 56, -87, 84, -69, -86, 125, 44, 16, 55, 80, 0, 27, -17, -84, 53, 101, -77, -92, -8, 42, -55, -45, -63, 107, -128, 118, 38, 14, -42, -125, 103, -105, 6, 5, -21, -78, -2, 44, 63, -120, 10, 101, -6, -74, -112, 33, 81, -90, 90, -125, 11, 51, -9, 111, 7, 106, 13, -59, -104, 75, 118, -125, 89, 38, 73, 21, -85, 91, -58, 71, 0, 42, 1, -38, 116, -16, -53, 44, -97, 64, -124, -36, -36, -108, -114, 114, -102, 38, 0, 82, 113, 92, 14, 45, 58, 77, 49, -112, -110, -91, 8, 84, -69, -37, -61, 113, -111, -69, -44, -59, 76, -128, 59, 60, 36, 120, -128, -72, -40, 92, 100, 71, 68, 107, -48, -99, -126, -108, -108, 106, -59, 38, 31, 49, -92, 107, 105, -126, 45, -79, -74, 64, -89, 122, -119, -37, 119, -119, -112, 122, -117, 108, 69, 106, -52, 26, -118, 108, 103, -59, 120, -128, 14, -55, 116, 70, -92, -102, -38, -38, 100, 32, -103, -108, -75, -108, -55, 3, 112, 70, -15, -46, 17, -57, 17, -74, -60, -70, 119, -123, -84, 105, 64, 21, 28, 11, 10, -96, -118, -54, -110, 114, -79, 113, -56, 26, 73, -121, -71, 19, -106, -45, -66, -77, 71, 83, -71, 44, -71, -100, -45, 105, -9, 84, -105, 100, -4, -103, 5, 114, 43, -24, 81, -108, -26, -38, -88, -67, 12, 9, -105, -14, -68, 85, -120, -54, 60, 101, 104, -88, 119, 80, 13, -74, 90, 31, -28, 65, 37, -16, 114, 35, 44, 87, 46, 92, 60, -70, 16, 35, -29, -43, 70, 34, 58, -115, -48, 96, -66, 7, 8, -115, 96, -127, -80, -2, -12, 53, -61, -117, -122, 75, -6, 83, 103, 4, -99, -6, -91, 20, -109, 42, 92, 110, 85, -78, 3, 43, -112, 72, 120, -70, -19, 68, 13, -78, 59, 104, 70, 49, 114, -49, 74, -94, -51, 57, 93, -83, 23, 6, 102, 70, 88, 111, 76, 86, -66, 120, -49, 13, -30, -83, 13, 18, 27, -1, -56, -81, 84, 28, -102, -41, -118, 67, -94, -6, 2, -66, -29, 98, 31, -72, 114, -109, -123, 39, -65, -117, -80, -24, -15, -106, 48, 59, 75, -121, 33, -116, -70, -75, -121, 31, -10, 50, -49, 38, 74, 119, -74, -69, 15, 72, -123, -42, 96, -62, -123, -13, 75, 51, -42, 71, -56, 119, -99, -32, -39, 63, -10, 97, -70, 27, -29, 114, 23, 106, 17, 95, 27, 15, 57, -123, 105, 11, 76, -101, -86, -9, 16, -4, 55, -73, -41, -40, 26, 50, 24, -72, 56, 43, 58, -84, -108, -96, -18, -101, 72, 98, -11, -86, 97, 60, -105, -59, 12, 113, -33, -105, -120, 10, 44, -105, 48, 84, -64, 96, 91, 67, -8, 99, 108, -71, 37, -74, -73, 54, 82, -100, 116, 64, -33, 16, -61, -53, 88, 11, -59, 34, 17, 91, 96, 83, 47, -21, 9, 93, 102, 79, 15, 86, -99, 116, -57, 19, -65, -68, 50, -120, -124, -111, -12, 64, 28, 74, -54, 25, -101, 35, 82, 85, -80, 46, -28, -57, -126, 25, -61, -92, -52, 81, 58, -63, -94, -119, -47, 108, 23, -21, -108, 110, -109, 34, 4, -56, -96, 67, 77, 3, 124, -40, -46, -122, -43, -48, 94, 21, -7, 51, -53, 105, 92, 38, -122, 3, -2, -119, 48, 111, 35, 53, 33, 5, 85, 15, 58, -65, -120, -109, 35, 92, 112, -124, -35, 34, 4, 25, -71, -85, -46, -14, 42, -70, 12, -121, 43, 7, 28, -36, -121, -105, -44, 8, 39, 1, -119, 87, 113, -12, 9, 126, 108, 111, 117, -4, 97, -101, -73, 115, -37, -75, 78, -56, 18, -93, 114, 75, 77, 91, -11, 71, 82, -76, 100, -32, 74, 33, 20, -9, -77, 10, 7, 102, -28, 6, -107, -62, -25, -104, 36, 6, -98, -92, -94, 66, 1, -75, -78, -114, 122, -81, -53, 8, -95, 59, -72, 100, -61, 67, 44, -79, 106, -86, 0, -3, 55, -115, -36, 64, 86, 28, 57, 57, 55, -61, -4, -100, 11, -38, -15, 46, -77, -55, -77, 35, 23, -123, -101, -105, 122, 86, -88, -122, 12, -110, -110, 104, 67, 5, 117, -42, 111, 102, -22, 64, 109, -106, 8, 126, -68, 108, -61, -86, 7, -5, 24, -94, 68, -69, -52, 94, 118, 115, 18, -70, -100, 15, -9, 87, -76, -59, -82, -30, -58, 31, -5, -61, -111, -9, -32, 48, 39, -79, -114, -67, -73, -125, 91, 8, -108, -43, 5, 66, -24, 50, 117, -96, -109, -63, 20, -128, 42, -74, 113, -98, 88, 57, 64, 57, -119, 106, 5, 35, 112, -57, -13, -84, -116, -120, 32, -96, 39, 102, 37, 28, -107, -16, -52, 101, -93, 8, 109, -77, -28, 9, 68, 108, 54, 25, -4, 110, -3, 86, -30, -50, 71, -60, -16, -101, -37, -10, 11, -29, 15, 86, -26, 89, 64, 15, 30, 14, -117, 61, -78, 116, 56, -34, -49, -49, -101, -42, 7, 44, -95, -13, 44, 94, -4, 10, -32, 71, 23, -74, -110, -24, 64, 116, -30, -59, -27, -98, -61, 87, -4, -115, -60, -27, -47, -53, 99, 106, -73, -80, 40, 88, -38, -40, 64, 116, -27, -29, -46, 69, -68, -7, 71, 106, 93, 106, 39, -86, 67, 66, -103, -93, 21, -109, -115, -84, 87, 120, -87, -79, 112, 42, 119, -75] + pub_key=[-61, 57, 103, 99, -111, 94, -33, 12, -113, 32, -27, 117, -123, -57, 111, -30, 66, -98, -78, 115, 86, -85, -75, 86, -2, 26, 24, -67, -28, -93, -8, 67, -122, 67, 123, 30, 101, -39, 54, -28, 16, 122, 113, -28, 18, 2, -56, 43, 65, 122, 116, -13, -29, 85, 49, 98, 108, 126, -22, 112, 31, 18, -56, -100, 56, -64, 53, -59, 48, -67, 40, -104, -128, -31, 23, -95, 99, -60, 103, 19, 11, 115, -95, 101, -48, -13, 69, -103, -107, -52, -120, 24, -83, -72, -44, -127, 64, -90, 96, -87, 119, 104, 60, 59, 95, -71, -120, -73, -19, 117, -105, 15, -46, -69, -75, -12, 51, 110, 90, 96, 67, 35, 118, 67, -100, 20, -4, 124, -69, 122, 73, -67, -73, -28, 28, 26, -106, -80, -42, 67, 74, 74, 1, 113, 30, 67, 5, -49, 54, 102, 83, 85, 22, -49, 16, 19, -6, -11, 37, 50, -61, 98, 100, -58, 4, 48, -63, -120, -97, 105, 21, 93, -42, -49, -63, 90, 44, 49, -107, 108, 84, 37, 3, 47, -60, 15, 22, -70, -74, -19, 74, -106, -64, 48, -71, -62, 5, 92, -8, -94, -101, -3, 60, -63, 9, 82, 89, 33, 123, 33, -117, 124, -104, 0, -84, -98, 73, -59, 44, 76, 53, -52, 82, -94, 76, -49, -36, 107, 69, 119, 83, -110, 1, -59, -6, 41, -104, -7, 103, -115, -94, 32, 87, 47, 82, 5, -61, 65, 84, -28, 96, 101, 123, -95, 101, -121, -84, 53, -19, 122, -76, -32, -6, -80, 10, -110, 21, -92, 40, 98, 115, -109, 78, -49, -5, 20, -122, -100, 4, -33, -60, -119, -43, -108, -74, 90, -90, 113, 19, -94, 96, -68, 43, 5, 24, -70, 69, -49, 122, -90, -117, -23, 28, 64, 60, -57, -26, 91, 78, -94, -120, -106, -39, -91, 110, -106, 67, 13, 56, -74, -114, 22, 114, -58, -37, 90, -79, -28, 23, 56, -76, -30, 100, -102, -112, 90, 37, -111, 61, 52, -79, -112, -66, -36, -95, 57, -110, 123, 54, 36, 81, 33, 99, 11, -33, 113, -101, 39, 112, 23, -101, 102, 49, 107, -45, -124, -85, 27, 95, 19, 1, -101, -105, -73, 90, -110, -62, 87, -80, -13, 17, -127, 119, 89, -66, 75, 10, 24, -38, 119, -120, -27, 108, -70, 21, 72, 67, -89, 29, 9, 116, 104, -44, 68, -102, -98, -87, 99, 111, -61, 49, 41, 90, -86, 90, -20, 102, 27, 124, 68, 93, -87, 30, 127, -10, 65, 11, -7, -61, 127, 5, -50, 107, 27, 67, 84, 43, 81, 22, 123, -111, 20, -121, 109, -17, 98, -111, -101, -100, -66, -59, 107, 39, -103, 22, 39, -44, 101, 2, 101, -58, 39, -69, 4, 42, 119, 60, 106, -75, -70, 92, -34, -5, -121, -2, 101, -124, 11, 65, 40, 88, 83, -88, -63, -54, 47, 120, 72, -54, -51, -48, -119, -33, 103, 79, -1, -24, -70, -15, -7, 48, 39, 104, -85, -30, -55, 85, -104, -46, 41, -39, -46, 36, -114, -128, 33, -72, -72, 51, -95, -120, 76, -95, 40, -78, -116, -12, -100, 119, 101, 90, 3, -91, 103, 71, -76, -118, 81, -106, -98, 99, -59, -80, -13, 118, -123, -63, -72, -102, -118, 1, 64, -122, 108, 46, -101, -127, 92, 69, 36, 23, -106, -25, 44, -48, 84, 119, -2, 35, 32, -103, 76, 119, -24, 117, -77, 101, -52, 75, -82, 70, 6, -124, -59, -119, -69, 16, -111, 115, -46, -67, 28, 90, -65, -107, -106, -70, -69, -111, 112, 47, -58, 106, 28, -40, 67, -90, 97, 5, 110, 33, 79, 45, -58, 40, -21, 80, 108, -57, -5, -69, 66, -107, -80, 50, -41, -87, -65, 36, 25, -85, -38, 7, 105, -8, 110, -62, 58, 100, -45, 32, -78, 69, -117, -99, 102, -21, 80, -56, -14, 64, -78, 36, 127, 5, 113, -113, 29, 44, -119, -38, -62, 126, 20, 101, 66, -125, 28, 35, 108, -84, 99, 99, 28, -69, -56, 86, 62, -91, 103, 86, 56, -112, 49, 70, -11, -64, -104, -126, 96, -126, -53, 20, 15, 24, -93, -39, 10, -81, 99, 11, 8, -84, -57, -61, 45, 57, 56, -128, 85, -100, 5, 52, -55, 35, 4, 127, 44, 56, 98, -56, -15, 87, 99, 87, -57, 56, -87, 84, -69, -86, 125, 44, 16, 55, 80, 0, 27, -17, -84, 53, 101, -77, -92, -8, 42, -55, -45, -63, 107, -128, 118, 38, 14, -42, -125, 103, -105, 6, 5, -21, -78, -2, 44, 63, -120, 10, 101, -6, -74, -112, 33, 81, -90, 90, -125, 11, 51, -9, 111, 7, 106, 13, -59, -104, 75, 118, -125, 89, 38, 73, 21, -85, 91, -58, 71, 0, 42, 1, -38, 116, -16, -53, 44, -97, 64, -124, -36, -36, -108, -114, 114, -102, 38, 0, 82, 113, 92, 14, 45, 58, 77, 49, -112, -110, -91, 8, 84, -69, -37, -61, 113, -111, -69, -44, -59, 76, -128, 59, 60, 36, 120, -128, -72, -40, 92, 100, 71, 68, 107, -48, -99, -126, -108, -108, 106, -59, 38, 31, 49, -92, 107, 105, -126, 45, -79, -74, 64, -89, 122, -119, -37, 119, -119, -112, 122, -117, 108, 69, 106, -52, 26, -118, 108, 103, -59, 120, -128, 14, -55, 116, 70, -92, -102, -38, -38, 100, 32, -103, -108, -75, -108, -55, 3, 112, 70, -15, -46, 17, -57, 17, -74, -60, -70, 119, -123, -84, 105, 64, 21, 28, 11, 10, -96, -118, -54, -110, 114, -79, 113, -56, 26, 73, -121, -71, 19, -106, -45, -66, -77, 71, 83, -71, 44, -71, -100, -45, 105, -9, 84, -105, 100, -4, -103, 5, 114, 43, -24, 81, -108, -26, -38, -88, -67, 12, 9, -105, -14, -68, 85, -120, -54, 60, 101, 104, -88, 119, 80, 13, -74, 90, 31, -28, 65, 37, -16, 114, 35, 44, 87, 46, 92, 60, -70, 16, 35, -29, -43, 70, 34, 58, -115, -48, 96, -66, 7, 8, -115, 96, -127, -80, -2, -12, 53, -61, -117, -122, 75, -6, 83, 103, 4, -99, -6, -91, 20, -109, 42, 92, 110, 85, -78, 3, 43, -112, 72, 120, -70, -19, 68, 13, -78, 59, 104, 70, 49, 114, -49, 74, -94, -51, 57, 93, -83, 23, 6, 102, 70, 88, 111, 76, 86, -66, 120, -49, 13, -30, -83, 13, 18, 27, -1, -56, -81, 84, 28, -102, -41, -118, 67, -94, -6, 2, -66, -29, 98, 31, -72, 114, -109, -123, 39, -65, -117, -80, -24, -15, -106, 48, 59, 75, -121, 33, -116, -70, -75, -121, 31, -10, 50, -49, 38, 74, 119, -74, -69, 15, 72, -123, -42, 96, -62, -123, -13, 75, 51, -42, 71, -56, 119, -99, -32, -39, 63, -10, 97, -70, 27, -29, 114, 23, 106, 17, 95, 27, 15, 57, -123, 105, 11, 76, -101, -86, -9, 16, -4, 55, -73, -41, -40, 26, 50, 24, -72, 56, 43, 58, -84, -108, -96, -18, -101, 72, 98, -11, -86, 97, 60, -105, -59, 12, 113, -33, -105, -120, 10, 44, -105, 48, 84, -64, 96, 91, 67, -8, 99, 108, -71, 37, -74, -73, 54, 82, -100, 116, 64, -33, 16, -61, -53, 88, 11, -59, 34, 17, 91, 96, 83, 47, -21, 9, 93, 102, 79, 15, 86, -99, 116, -57, 19, -65, -68, 50, -120, -124, -111, -12, 64, 28, 74, -54, 25, -101, 35, 82, 85, -80, 46, -28, -57, -126, 25, -61, -92, -52, 81, 58, -63, -94, -119, -47, 108, 23, -21, -108, 110, -109, 34, 4, -56, -96, 67, 77, 3, 124, -40, -46, -122, -43, -48, 94, 21, -7, 51, -53, 105, 92, 38, -122, 3, -2, -119, 48, 111, 35, 53, 33, 5, 85, 15, 58, -65, -120, -109, 35, 92, 112, -124, -35, 34, 4, 25, -71, -85, -46, -14, 42, -70, 12, -121, 43, 7, 28, -36, -121, -105, -44, 8, 39, 1, -119, 87, 113, -12, 9, 126, 108, 111, 117, -4, 97, -101, -73, 115, -37, -75, 78, -56, 18, -93, 114, 75, 77, 91, -11, 71, 82, -76, 100, -32, 74, 33, 20, -9, -77, 10, 7, 102, -28, 6, -107, -62, -25, -104, 36, 6, -98, -92, -94, 66, 1, -75, -78, -114, 122, -81, -53, 8, -95, 59, -72, 100, -61, 67, 44, -79, 106, -86, 0, -3, 55, -115, -36, 64, 86, 28, 57, 57, 55, -61, -4, -100, 11, -38, -15, 46, -77, -55, -77, 35, 23, -123, -101, -105, 122, 86, -88, -122, 12, -110, -110, 104, 67, 5, 117, -42, 111, 102, -22, 64, 109, -106, 8, 126, -68, 108, -61, -86, 7, -5, 24, -94, 68, -69, -52, 94, 118, 115, 18, -70, -100, 15, -9, 87, -76, -59, -82, -30, -58, 31, -5, -61, -111, -9, -32, 48, 39, -79, -114, -67, -73, -125, 91, 8, -108, -43, 5, 66, -24, 50, 117, -96, -109, -63, 20, -128, 42, -74, 113, -98, 88, 57, 64, 57, -119, 106, 5, 35, 112, -57, -13, -84, -116, -120, 32, -96, 39, 102, 37, 28, -107, -16, -52, 101, -93, 8, 109, -77, -28, 9, 68, 108, 54, 25, -4, 110, -3, 86, -30, -50, 71, -60, -16, -101, -37, -10, 11, -29, 15, 86, -26, 89, 64, 15, 30, 14, -117, 61, -78, 116, 56, -34, -49, -49, -101, -42, 7, 44] + cipher= [-39, 5, -112, -92, 45, 104, -10, 51, -8, 98, 100, -47, -108, -113, -23, 74, 81, -103, 1, 63, -8, -39, 103, -13, -10, 67, 1, 101, 66, -9, -22, 74, -113, -111, 21, 49, 126, 7, -66, -13, -40, 14, -51, -13, 38, 15, 3, 83, 6, 101, 69, -85, 79, 53, 67, 18, 120, -88, 124, 68, -100, 60, -127, 52, -114, 73, -76, -121, 70, -27, -26, -73, -99, 71, -34, -100, 12, 46, -107, -82, 71, 1, -54, -93, 111, 40, 103, 125, -94, 84, -119, 108, -51, -37, -93, 101, 22, 42, 2, -22, 104, -43, 96, 35, 59, -69, -111, 18, 56, 80, 120, 104, -16, 90, 55, -117, 50, -40, 57, 30, 80, 0, 69, 54, 110, -15, 19, -10, -36, -81, -47, -97, 109, -11, -75, 84, 70, 53, -95, 23, -93, 59, -50, 10, -58, 90, 25, 82, 25, 72, -28, 28, 70, 32, -16, 34, -78, -29, 16, 55, -57, -63, -11, -64, 8, -42, 100, -45, -122, -65, 59, -59, -113, 116, -78, 34, -114, 78, 66, 113, -27, -115, 72, 41, -47, -128, -76, -43, -54, 26, 83, -67, -79, -81, -112, -17, -92, 82, 65, 105, 48, 41, 17, -97, 117, -69, 25, -78, -17, -126, 46, 87, 85, 65, -69, -49, 92, -114, 21, -68, -36, 83, -119, 61, 53, 83, -116, -29, -89, -100, 62, 82, 118, 117, 41, -101, 34, -74, 47, 121, 17, -30, -108, -107, -122, 120, 23, -25, -62, -94, 21, -101, 62, -127, -18, 2, -128, 86, -98, -114, 75, -27, 98, 69, 54, 93, -8, -101, 125, 105, 68, -127, -75, -124, 80, -15, -115, 75, -64, 55, -50, -38, 104, 78, -112, 105, -114, -101, -91, -60, -26, 21, 81, -15, 93, -99, -71, 77, -95, 116, -31, -22, -95, 53, 74, 24, 117, -25, 16, 43, 40, -106, 37, -62, -116, -69, -40, 61, 74, -90, 18, 32, 36, 86, -16, 55, 96, 43, 9, -61, 104, -122, 121, 96, 56, -128, -86, 106, -47, -121, -107, 3, 19, 0, 22, -2, -102, -7, 10, -56, 17, -69, -11, 92, 87, 62, -4, 45, -120, 85, 114, -67, 30, 115, 85, 41, 27, -97, -77, -85, 97, -62, -114, 78, 26, 112, -24, 78, -83, 124, -97, 20, 32, -57, 99, 18, 112, -83, -61, -119, -8, -11, 88, -4, 103, -24, -7, -98, -113, -5, -14, -116, -91, -118, -66, -92, 82, -86, 89, -85, 35, 72, -70, 99, -93, -74, 6, -103, -96, -87, -98, 88, -38, -40, 49, -109, 22, -61, -108, -93, -42, -70, -35, 14, 31, 11, 51, 82, 97, -80, 9, 120, 21, 69, 36, 3, 112, -75, 109, -49, 1, 40, 60, 11, 123, 31, 51, -71, -32, -91, -46, -22, -103, -31, -127, -97, 99, 46, 43, 23, -2, -55, 120, -82, -81, -51, 105, -96, 27, 23, 42, 65, -23, 93, 63, -16, 119, -21, -70, 23, 22, 40, 93, 30, 95, -68, -15, -57, 121, -43, -29, -54, -108, 120, -59, -120, 100, 122, 25, 66, -82, 101, 104, -61, -81, -76, -9, -29, 10, 100, -1, 114, -67, 54, 77, 2, -86, -22, 103, -57, 82, -35, -61, 74, -23, -33, -61, -25, 14, -67, 33, -114, 115, 101, -19, -126, 37, 50, -19, 72, 34, -57, 1, -105, 99, -127, 82, -106, 47, -75, -72, -116, 24, -60, -75, 3, -16, -40, -60, -97, -12, 76, -108, -67, 57, -103, -40, 63, 127, -19, -41, -56, 54, 113, 46, 46, -13, -38, -64, -14, -87, -14, 20, -115, -114, -24, 93, -77, 104, 121, 106, -43, 102, -100, 44, 16, -57, 35, 39, -21, 46, -37, 106, -74, 85, 28, -13, -62, 63, -44, -40, -32, 36, -100, -118, 109, 87, 61, 89, -9, 36, 118, -51, -105, -114, 4, 21, 82, -26, 92, 42, 70, 33, 96, -31, 39, 52, 104, 50, -49, 118, -90, -60, -78, 43, 113, -127, -80, 49, -81, -119, -78, -35, 15, -21, 117, -19, 8, 65, -21, -2, -52, 73, 111, 16, 69, 106, 124, 44, 71, 6, 75, 38, 80, 26, 86, -61, -45, -99, 103, 73, -11, -12, -12, -64, -102, -107, -101, -10, -103, -29, -117, -17, 78, -110, 10, -94, 21, 8, -1, 76, 33, 125, 112, -86, 117, 20, 109, 93, 70, 41, 3, -97, 35, 12, -60, -67, -93, -97, 108, -12, -45, 85, -33, -51, 85, 53, -85, -21, 84, -56, 55, 33, 47, 32, 58, 85, -128, 2, -18, -85, -94, 124, 27, 108, -88, 87, 18, 45, 114, 81, 63, -45, -2, 122, -126, -5, 96, -64, -60, 45, 1, 41, -90, 120, -50, 69, 85, 24, -112, 57, 101, -127, 31, -82, -95, 107, -7, -45, -23, -86, 53, -14, -14, -86, -109, -43, -11, -23, -30, -120, -117, 20, 7, 19, 62, -82, 20, 23, 86, -128, 122, -81, 124, 101, 35, 125, 110, -75, 122, 38, 60, 81, 116, -9, -5, -54, 88, 92, 72, 101, -19, 115, -101, -8, -41, -98, -76, 49, 102, 41, 124, 124, 119, -34, 2, -89, -6, -118, 84, 83, -101, -8, -8, -76, 74, 35, -37, 82, 76, 71, -65, -40, -115, 97, -55, 91, 57, -44, 32, -116, 74, 57, -69, -54, -71, 101, -75, 16, 96, 86, 74, -82, 57, 118, 101, 26, 114, 52, 99, -111, 49, 95, -101, -29, 61, -96, 22, -74, 54, 35, -127, -7, -102, -23, -51, 109, 17, -45, 97, 44, -73, 77, 73, -71, 93, 48, -20, -113, -68, 6, -90, -68, -40, 56, -22, 38, -106, 9, 21, -20, -11, -121, 62, 0, -5, -47, 61, -93, -86, 74, -65, 55, -34, -34, -23, -74, 64, -22, -52, -1, 5, 19, -30, -111, -41, -100, 71, -9, -13, 31, -8, 114, 72, -8, 0, 75, 95, 113, -27, -107, -82, -54, 3, -118, -5, -61, 42, -15, 13, 117, 28, 101, 75, 24, -107, 66, -7, 125, 119, 65, 0, -37, 49, -50, 37, 34, -36, 28, 2, 25, 34, 110, -62, -96, 36, 66, 67, 82, -33, -127, 50, -9, 0, -44, 33, 17, 80, -91, -88, -90, 33, -116, 80, 30, -41, 25, -59, -64, -103, -51, -3, -94, -12, 124, -97, 77, 40, 67, 114, -23, -21, -115, 56, -54, -90, 14, 71, -91, -76, 27, 40, 107, -120, -16, -20, -73, 98, 112, -40, -32, -128, -49, 44, 56, 62, 13, -68, 126, 75, -103, -7, -126, -63, 86, 21, -74, 65, -5, 113, 109, 36, -18, -14, -13, -77, 46, 90, -7, 17, 93, 105, -28, -74, -116, 60, -107, 68, 63, -52, -103, 95, 47, 18, -58, 23, -26, -72, 91, -88, -48, -106, -105, -101, 101, 51, 66, 48, -31, -40, 91, 117, -52, -99, 113, 57, 30, 9, -79, 24, -65, -63, 118, 95, 122, 79, -6, 4, -109, -88, 111, -100, -27, 20, 102, -14, 90, -52, -107, 119, 29, -109, -73, 116, -111, 23, -73, 126, -117, 44, 72, -65, -5, 122, -73, -119, 64, 30, 15, -104, 63, -47, -74, 45, -28, 59, 33, 21, 125, -109, 30, 121, 6, -108, -23, -111, 83, 72, -65, -55, -15, -124, -11, -104, 51, 31, -114, 107, -12, 104, -8, 43, -90, 21, 119, 103, -42, -4, 59, -22, -5, -9, 9, 103, 113, 44, 30, -71, -67, -57, 5, 78, -107, -85, -84, -122, -33, 103, -31, 5, -114, 33, 123, 46, 98, 60, -48, 6, 102, 105, 108, -14, -8, 100, 60, -79, 81, -63, -76, 77, 19, -76, -66, -90, -96, 25, 49, 37, 62, -127, -35, -34, 117, 75, 102, 82, 60, -58, 115, -58, 56, -37, 122, -69, -101, -18, 80, -94, -106, -84, 22, -83, 23, 86, -4, -8, 7, -81, -87, 112, 89, 85, 121, -27, 77, -109, -41, -102, -50, 116, 20, 92, 35, -70, 118, 27, -33, -76, 126, 20, 47, -106, -58, -2, -22, -27, 60, -106, 48, -114, 87, 19, -83, 124, -31, 87, 95, 67, -110, -19, 59, -12, 39, 49, -87, -17, 44, -25, -66, -18, -23, -119, -13, 70, 36, -15, 33, 120, -18, -103, 53, -108, 112, -17, -67, -87, 73, 41, 34, 126, 35, 42, 20, -98, -79, 52, -67, 110, -24, 30, -40, -94, -17, 110, 57, 43, 5, 72, 93, -10, -43, 52, 75, 49, 95, -18, -72, -66, -8, 75, -67, -51, -26, -106, 115, -64, -9, 88, 75, -64, -25, -35, -4, -50, 73, -52, -70, 87, 70, -13, -116, 39, -117, 104, 54, -74, 45, 4, -57, 118, 108, 125, -78, 28, 65, -108, -83, 68, -88, -3, -96, 0, 84, 125, -114, -78, -87, 120, 91, -37, -120, -42, 112, -16, -22, -76, -53, -2, 72, -36, -80, 117, 71, 109, 95, 62, 7, 63, -111, -48, 61, 46, -42, 31, -57, 68, -56, 64, 35, 68, 37, 107, -64, 13, 76, 50, 95, -37, 42, 110, 85, 80, -105, 119, -63, -108, 0, 63, 15, -11, 125, 50, -87, 52, 74, 116, -100, 91, -92, 125, 81, -38, 87, -101, -85, -16, 22, -9, 122, 12, -80, -3, -19, -17, -88, 120, 19, 118, -60, -88, -32, -102, -46, 19, 92, -47, -106, -106, -75, -107, 6, 16, 1, -23, -128, -77, 35, -39, 44, -88, -18, -43, -48, 99, -1, 57, 66, 120, 15, -110, -94, 99, 24, 15, 93, 58, 124, 123, 19, 25, 64, -109, -40, -36, -88, -83, 67, -39] + + # decrypt session key with Kyber private key + loading_message("Decrypting AES symmetric key with Kyber private key and cipher text...", duration=0.1) + decrypted_aes_key = kem_decaps1024(priv_key, cipher) + print("AES session key decrypted with Kyber private key.\n") + + # decrypt the message with the decrypted AES key + loading_message("Decrypting message with AES...", duration=0.1) + decrypted_message = aes_decrypt(encrypted_message, convert_to_bytes(decrypted_aes_key)) + print("Message decrypted with AES.\n") + + # Check if the original message and decrypted message are the same + assert message == decrypted_message, "Decryption failed: original and decrypted messages do not match!" + print("Encryption and decryption test passed!") + + print("Original Message:", message) + print("Decrypted Message:", decrypted_message) + +if __name__ == "__main__": + test_decryption() diff --git a/tests/test_encryption.py b/tests/test_encryption.py index 75b3b42..a48b0e6 100644 --- a/tests/test_encryption.py +++ b/tests/test_encryption.py @@ -1,44 +1,52 @@ +import time +from tqdm import tqdm from Crypto.Cipher import AES -from Crypto.Util.Padding import pad -#from src.key_management import generate_kyber_keypair -from pyky.ccakem import kem_keygen512, kem_encaps512, kem_decaps512 +from Crypto.Util.Padding import pad, unpad +from pyky.ccakem import kem_keygen1024, kem_encaps1024, kem_decaps1024 from src.encryption import generate_aes_key, aes_encrypt -from src.decryption import aes_decrypt def generate_kyber_keypair(): """Generate a Kyber key pair.""" - return kem_keygen512() + return kem_keygen1024() + +# Convert list of signed integers to bytes +def convert_to_bytes(signed_int_list): + return bytes([x & 0xFF for x in signed_int_list]) + +def loading_message(message, duration=0.1): + """Simulate a loading process with a message and duration.""" + print(message) + for _ in tqdm(range(100), desc=message, ncols=100, ascii=True, bar_format='{l_bar}{bar} | {percentage:3.0f}%'): + time.sleep(duration / 100) + print() def test_encryption(): # Generate Kyber key pair - - priv_key, pub_key = generate_kyber_keypair() - print("Kyber key pair generated.") + loading_message("Getting public key from receiver", duration=0.1) - # Generate AES session key - aes_key = generate_aes_key() - print("AES session key generated.") + #public_key generated from receiver + priv_key = [-58, -4, -86, 73, -7, -121, -127, -71, 34, -40, -25, 29, -73, 117, -120, 108, 75, -111, -37, -78, -109, -110, -86, -120, 29, -7, -62, 103, 80, 46, 72, -27, -78, 53, -63, -76, 73, -101, 62, -72, -105, 124, -64, -31, 79, 123, 7, -100, 45, -42, 127, -65, -92, 74, -117, -11, -96, -58, 122, 6, 108, 23, 21, -53, -118, 66, -56, -112, 56, 41, -4, -82, -26, -47, -72, -109, 28, -53, 30, 80, -105, 106, 24, 64, 3, 80, 92, 4, 1, -102, 40, 54, 19, -51, 18, 19, 74, -13, -82, -125, -41, 58, -111, -56, 56, 94, 115, 20, 122, 4, 67, -95, -96, 4, 99, -73, 41, 5, 41, 65, 44, 66, -95, -23, 50, 95, -2, -119, -64, -103, 81, 114, 14, 60, 94, -83, 2, -77, 23, -64, 55, 80, -5, 74, 26, -71, 29, -26, 51, 99, 86, -37, -107, -120, 52, -80, 94, 35, 11, 126, -76, 105, 73, -122, 75, 26, 113, -49, 98, 55, 68, -43, -91, -67, 114, 7, 13, 32, -104, 27, -79, -71, 100, 56, -59, 112, -17, -74, 59, -4, 66, 79, 20, 91, 79, -89, -40, 29, 107, 122, 11, 91, 66, 35, -32, 9, 105, -24, 17, 118, 78, -80, -79, -60, 20, -94, -12, -120, -98, -64, -91, -113, 72, -70, 0, 114, -62, 0, 34, -112, 21, -22, 69, 119, 17, -126, 86, -121, 98, 53, 32, -73, 14, -44, -12, -54, -121, 84, 119, 104, 52, -79, -86, 121, 120, 107, 96, 43, 109, -89, 51, -77, 9, 56, -90, 22, 3, -115, 12, 35, -122, -14, 19, 4, -5, 96, 9, 70, -118, -112, -27, 61, 70, 69, 54, 14, -91, 119, 102, -24, -115, -6, -75, -125, -5, -27, 106, -127, -127, 64, -51, 1, 11, 26, 57, 55, -87, 19, -79, -9, 21, 12, 45, -29, 127, -21, -21, 19, -37, -72, 109, 84, 27, 55, 90, 112, 21, 40, -86, 87, -112, -47, 70, -13, 91, -119, 102, 17, -82, -6, -72, 77, -13, 40, -94, 118, -21, -65, -52, -128, 91, -85, 66, -75, 112, -92, -122, 22, 9, 48, -63, -58, -66, 24, -53, 1, -85, 18, -111, 55, 100, 101, -15, 80, 87, -16, 120, 18, -88, -80, 3, 117, -14, 10, -102, -15, -100, -12, 96, -78, -4, -39, -65, -33, 65, -93, -123, 5, -76, -5, -95, -118, -8, 21, 39, -7, -74, 7, -35, -59, 78, -32, -47, 0, -53, 122, 114, -75, -6, 98, 74, 37, 35, 11, -106, 27, 124, 100, -80, 16, 3, 71, 107, 89, 102, 1, -87, -78, -15, -48, -89, 70, -104, -62, 114, -77, -113, 25, 115, 117, -108, 75, -71, 12, 35, 0, 85, -95, -92, 47, -94, 32, -65, 85, -79, -127, 87, 55, -37, 122, 11, 35, -41, 96, 6, 26, 52, 113, 101, -107, -115, 73, 9, -18, -11, -89, 9, -84, 28, 126, -52, -70, 28, -88, 46, 55, -122, 44, -66, 3, 41, -24, 89, -98, -60, 59, -56, 97, -76, -53, 28, -110, -111, 51, 11, 50, 104, 82, -115, 41, -119, 38, -51, 48, -60, -80, -26, 13, -97, -106, 96, -12, -74, 82, 15, -116, 86, 121, 106, 91, 3, 103, 33, 6, -57, -107, 107, -111, -63, -67, -100, 14, -9, 120, 95, -5, 39, -83, -102, -127, 65, -110, 27, 16, -20, 59, 52, -31, 71, -97, 93, -111, -125, -14, 27, 48, 28, -60, 102, -72, -5, 75, 111, -123, -70, -51, 92, 5, 79, -78, -90, 31, -70, -74, -44, -104, -65, 85, -96, -64, -15, -105, 113, 34, -84, -103, -43, -8, 41, 1, 2, 33, -87, 48, -128, -85, -101, -52, 71, 81, -102, 44, -119, 20, 120, 12, 9, 87, 58, 110, -115, -64, 83, -76, 51, -75, -47, -90, -112, 66, -14, 85, -27, 39, 15, -97, -53, -94, -39, 101, 43, 65, -52, 69, -81, 96, 39, -46, 123, -77, -98, -117, -68, 20, 105, 113, -74, -30, 24, -121, -105, 121, -91, -41, 21, -107, 40, 124, 8, -5, -55, -11, 114, -53, -52, 101, 13, 49, 86, 117, 6, 74, 66, 73, -44, 111, -1, 37, 62, -17, 56, 39, -114, -32, -99, 28, -109, 50, -86, 73, 57, 27, -41, -88, -108, -95, 60, 11, -103, -123, 11, -7, -56, 33, -70, 87, -86, -30, -50, 67, 105, 127, 74, -109, 18, -45, -109, 55, -17, -84, 2, -21, -128, -102, 98, 51, -53, 92, 117, 48, 124, 101, -82, 63, 120, 52, -92, -75, 30, -65, -128, -52, 80, -68, 31, -3, 9, -114, -43, -68, 1, 74, -60, -115, 91, 9, 11, 15, 3, -78, -118, -21, 119, -65, -123, 65, 42, -15, 44, -117, -116, -109, 92, -22, -62, -33, -15, 108, 19, -6, -89, 119, -92, -54, 72, 97, 68, -67, -6, -54, -49, -110, -116, -78, -121, 19, 43, -42, -111, -67, -63, -89, -48, -91, -111, -33, -22, 30, -24, -91, -95, -30, 16, 122, -87, 36, 23, 23, 33, 80, -74, -62, 115, -27, -103, 45, 28, 53, -93, -63, 124, -61, -28, -123, -77, -11, -30, 65, -98, -69, -104, -1, -71, 48, 71, -88, -105, -114, -13, 67, -116, 81, -103, -119, -110, -71, 112, 76, -120, 19, -128, 55, -40, 33, -127, -74, 97, 117, 47, -64, -50, 84, -20, -65, 46, -89, 13, -104, 75, 51, 77, 38, -100, 104, -72, 107, 10, -103, 67, -46, -12, 36, 14, 38, 109, 0, 66, 11, -128, -24, -110, -44, 81, -63, 63, 16, 48, 121, 107, 38, -103, -11, 4, -68, 113, -110, -17, -21, -87, -98, -63, -49, -19, -126, -56, 55, -128, 58, -39, -122, -70, -114, 50, 23, -122, 20, -75, -5, 85, 22, 12, 83, -127, 87, -101, 34, 118, 33, 63, 108, 56, -106, 79, -118, 58, -17, 92, -57, -45, 49, -102, 37, -26, 12, -89, 67, -106, 39, 115, -62, -56, 112, -92, -71, 52, 20, -59, -128, -51, -51, 1, 44, 114, -55, -95, 11, 86, -71, 81, 32, -51, -93, -55, 82, 89, -63, -71, -46, -9, 1, -27, -68, 78, -109, 21, 52, -37, 44, 107, 76, 36, 89, -77, 10, 13, 77, 85, 114, 0, -30, -122, -19, -69, -50, -31, 86, -84, 82, -9, -128, 112, 43, 8, 63, 68, 31, 84, 52, 57, -107, 12, -89, -103, -111, 3, 2, 86, 5, -79, -70, 125, -35, -47, -80, -12, -6, 20, -51, 19, 48, 47, 91, -56, 92, 57, -66, -7, -46, 12, 121, -77, -73, -125, -104, -89, -74, 51, 19, 53, -121, -111, 2, -118, -120, 60, 32, 32, -3, 5, 66, -74, 44, 123, 106, 121, 54, -60, 52, 46, -51, 43, -103, 59, -39, -58, -110, -61, 51, 107, -53, 73, -62, 75, 11, 75, -71, -128, 120, 85, 121, -75, -39, -52, -108, -38, 126, -80, -31, -93, -70, -91, -93, -61, 123, 101, -39, 25, 78, -21, -21, 2, 45, -94, 94, 10, 90, -69, -82, -55, 29, -37, -6, -108, 80, -38, 30, -75, 24, -98, 125, 28, 91, 46, -96, 60, 4, -64, 7, -80, 37, 44, 64, 21, -77, -6, 106, 115, 124, -41, 90, 0, 76, -87, -11, 0, -86, 61, -36, 105, -1, -94, 33, -60, 64, 95, -42, 35, -115, -21, -64, 97, -76, -110, -97, -3, -58, 11, 116, 97, 22, 109, 6, -61, -44, -80, 127, 124, 88, 68, -72, 19, 49, 111, -100, -52, -64, -59, -122, -97, 22, -120, -91, 38, -90, -16, 83, 103, -26, 19, -99, 82, -96, 1, -119, -16, 121, 3, -127, 84, 44, 124, -50, 99, -101, 73, 77, -5, 4, 37, 71, 99, 100, 86, 57, -48, -14, 47, 1, 55, 76, -96, -78, 105, -96, 43, -99, -44, -73, 2, -114, -100, 42, 24, -24, -56, 13, 108, 84, -98, -4, -86, -81, -89, 2, -89, -101, -121, 38, 91, -119, 103, -25, -105, -56, -36, -115, 61, 44, -81, 43, 54, 35, 30, -91, -59, 44, -43, -67, -123, -77, -118, 111, 90, 37, -6, -116, 78, -25, -105, 33, 41, 100, 80, -2, 99, -57, 7, 55, 44, 95, 41, 30, -74, -53, 115, 108, -58, -57, -27, -116, 26, -30, 119, 0, 84, 72, -100, 85, 115, -100, 38, -43, 31, -82, 115, -116, -5, 23, 59, 105, -8, 118, 39, -103, -81, 42, -55, -66, -20, -72, 105, -57, -46, 44, 75, 65, 110, -65, 19, 55, -113, -27, 126, -1, 118, 122, 10, 112, 44, 76, -20, 76, 54, -4, 53, 81, -123, 99, -20, -11, 43, 63, -36, 104, 24, -21, 52, 63, 118, 26, -119, 50, -55, 7, -39, 77, 5, 113, 43, -119, -10, 100, 105, -29, -71, -12, 101, 115, 78, -88, -114, 55, -47, -119, -116, -29, 38, 94, 74, 18, -12, -71, -82, -35, -56, 103, 59, -46, 74, 99, 117, 23, -21, 82, -73, -93, 116, 120, -93, 48, 113, -43, 48, 81, -74, 84, 6, -2, -68, 112, 116, 26, -85, -45, 49, -107, 109, -93, 23, -86, 55, -53, -4, -59, -126, -10, -75, 86, 67, 105, 93, 15, -117, 3, 42, -43, 38, 54, 74, 85, 40, 50, 100, -113, -122, -70, -61, 57, 103, 99, -111, 94, -33, 12, -113, 32, -27, 117, -123, -57, 111, -30, 66, -98, -78, 115, 86, -85, -75, 86, -2, 26, 24, -67, -28, -93, -8, 67, -122, 67, 123, 30, 101, -39, 54, -28, 16, 122, 113, -28, 18, 2, -56, 43, 65, 122, 116, -13, -29, 85, 49, 98, 108, 126, -22, 112, 31, 18, -56, -100, 56, -64, 53, -59, 48, -67, 40, -104, -128, -31, 23, -95, 99, -60, 103, 19, 11, 115, -95, 101, -48, -13, 69, -103, -107, -52, -120, 24, -83, -72, -44, -127, 64, -90, 96, -87, 119, 104, 60, 59, 95, -71, -120, -73, -19, 117, -105, 15, -46, -69, -75, -12, 51, 110, 90, 96, 67, 35, 118, 67, -100, 20, -4, 124, -69, 122, 73, -67, -73, -28, 28, 26, -106, -80, -42, 67, 74, 74, 1, 113, 30, 67, 5, -49, 54, 102, 83, 85, 22, -49, 16, 19, -6, -11, 37, 50, -61, 98, 100, -58, 4, 48, -63, -120, -97, 105, 21, 93, -42, -49, -63, 90, 44, 49, -107, 108, 84, 37, 3, 47, -60, 15, 22, -70, -74, -19, 74, -106, -64, 48, -71, -62, 5, 92, -8, -94, -101, -3, 60, -63, 9, 82, 89, 33, 123, 33, -117, 124, -104, 0, -84, -98, 73, -59, 44, 76, 53, -52, 82, -94, 76, -49, -36, 107, 69, 119, 83, -110, 1, -59, -6, 41, -104, -7, 103, -115, -94, 32, 87, 47, 82, 5, -61, 65, 84, -28, 96, 101, 123, -95, 101, -121, -84, 53, -19, 122, -76, -32, -6, -80, 10, -110, 21, -92, 40, 98, 115, -109, 78, -49, -5, 20, -122, -100, 4, -33, -60, -119, -43, -108, -74, 90, -90, 113, 19, -94, 96, -68, 43, 5, 24, -70, 69, -49, 122, -90, -117, -23, 28, 64, 60, -57, -26, 91, 78, -94, -120, -106, -39, -91, 110, -106, 67, 13, 56, -74, -114, 22, 114, -58, -37, 90, -79, -28, 23, 56, -76, -30, 100, -102, -112, 90, 37, -111, 61, 52, -79, -112, -66, -36, -95, 57, -110, 123, 54, 36, 81, 33, 99, 11, -33, 113, -101, 39, 112, 23, -101, 102, 49, 107, -45, -124, -85, 27, 95, 19, 1, -101, -105, -73, 90, -110, -62, 87, -80, -13, 17, -127, 119, 89, -66, 75, 10, 24, -38, 119, -120, -27, 108, -70, 21, 72, 67, -89, 29, 9, 116, 104, -44, 68, -102, -98, -87, 99, 111, -61, 49, 41, 90, -86, 90, -20, 102, 27, 124, 68, 93, -87, 30, 127, -10, 65, 11, -7, -61, 127, 5, -50, 107, 27, 67, 84, 43, 81, 22, 123, -111, 20, -121, 109, -17, 98, -111, -101, -100, -66, -59, 107, 39, -103, 22, 39, -44, 101, 2, 101, -58, 39, -69, 4, 42, 119, 60, 106, -75, -70, 92, -34, -5, -121, -2, 101, -124, 11, 65, 40, 88, 83, -88, -63, -54, 47, 120, 72, -54, -51, -48, -119, -33, 103, 79, -1, -24, -70, -15, -7, 48, 39, 104, -85, -30, -55, 85, -104, -46, 41, -39, -46, 36, -114, -128, 33, -72, -72, 51, -95, -120, 76, -95, 40, -78, -116, -12, -100, 119, 101, 90, 3, -91, 103, 71, -76, -118, 81, -106, -98, 99, -59, -80, -13, 118, -123, -63, -72, -102, -118, 1, 64, -122, 108, 46, -101, -127, 92, 69, 36, 23, -106, -25, 44, -48, 84, 119, -2, 35, 32, -103, 76, 119, -24, 117, -77, 101, -52, 75, -82, 70, 6, -124, -59, -119, -69, 16, -111, 115, -46, -67, 28, 90, -65, -107, -106, -70, -69, -111, 112, 47, -58, 106, 28, -40, 67, -90, 97, 5, 110, 33, 79, 45, -58, 40, -21, 80, 108, -57, -5, -69, 66, -107, -80, 50, -41, -87, -65, 36, 25, -85, -38, 7, 105, -8, 110, -62, 58, 100, -45, 32, -78, 69, -117, -99, 102, -21, 80, -56, -14, 64, -78, 36, 127, 5, 113, -113, 29, 44, -119, -38, -62, 126, 20, 101, 66, -125, 28, 35, 108, -84, 99, 99, 28, -69, -56, 86, 62, -91, 103, 86, 56, -112, 49, 70, -11, -64, -104, -126, 96, -126, -53, 20, 15, 24, -93, -39, 10, -81, 99, 11, 8, -84, -57, -61, 45, 57, 56, -128, 85, -100, 5, 52, -55, 35, 4, 127, 44, 56, 98, -56, -15, 87, 99, 87, -57, 56, -87, 84, -69, -86, 125, 44, 16, 55, 80, 0, 27, -17, -84, 53, 101, -77, -92, -8, 42, -55, -45, -63, 107, -128, 118, 38, 14, -42, -125, 103, -105, 6, 5, -21, -78, -2, 44, 63, -120, 10, 101, -6, -74, -112, 33, 81, -90, 90, -125, 11, 51, -9, 111, 7, 106, 13, -59, -104, 75, 118, -125, 89, 38, 73, 21, -85, 91, -58, 71, 0, 42, 1, -38, 116, -16, -53, 44, -97, 64, -124, -36, -36, -108, -114, 114, -102, 38, 0, 82, 113, 92, 14, 45, 58, 77, 49, -112, -110, -91, 8, 84, -69, -37, -61, 113, -111, -69, -44, -59, 76, -128, 59, 60, 36, 120, -128, -72, -40, 92, 100, 71, 68, 107, -48, -99, -126, -108, -108, 106, -59, 38, 31, 49, -92, 107, 105, -126, 45, -79, -74, 64, -89, 122, -119, -37, 119, -119, -112, 122, -117, 108, 69, 106, -52, 26, -118, 108, 103, -59, 120, -128, 14, -55, 116, 70, -92, -102, -38, -38, 100, 32, -103, -108, -75, -108, -55, 3, 112, 70, -15, -46, 17, -57, 17, -74, -60, -70, 119, -123, -84, 105, 64, 21, 28, 11, 10, -96, -118, -54, -110, 114, -79, 113, -56, 26, 73, -121, -71, 19, -106, -45, -66, -77, 71, 83, -71, 44, -71, -100, -45, 105, -9, 84, -105, 100, -4, -103, 5, 114, 43, -24, 81, -108, -26, -38, -88, -67, 12, 9, -105, -14, -68, 85, -120, -54, 60, 101, 104, -88, 119, 80, 13, -74, 90, 31, -28, 65, 37, -16, 114, 35, 44, 87, 46, 92, 60, -70, 16, 35, -29, -43, 70, 34, 58, -115, -48, 96, -66, 7, 8, -115, 96, -127, -80, -2, -12, 53, -61, -117, -122, 75, -6, 83, 103, 4, -99, -6, -91, 20, -109, 42, 92, 110, 85, -78, 3, 43, -112, 72, 120, -70, -19, 68, 13, -78, 59, 104, 70, 49, 114, -49, 74, -94, -51, 57, 93, -83, 23, 6, 102, 70, 88, 111, 76, 86, -66, 120, -49, 13, -30, -83, 13, 18, 27, -1, -56, -81, 84, 28, -102, -41, -118, 67, -94, -6, 2, -66, -29, 98, 31, -72, 114, -109, -123, 39, -65, -117, -80, -24, -15, -106, 48, 59, 75, -121, 33, -116, -70, -75, -121, 31, -10, 50, -49, 38, 74, 119, -74, -69, 15, 72, -123, -42, 96, -62, -123, -13, 75, 51, -42, 71, -56, 119, -99, -32, -39, 63, -10, 97, -70, 27, -29, 114, 23, 106, 17, 95, 27, 15, 57, -123, 105, 11, 76, -101, -86, -9, 16, -4, 55, -73, -41, -40, 26, 50, 24, -72, 56, 43, 58, -84, -108, -96, -18, -101, 72, 98, -11, -86, 97, 60, -105, -59, 12, 113, -33, -105, -120, 10, 44, -105, 48, 84, -64, 96, 91, 67, -8, 99, 108, -71, 37, -74, -73, 54, 82, -100, 116, 64, -33, 16, -61, -53, 88, 11, -59, 34, 17, 91, 96, 83, 47, -21, 9, 93, 102, 79, 15, 86, -99, 116, -57, 19, -65, -68, 50, -120, -124, -111, -12, 64, 28, 74, -54, 25, -101, 35, 82, 85, -80, 46, -28, -57, -126, 25, -61, -92, -52, 81, 58, -63, -94, -119, -47, 108, 23, -21, -108, 110, -109, 34, 4, -56, -96, 67, 77, 3, 124, -40, -46, -122, -43, -48, 94, 21, -7, 51, -53, 105, 92, 38, -122, 3, -2, -119, 48, 111, 35, 53, 33, 5, 85, 15, 58, -65, -120, -109, 35, 92, 112, -124, -35, 34, 4, 25, -71, -85, -46, -14, 42, -70, 12, -121, 43, 7, 28, -36, -121, -105, -44, 8, 39, 1, -119, 87, 113, -12, 9, 126, 108, 111, 117, -4, 97, -101, -73, 115, -37, -75, 78, -56, 18, -93, 114, 75, 77, 91, -11, 71, 82, -76, 100, -32, 74, 33, 20, -9, -77, 10, 7, 102, -28, 6, -107, -62, -25, -104, 36, 6, -98, -92, -94, 66, 1, -75, -78, -114, 122, -81, -53, 8, -95, 59, -72, 100, -61, 67, 44, -79, 106, -86, 0, -3, 55, -115, -36, 64, 86, 28, 57, 57, 55, -61, -4, -100, 11, -38, -15, 46, -77, -55, -77, 35, 23, -123, -101, -105, 122, 86, -88, -122, 12, -110, -110, 104, 67, 5, 117, -42, 111, 102, -22, 64, 109, -106, 8, 126, -68, 108, -61, -86, 7, -5, 24, -94, 68, -69, -52, 94, 118, 115, 18, -70, -100, 15, -9, 87, -76, -59, -82, -30, -58, 31, -5, -61, -111, -9, -32, 48, 39, -79, -114, -67, -73, -125, 91, 8, -108, -43, 5, 66, -24, 50, 117, -96, -109, -63, 20, -128, 42, -74, 113, -98, 88, 57, 64, 57, -119, 106, 5, 35, 112, -57, -13, -84, -116, -120, 32, -96, 39, 102, 37, 28, -107, -16, -52, 101, -93, 8, 109, -77, -28, 9, 68, 108, 54, 25, -4, 110, -3, 86, -30, -50, 71, -60, -16, -101, -37, -10, 11, -29, 15, 86, -26, 89, 64, 15, 30, 14, -117, 61, -78, 116, 56, -34, -49, -49, -101, -42, 7, 44, -95, -13, 44, 94, -4, 10, -32, 71, 23, -74, -110, -24, 64, 116, -30, -59, -27, -98, -61, 87, -4, -115, -60, -27, -47, -53, 99, 106, -73, -80, 40, 88, -38, -40, 64, 116, -27, -29, -46, 69, -68, -7, 71, 106, 93, 106, 39, -86, 67, 66, -103, -93, 21, -109, -115, -84, 87, 120, -87, -79, 112, 42, 119, -75] + + pub_key=[-61, 57, 103, 99, -111, 94, -33, 12, -113, 32, -27, 117, -123, -57, 111, -30, 66, -98, -78, 115, 86, -85, -75, 86, -2, 26, 24, -67, -28, -93, -8, 67, -122, 67, 123, 30, 101, -39, 54, -28, 16, 122, 113, -28, 18, 2, -56, 43, 65, 122, 116, -13, -29, 85, 49, 98, 108, 126, -22, 112, 31, 18, -56, -100, 56, -64, 53, -59, 48, -67, 40, -104, -128, -31, 23, -95, 99, -60, 103, 19, 11, 115, -95, 101, -48, -13, 69, -103, -107, -52, -120, 24, -83, -72, -44, -127, 64, -90, 96, -87, 119, 104, 60, 59, 95, -71, -120, -73, -19, 117, -105, 15, -46, -69, -75, -12, 51, 110, 90, 96, 67, 35, 118, 67, -100, 20, -4, 124, -69, 122, 73, -67, -73, -28, 28, 26, -106, -80, -42, 67, 74, 74, 1, 113, 30, 67, 5, -49, 54, 102, 83, 85, 22, -49, 16, 19, -6, -11, 37, 50, -61, 98, 100, -58, 4, 48, -63, -120, -97, 105, 21, 93, -42, -49, -63, 90, 44, 49, -107, 108, 84, 37, 3, 47, -60, 15, 22, -70, -74, -19, 74, -106, -64, 48, -71, -62, 5, 92, -8, -94, -101, -3, 60, -63, 9, 82, 89, 33, 123, 33, -117, 124, -104, 0, -84, -98, 73, -59, 44, 76, 53, -52, 82, -94, 76, -49, -36, 107, 69, 119, 83, -110, 1, -59, -6, 41, -104, -7, 103, -115, -94, 32, 87, 47, 82, 5, -61, 65, 84, -28, 96, 101, 123, -95, 101, -121, -84, 53, -19, 122, -76, -32, -6, -80, 10, -110, 21, -92, 40, 98, 115, -109, 78, -49, -5, 20, -122, -100, 4, -33, -60, -119, -43, -108, -74, 90, -90, 113, 19, -94, 96, -68, 43, 5, 24, -70, 69, -49, 122, -90, -117, -23, 28, 64, 60, -57, -26, 91, 78, -94, -120, -106, -39, -91, 110, -106, 67, 13, 56, -74, -114, 22, 114, -58, -37, 90, -79, -28, 23, 56, -76, -30, 100, -102, -112, 90, 37, -111, 61, 52, -79, -112, -66, -36, -95, 57, -110, 123, 54, 36, 81, 33, 99, 11, -33, 113, -101, 39, 112, 23, -101, 102, 49, 107, -45, -124, -85, 27, 95, 19, 1, -101, -105, -73, 90, -110, -62, 87, -80, -13, 17, -127, 119, 89, -66, 75, 10, 24, -38, 119, -120, -27, 108, -70, 21, 72, 67, -89, 29, 9, 116, 104, -44, 68, -102, -98, -87, 99, 111, -61, 49, 41, 90, -86, 90, -20, 102, 27, 124, 68, 93, -87, 30, 127, -10, 65, 11, -7, -61, 127, 5, -50, 107, 27, 67, 84, 43, 81, 22, 123, -111, 20, -121, 109, -17, 98, -111, -101, -100, -66, -59, 107, 39, -103, 22, 39, -44, 101, 2, 101, -58, 39, -69, 4, 42, 119, 60, 106, -75, -70, 92, -34, -5, -121, -2, 101, -124, 11, 65, 40, 88, 83, -88, -63, -54, 47, 120, 72, -54, -51, -48, -119, -33, 103, 79, -1, -24, -70, -15, -7, 48, 39, 104, -85, -30, -55, 85, -104, -46, 41, -39, -46, 36, -114, -128, 33, -72, -72, 51, -95, -120, 76, -95, 40, -78, -116, -12, -100, 119, 101, 90, 3, -91, 103, 71, -76, -118, 81, -106, -98, 99, -59, -80, -13, 118, -123, -63, -72, -102, -118, 1, 64, -122, 108, 46, -101, -127, 92, 69, 36, 23, -106, -25, 44, -48, 84, 119, -2, 35, 32, -103, 76, 119, -24, 117, -77, 101, -52, 75, -82, 70, 6, -124, -59, -119, -69, 16, -111, 115, -46, -67, 28, 90, -65, -107, -106, -70, -69, -111, 112, 47, -58, 106, 28, -40, 67, -90, 97, 5, 110, 33, 79, 45, -58, 40, -21, 80, 108, -57, -5, -69, 66, -107, -80, 50, -41, -87, -65, 36, 25, -85, -38, 7, 105, -8, 110, -62, 58, 100, -45, 32, -78, 69, -117, -99, 102, -21, 80, -56, -14, 64, -78, 36, 127, 5, 113, -113, 29, 44, -119, -38, -62, 126, 20, 101, 66, -125, 28, 35, 108, -84, 99, 99, 28, -69, -56, 86, 62, -91, 103, 86, 56, -112, 49, 70, -11, -64, -104, -126, 96, -126, -53, 20, 15, 24, -93, -39, 10, -81, 99, 11, 8, -84, -57, -61, 45, 57, 56, -128, 85, -100, 5, 52, -55, 35, 4, 127, 44, 56, 98, -56, -15, 87, 99, 87, -57, 56, -87, 84, -69, -86, 125, 44, 16, 55, 80, 0, 27, -17, -84, 53, 101, -77, -92, -8, 42, -55, -45, -63, 107, -128, 118, 38, 14, -42, -125, 103, -105, 6, 5, -21, -78, -2, 44, 63, -120, 10, 101, -6, -74, -112, 33, 81, -90, 90, -125, 11, 51, -9, 111, 7, 106, 13, -59, -104, 75, 118, -125, 89, 38, 73, 21, -85, 91, -58, 71, 0, 42, 1, -38, 116, -16, -53, 44, -97, 64, -124, -36, -36, -108, -114, 114, -102, 38, 0, 82, 113, 92, 14, 45, 58, 77, 49, -112, -110, -91, 8, 84, -69, -37, -61, 113, -111, -69, -44, -59, 76, -128, 59, 60, 36, 120, -128, -72, -40, 92, 100, 71, 68, 107, -48, -99, -126, -108, -108, 106, -59, 38, 31, 49, -92, 107, 105, -126, 45, -79, -74, 64, -89, 122, -119, -37, 119, -119, -112, 122, -117, 108, 69, 106, -52, 26, -118, 108, 103, -59, 120, -128, 14, -55, 116, 70, -92, -102, -38, -38, 100, 32, -103, -108, -75, -108, -55, 3, 112, 70, -15, -46, 17, -57, 17, -74, -60, -70, 119, -123, -84, 105, 64, 21, 28, 11, 10, -96, -118, -54, -110, 114, -79, 113, -56, 26, 73, -121, -71, 19, -106, -45, -66, -77, 71, 83, -71, 44, -71, -100, -45, 105, -9, 84, -105, 100, -4, -103, 5, 114, 43, -24, 81, -108, -26, -38, -88, -67, 12, 9, -105, -14, -68, 85, -120, -54, 60, 101, 104, -88, 119, 80, 13, -74, 90, 31, -28, 65, 37, -16, 114, 35, 44, 87, 46, 92, 60, -70, 16, 35, -29, -43, 70, 34, 58, -115, -48, 96, -66, 7, 8, -115, 96, -127, -80, -2, -12, 53, -61, -117, -122, 75, -6, 83, 103, 4, -99, -6, -91, 20, -109, 42, 92, 110, 85, -78, 3, 43, -112, 72, 120, -70, -19, 68, 13, -78, 59, 104, 70, 49, 114, -49, 74, -94, -51, 57, 93, -83, 23, 6, 102, 70, 88, 111, 76, 86, -66, 120, -49, 13, -30, -83, 13, 18, 27, -1, -56, -81, 84, 28, -102, -41, -118, 67, -94, -6, 2, -66, -29, 98, 31, -72, 114, -109, -123, 39, -65, -117, -80, -24, -15, -106, 48, 59, 75, -121, 33, -116, -70, -75, -121, 31, -10, 50, -49, 38, 74, 119, -74, -69, 15, 72, -123, -42, 96, -62, -123, -13, 75, 51, -42, 71, -56, 119, -99, -32, -39, 63, -10, 97, -70, 27, -29, 114, 23, 106, 17, 95, 27, 15, 57, -123, 105, 11, 76, -101, -86, -9, 16, -4, 55, -73, -41, -40, 26, 50, 24, -72, 56, 43, 58, -84, -108, -96, -18, -101, 72, 98, -11, -86, 97, 60, -105, -59, 12, 113, -33, -105, -120, 10, 44, -105, 48, 84, -64, 96, 91, 67, -8, 99, 108, -71, 37, -74, -73, 54, 82, -100, 116, 64, -33, 16, -61, -53, 88, 11, -59, 34, 17, 91, 96, 83, 47, -21, 9, 93, 102, 79, 15, 86, -99, 116, -57, 19, -65, -68, 50, -120, -124, -111, -12, 64, 28, 74, -54, 25, -101, 35, 82, 85, -80, 46, -28, -57, -126, 25, -61, -92, -52, 81, 58, -63, -94, -119, -47, 108, 23, -21, -108, 110, -109, 34, 4, -56, -96, 67, 77, 3, 124, -40, -46, -122, -43, -48, 94, 21, -7, 51, -53, 105, 92, 38, -122, 3, -2, -119, 48, 111, 35, 53, 33, 5, 85, 15, 58, -65, -120, -109, 35, 92, 112, -124, -35, 34, 4, 25, -71, -85, -46, -14, 42, -70, 12, -121, 43, 7, 28, -36, -121, -105, -44, 8, 39, 1, -119, 87, 113, -12, 9, 126, 108, 111, 117, -4, 97, -101, -73, 115, -37, -75, 78, -56, 18, -93, 114, 75, 77, 91, -11, 71, 82, -76, 100, -32, 74, 33, 20, -9, -77, 10, 7, 102, -28, 6, -107, -62, -25, -104, 36, 6, -98, -92, -94, 66, 1, -75, -78, -114, 122, -81, -53, 8, -95, 59, -72, 100, -61, 67, 44, -79, 106, -86, 0, -3, 55, -115, -36, 64, 86, 28, 57, 57, 55, -61, -4, -100, 11, -38, -15, 46, -77, -55, -77, 35, 23, -123, -101, -105, 122, 86, -88, -122, 12, -110, -110, 104, 67, 5, 117, -42, 111, 102, -22, 64, 109, -106, 8, 126, -68, 108, -61, -86, 7, -5, 24, -94, 68, -69, -52, 94, 118, 115, 18, -70, -100, 15, -9, 87, -76, -59, -82, -30, -58, 31, -5, -61, -111, -9, -32, 48, 39, -79, -114, -67, -73, -125, 91, 8, -108, -43, 5, 66, -24, 50, 117, -96, -109, -63, 20, -128, 42, -74, 113, -98, 88, 57, 64, 57, -119, 106, 5, 35, 112, -57, -13, -84, -116, -120, 32, -96, 39, 102, 37, 28, -107, -16, -52, 101, -93, 8, 109, -77, -28, 9, 68, 108, 54, 25, -4, 110, -3, 86, -30, -50, 71, -60, -16, -101, -37, -10, 11, -29, 15, 86, -26, 89, 64, 15, 30, 14, -117, 61, -78, 116, 56, -34, -49, -49, -101, -42, 7, 44] # Encrypt AES session key with Kyber public key - encrypted_session_key, _ = kem_encaps512(pub_key) - print("AES session key encrypted with Kyber public key.") + loading_message("Encrypting AES session key with Kyber public key...", duration=0.1) + shared_secret, cipher = kem_encaps1024(pub_key) + print("AES session key encrypted with Kyber public key.\n") + + # Get Symmetric key for AES + loading_message("AES session key...", duration=0.1) + aes_key = convert_to_bytes(shared_secret) + print("AES session key generated.\n") # Encrypt a sample message with AES + loading_message("Encrypting message with AES...", duration=0.1) message = b"Hello, this is a test message!" encrypted_message = aes_encrypt(message, aes_key) - print("Message encrypted with AES.") - - # Decrypt AES session key with Kyber private key - decrypted_aes_key = kem_decaps512(priv_key, encrypted_session_key) - print("AES session key decrypted with Kyber private key.") - - # Decrypt the message with the decrypted AES key - decrypted_message = aes_decrypt(encrypted_message, decrypted_aes_key) - print("Message decrypted with AES.") + print("Message encrypted with AES.\n") - # Check if the original message and decrypted message are the same - assert message == decrypted_message, "Decryption failed: original and decrypted messages do not match!" - print("Encryption and decryption test passed!") + print("Original Message=", message) + print("Encrypted Message=", encrypted_message) if __name__ == "__main__": test_encryption() diff --git a/tests/test_file_utils.py b/tests/test_file_utils.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/key_generation.py b/tests/test_key_generation.py similarity index 100% rename from src/key_generation.py rename to tests/test_key_generation.py diff --git a/tests/test_key_management.py b/tests/test_key_management.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..0f95119 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,65 @@ +import time +from tqdm import tqdm +from Crypto.Cipher import AES +from Crypto.Util.Padding import pad, unpad +from src.key_management import generate_kyber_keypair, encrypt_session_key, decrypt_session_key +from src.encryption import generate_aes_key, aes_encrypt +from src.decryption import aes_decrypt + + +# Convert list of signed integers to bytes +def convert_to_bytes(signed_int_list): + return bytes([x & 0xFF for x in signed_int_list]) + +def loading_message(message, duration=0.1): + """Simulate a loading process with a message and duration.""" + print(message) + for _ in tqdm(range(100), desc=message, ncols=100, ascii=True, bar_format='{l_bar}{bar} | {percentage:3.0f}%'): + time.sleep(duration / 100) + print() + +def test_main(): + # Generate Kyber key pair + loading_message("1. Generating Kyber key pair...") + priv_key, pub_key = generate_kyber_keypair() + print("Kyber key pair generated.\n") + + + # Encrypt AES session key with Kyber public key + loading_message("2. Encrypting session key with Kyber public key...") + shared_secret, cipher = encrypt_session_key(pub_key) + print("AES session key encrypted with Kyber public key.\n") + + # Get Symmetric key for AES + loading_message("3. AES session key...") + aes_key = convert_to_bytes(shared_secret) + print("AES session key generated.\n") + + # Encrypt a sample message with AES + loading_message("Encrypting message with AES...") + message = b"Hello, this is a test message!" + encrypted_message = aes_encrypt(message, aes_key) + print("Message encrypted with AES.\n") + + # Decrypt AES session key with Kyber private key + loading_message("Decrypting AES symmetric key with Kyber private key and cipher text...") + decrypted_aes_key = decrypt_session_key(priv_key, cipher) + print("AES session key decrypted with Kyber private key.\n") + + # Decrypt the message with the decrypted AES key + loading_message("Decrypting message with AES...") + decrypted_message = aes_decrypt(encrypted_message, convert_to_bytes(decrypted_aes_key)) + print("Message decrypted with AES.\n") + + # Check if the original message and decrypted message are the same + assert message == decrypted_message, "Decryption failed: original and decrypted messages do not match!" + print("Encryption and decryption test passed!") + + print("Original Message:", message) + print("Decrypted Message:", decrypted_message) + print("***TEST***=",message==decrypted_message) + +if __name__ == "__main__": + loading_message("***This is the general test for Encryption and DEcryption using Kyber and AES.***", duration=1) + test_main() + print("Test completed successfully!") \ No newline at end of file diff --git a/tests/test_pqc_multipath.py b/tests/test_pqc_multipath.py new file mode 100644 index 0000000..64d5a10 --- /dev/null +++ b/tests/test_pqc_multipath.py @@ -0,0 +1,52 @@ +import os +from src.encryption import generate_aes_key, aes_encrypt +from src.decryption import aes_decrypt +from src.key_management import generate_kyber_keypair, encrypt_session_key, decrypt_session_key +from tqdm import tqdm +import time + +def loading_message(message, duration=0.1): + """Simulate a loading process with a message and duration.""" + print(message) + for _ in tqdm(range(100), desc=message, ncols=100, ascii=True, bar_format='{l_bar}{bar} | {percentage:3.0f}%'): + time.sleep(duration / 100) + print() + +folder_path = '/Users/abhisekjha/Multipath_Research/PQC/pqc_aes_multipath/data/input' +files = os.listdir(folder_path) + + + +def convert_to_bytes(signed_int_list): + return bytes([x & 0xFF for x in signed_int_list]) + +def pqc_multipath(): + + loading_message("0. Reading Encoded Message from Input folder") + for file_name in files: + file_path = os.path.join(folder_path, file_name) + with open(file_path, 'rb') as file: + M = file.read() + + + #kyber keys + loading_message("1. Generating Kyber Key Pair") + private_key, public_key = generate_kyber_keypair() + + aes_key, cipher= encrypt_session_key(public_key) + + loading_message("2. Encrypt the message") + encrypted_message = aes_encrypt(M, convert_to_bytes(aes_key)) + + + loading_message("3. Decrypt the aes key with kyber private key") + decrypted_aes_key = decrypt_session_key(private_key, cipher) + + loading_message("4. Decrypt the message") + decrypted_message = aes_decrypt(encrypted_message, convert_to_bytes(decrypted_aes_key)) + + print("***Is Original Message and Decrypted Message SAME***??=>", M == decrypted_message) + +if __name__== "__main__": + pqc_multipath() + print("PQC Multipath Done") \ No newline at end of file diff --git a/tests/test_pqcrypto.py b/tests/test_pqcrypto.py deleted file mode 100644 index 7226087..0000000 --- a/tests/test_pqcrypto.py +++ /dev/null @@ -1,18 +0,0 @@ -from ccakem import kem_keygen512, kem_encaps512, kem_decaps512 - -# Generate Kyber key pairs -private_key, public_key = kem_keygen512() - -# Generate a random session key -session_key = b"this is a test session key" - -# Encrypt the session key using the public key -ciphertext, encapsulation = kem_encaps512(public_key, session_key) - -# Decrypt the session key using the private key -decrypted_session_key = kem_decaps512(private_key, ciphertext) - -# Verify the decryption -print("Original session key: ", session_key) -print("Decrypted session key:", decrypted_session_key) -print("Decryption successful:", session_key == decrypted_session_key)