#!/usr/bin/env python3

import rsa
from rsa import PrivateKey

import json

"""
{
  "algorithm" : "RSAES-PKCS1-v1_5",
  "generatorVersion" : "0.8r12",
  "numberOfTests" : 65,
  "header" : [
    "Test vectors of type RsaesPkcs1Decrypt are intended to check the decryption",
    "of RSA encrypted ciphertexts."
  ],
  "notes" : {
    "InvalidPkcs1Padding" : "This is a test vector with an invalid PKCS #1 padding. Implementations must ensure that different error conditions cannot be distinguished, since the information about the error condition can be used for a padding oracle attack. (RFC 8017 Section 7.2.2)"
  },
  "schema" : "rsaes_pkcs1_decrypt_schema.json",
  "testGroups" : [
    {
      "d" : "00d3519bd86edf5dbe9c64a3781713dd049b747f5651fd918cce8a9b80b6d6a2fb6aab334ab569a89b58982e0aae373090299fa227f9652b802d23ee5ca6824c433d01d40bb0473b16190a8bfb137c0a704b4f49b45015bfbee1f670446f07595259d70c7d79ae95f9b2543b0162ebb763ebb81c4b6edff9d197dede1dbe57e40466d156d4dfd5d7634c45534fb2bbbd1bf257817a173c0795fdbcc533976f4a0d04160f299af5dc272a814b36d5bae5116b9542178f1d554cab7a6453035482b981add4bd8ffd5d500839b23e30ebd3f3868f07584cbd12ba089325982860f69f2bdc7077b6c60f58a2272823379e1023704165f7c14f64a18fd5b245a18149b7eda3385a56ba9e79502a27bf13865cde35be15de03d06aa6f08b172b7eeb4b73cbc157019c5d933584a8d1add61b7dbca3b253ca0cf93dc9a8a3aac2f50227022e692f7b4767556620cc928d63e31078c360e2ab4b71a917e19e7eb09380482e5b4ea88202871c2a29ca6f66b2fe304af609520e4f81d64c26768bb812a86679366611f4cf6e89e2bd1d9d7e28729c7f0e4e3152d7ad7f186fa32f01e169ff06a12001bc179dfd0dc942cbabc555f67f5fd043e0a3354340fa490d2f123367be926eb3e1dffe70c3151c87450f3217dc2aa0b5a7069c5a17d55614c9994139f7b37b49e9fe780af65a0e89e2e58feaaffe163bc9d19eafd9cd29b0ef3cef3d01",
      "e" : "010001",
      "keysize" : 4096,
      "n" : "00f601be0dccd04aa40b12f3f191ae17c1f9c8c0b68e7a77e14be25c3c7907cb1d33a6ef418ef41852f32c98392bc5c9aed91c1a1501c503eab89b3ee6f4f8eb2e0fcfc41bd03609cf6a8eb3aa6f0fbe23187b33db4d34b66d128a8aba0a2abf40bb9d13d8e2554569a57ab1d8c61b8cad2dc88599ae0da5346e15dace1bac7bf69737c22f083be9b46bb8b1eab5957b2da740275e96c87195b96fe11452159dafcfd916cee5d749a77bc3905a5ebd387ae445e8fe70f16e9a086639779ceffbfd41557bd99aea6a371a6b4b160615a1a12bc6958d34bce0c85adcbd8392fa10ceca52209d56196ba3d273ce228f1f111192aa92de2a039798a17bcecb4dc6100e6f8ae8c2643f2ae768b2255f082c978e95ca551555f10608231cf8003bbf807969fff1e51914b9a8c9b8f4564645b9e5d705ffad29663f5dae3d76652b422e43f13e6c1491090805c2d1268a74a251177427e33a9a91175c3670b91746008bce1fd231e6e4f2ad70cb43aca5f07600a6d31dd02915243dfdd943a02165da367a6b7e4dae1dd2e8b836903080795d2585076cc1c15dd9e8d2e5e047526569b1bfd395d957eb9fde325d342d14426e71efdc1887515e53cdea5834921f928629e748eed097ac4024e2bf255d70411f87373948cf8e8aa7effa2b0ab47d5166091e1aedec60568b155bd9c27bc55f3ece35f83d636dbcd5abf4853a051db94d5045",
      "privateKeyJwk" : {
        "alg" : "RSA1_5",
        "d" : "01Gb2G7fXb6cZKN4FxPdBJt0f1ZR_ZGMzoqbgLbWovtqqzNKtWmom1iYLgquNzCQKZ-iJ_llK4AtI-5cpoJMQz0B1AuwRzsWGQqL-xN8CnBLT0m0UBW_vuH2cERvB1lSWdcMfXmulfmyVDsBYuu3Y-u4HEtu3_nRl97eHb5X5ARm0VbU39XXY0xFU0-yu70b8leBehc8B5X9vMUzl29KDQQWDyma9dwnKoFLNtW65RFrlUIXjx1VTKt6ZFMDVIK5ga3UvY_9XVAIObI-MOvT84aPB1hMvRK6CJMlmChg9p8r3HB3tsYPWKInKCM3nhAjcEFl98FPZKGP1bJFo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id" : "none",
        "kty" : "RSA",
        "n" : "9gG-DczQSqQLEvPxka4XwfnIwLaOenfhS-JcPHkHyx0zpu9BjvQYUvMsmDkrxcmu2RwaFQHFA-q4mz7m9PjrLg_PxBvQNgnPao6zqm8PviMYezPbTTS2bRKKiroKKr9Au50T2OJVRWmlerHYxhuMrS3IhZmuDaU0bhXazhuse_aXN8IvCDvptGu4seq1lXstp0AnXpbIcZW5b-EUUhWdr8_ZFs7l10mne8OQWl69OHrkRej-cPFumghmOXec7_v9QVV72Zrqajcaa0sWBhWhoSvGlY00vODIWty9g5L6EM7KUiCdVhlro9JzziKPHxERkqqS3ioDl5ihe87LTcYQDm-K6MJkPyrnaLIlXwgsl46VylUVVfEGCCMc-AA7v4B5af_x5RkUuajJuPRWRkW55dcF_60pZj9drj12ZStCLkPxPmwUkQkIBcLRJop0olEXdCfjOpqRF1w2cLkXRgCLzh_SMebk8q1wy0OspfB2AKbTHdApFSQ9_dlDoCFl2jZ6a35Nrh3S6Lg2kDCAeV0lhQdswcFd2ejS5eBHUmVpsb_TldlX65_eMl00LRRCbnHv3BiHUV5TzepYNJIfkoYp50ju0JesQCTivyVdcEEfhzc5SM-Oiqfv-isKtH1RZgkeGu3sYFaLFVvZwnvFXz7ONfg9Y2281av0hToFHblNUEU",
        "p" : "_CG4VcWtTKK2lwUWQG9xxuee_EEm5lmHctseCC3msN3aqiopUfBBSOhuC94oITt_YA-YcwgwHqzqE0Biuww932KNqav5PvHOPnWwlTpITb01VL1cBkmTPdd-UnVj6Q8FqAE_3ayVjDKTeOlDA7MEvl-d8f5bBDp_3ZRwCj8LHLvQUWt82UxXypbZ_SqMqXOZEhjLozocI9gQ91GdH3cCq3Kv_bP4ShsqiBFuQDO8TQz8eYnGV-D-lOlkR2rli65reHbzbAnTKxpj-MR8lKdMku7fdfwnz_4PhFI2PkvI92U_PLVer2k87HDRPIdd6TWosgQ5q36T92mBxZV_xbtE2Q",
        "q" : "-cf3SKUF0j7O-ahfgJfIz31wKO9skOI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EBALYdhP+TSk5DexbuG0uf30rhM3C1OFveelRkoSPAND31dfnhKO+d\n+UQjDTnMnPXcDtsot+dAtp7wJMG/7jn81TQP+uoAEBYMU13Akg582BvlM9APpVSh\n/E0+AsRhVp9efKeH8VFe30WxlrdZiE3mUsONWTTPklJOgHtNO1kLw5vEF+5Ihadh\n0o3a3ObI/bO5YdPn/UgGTfk0CpZ/i3mZdDiEH0hXmkdt21UIjDCPaPKynQHGWXpa\nfI0GYoT2PjemjDh5wyqjg2Z1/Q6ycZiDqRlEVh6d1+iqa7FxV/CMSPjm+uXD5aK7\na11YDuxsl93Nm+CknvKDpwMa16uo1DjfTpUCggEAIvuOX82bdnEE5xJE21MFjBgG\nHhsNH2O3Pi1ZqV4qEM2HQmoz2hPCh83vgTbl5H6T+5swrZJiintUP0jrARqGNWqz\ny0gPJ+ORsBjKGH2Xrz2C4xhh7K+mY9t4qonDvUaOaq3vs6Q/eLwAuAFMldtU6dIa\nAX6PIfZxVF7d6all6jLf/0XNo3/KGqUTL2yO7SIr0B/tWm59Y5WAxZVXd6hlRMLE\nyTm9uLTEht2lMHKGGgM0NZvbN1hHXknZDQU5lE54z8/Y//Vbsxoc68ZbKPUeeQcB\nsveRIYiYTwNObpbhxSUeM/44+yIbznqQqGhXxfVrbKdzB8RdUpCx8Iit4IKzSQ==\n-----END RSA PRIVATE KEY-----",
      "privateKeyPkcs8" : " ",
      "type" : "RsaesPkcs1Decrypt",

        {
          "tcId" : 31,
          "comment" : "prepended bytes to ciphertext",
          "msg" : "54657374",
          "ct" : "000004327a40b02bf671557124f963a57b3860e92cff62c439c0425b48b4346fc60c0ebf7a7584f94d34450d20cbd877c8d5dca12f517b486c2cccb8e1f467276ac03aadc94a97fcd224994d81672eb577cf0bbd6aa948d3dc4d7f06456f6650e5620435c078787db0f36124b292349ebe011ce54b3e932fac6525a37c793846a4f08ac3694d649f4a04e24e1f5e50f11a0492a68a509cf30e565ceb9931565b4aa5c3514b2ba87c4c0937ebcd6bb2b8248abb0970d30480059daea4c6ae556f6e91b25ffa5a4f723a9bf98a0bff668a1f0c799d3b0c85b19190dbfb5d894f84fa5d72d261dd2c09013dc0981cd0c46d7a08710801590aac8ff17b237387427ab3c6d6f2a59434b37f123bc7fc0a83d5ca5793540cba582e41b262859d36eabd0aa8203ca05d4c16aaf2a7b2bc7f251497d4c8f8654deae3cfffc5d3599ab4779585bf1673196782075a91ee7c3296a2edc6ee6c30344dd0c0a82274ae17982eeb23eca5c39c7d11a2dd171c70108b0a33164fc175425586f714deb5552e90e561f7882211d3f01c07867256d0cca511e61b0cb51189d8e5124e8cacdab6042bd421447ffa7fe6cad8e7f17dd3e599bae061f85bb5181726d1c0c5bbf2c2a5c1e60f486a81782e58d90ccd5a769f98361765441de142bb0a7f7bd406a537d5be0c2773e847b1df1d49ac1daa963feec84954b72a695b74281159647a62a3c19acdda",
          "result" : "invalid",
          "flags" : []
        },


"""

print("\nTest with prepended bytes to ciphertext\n")

privateKeyPem = "-----BEGIN RSA PRIVATE KEY-----\nMIIJKgIBAAKCAgEA9gG+DczQSqQLEvPxka4XwfnIwLaOenfhS+JcPHkHyx0zpu9B\njvQYUvMsmDkrxcmu2RwaFQHFA+q4mz7m9PjrLg/PxBvQNgnPao6zqm8PviMYezPb\nTTS2bRKKiroKKr9Au50T2OJVRWmlerHYxhuMrS3IhZmuDaU0bhXazhuse/aXN8Iv\nCDvptGu4seq1lXstp0AnXpbIcZW5b+EUUhWdr8/ZFs7l10mne8OQWl69OHrkRej+\ncPFumghmOXec7/v9QVV72Zrqajcaa0sWBhWhoSvGlY00vODIWty9g5L6EM7KUiCd\nVhlro9JzziKPHxERkqqS3ioDl5ihe87LTcYQDm+K6MJkPyrnaLIlXwgsl46VylUV\nVfEGCCMc+AA7v4B5af/x5RkUuajJuPRWRkW55dcF/60pZj9drj12ZStCLkPxPmwU\nkQkIBcLRJop0olEXdCfjOpqRF1w2cLkXRgCLzh/SMebk8q1wy0OspfB2AKbTHdAp\nFSQ9/dlDoCFl2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5vEF+5Ihadh\n0o3a3ObI/bO5YdPn/UgGTfk0CpZ/i3mZdDiEH0hXmkdt21UIjDCPaPKynQHGWXpa\nfI0GYoT2PjemjDh5wyqjg2Z1/Q6ycZiDqRlEVh6d1+iqa7FxV/CMSPjm+uXD5aK7\na11YDuxsl93Nm+CknvKDpwMa16uo1DjfTpUCggEAIvuOX82bdnEE5xJE21MFjBgG\nHhsNH2O3Pi1ZqV4qEM2HQmoz2hPCh83vgTbl5H6T+5swrZJiintUP0jrARqGNWqz\ny0gPJ+ORsBjKGH2Xrz2C4xhh7K+mY9t4qonDvUaOaq3vs6Q/eLwAuAFMldtU6dIa\nAX6PIfZxVF7d6all6jLf/0XNo3/KGqUTL2yO7SIr0B/tWm59Y5WAxZVXd6hlRMLE\nyTm9uLTEht2lMHKGGgM0NZvbN1hHXknZDQU5lE54z8/Y//Vbsxoc68ZbKPUeeQcB\nsveRIYiYTwNObpbhxSUeM/44+yIbznqQqGhXxfVrbKdzB8RdUpCx8Iit4IKzSQ==\n-----END RSA PRIVATE KEY-----"
private_key = PrivateKey.load_pkcs1(privateKeyPem, format='PEM')

ct = bytes.fromhex("000004327a40b02bf671557124f963a57b3860e92cff62c439c0425b48b4346fc60c0ebf7a7584f94d34450d20cbd877c8d5dca12f517b486c2cccb8e1f467276ac03aadc94a97fcd224994d81672eb577cf0bbd6aa948d3dc4d7f06456f6650e5620435c078787db0f36124b292349ebe011ce54b3e932fac6525a37c793846a4f08ac3694d649f4a04e24e1f5e50f11a0492a68a509cf30e565ceb9931565b4aa5c3514b2ba87c4c0937ebcd6bb2b8248abb0970d30480059daea4c6ae556f6e91b25ffa5a4f723a9bf98a0bff668a1f0c799d3b0c85b19190dbfb5d894f84fa5d72d261dd2c09013dc0981cd0c46d7a08710801590aac8ff17b237387427ab3c6d6f2a59434b37f123bc7fc0a83d5ca5793540cba582e41b262859d36eabd0aa8203ca05d4c16aaf2a7b2bc7f251497d4c8f8654deae3cfffc5d3599ab4779585bf1673196782075a91ee7c3296a2edc6ee6c30344dd0c0a82274ae17982eeb23eca5c39c7d11a2dd171c70108b0a33164fc175425586f714deb5552e90e561f7882211d3f01c07867256d0cca511e61b0cb51189d8e5124e8cacdab6042bd421447ffa7fe6cad8e7f17dd3e599bae061f85bb5181726d1c0c5bbf2c2a5c1e60f486a81782e58d90ccd5a769f98361765441de142bb0a7f7bd406a537d5be0c2773e847b1df1d49ac1daa963feec84954b72a695b74281159647a62a3c19acdda")
pt = bytes.fromhex("54657374")

try:
  message = rsa.decrypt(ct, private_key)
except:
  print("[*] Invalid decryption")
else:
  print("[!] No errors in decryption")
  print("message == pt?", message == pt)

print("\nTest with original ciphertext\n")

privateKeyPem = "-----BEGIN RSA PRIVATE KEY-----\nMIIJKgIBAAKCAgEA9gG+DczQSqQLEvPxka4XwfnIwLaOenfhS+JcPHkHyx0zpu9B\njvQYUvMsmDkrxcmu2RwaFQHFA+q4mz7m9PjrLg/PxBvQNgnPao6zqm8PviMYezPb\nTTS2bRKKiroKKr9Au50T2OJVRWmlerHYxhuMrS3IhZmuDaU0bhXazhuse/aXN8Iv\nCDvptGu4seq1lXstp0AnXpbIcZW5b+EUUhWdr8/ZFs7l10mne8OQWl69OHrkRej+\ncPFumghmOXec7/v9QVV72Zrqajcaa0sWBhWhoSvGlY00vODIWty9g5L6EM7KUiCd\nVhlro9JzziKPHxERkqqS3ioDl5ihe87LTcYQDm+K6MJkPyrnaLIlXwgsl46VylUV\nVfEGCCMc+AA7v4B5af/x5RkUuajJuPRWRkW55dcF/60pZj9drj12ZStCLkPxPmwU\nkQkIBcLRJop0olEXdCfjOpqRF1w2cLkXRgCLzh/SMebk8q1wy0OspfB2AKbTHdAp\nFSQ9/dlDoCFl2jZ6a35Nrh3S6Lg2kDCAeV0lhQdswcFd2ejS5eBHUmVpsb/TldlX\n65/eMl00LRRCbnHv3BiHUV5TzepYNJIfkoYp50ju0JesQCTivyVdcEEfhzc5SM+O\niqfv+isKtH1RZgkeGu3sYFaLFVvZwnvFXz7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YDuxsl93Nm+CknvKDpwMa16uo1DjfTpUCggEAIvuOX82bdnEE5xJE21MFjBgG\nHhsNH2O3Pi1ZqV4qEM2HQmoz2hPCh83vgTbl5H6T+5swrZJiintUP0jrARqGNWqz\ny0gPJ+ORsBjKGH2Xrz2C4xhh7K+mY9t4qonDvUaOaq3vs6Q/eLwAuAFMldtU6dIa\nAX6PIfZxVF7d6all6jLf/0XNo3/KGqUTL2yO7SIr0B/tWm59Y5WAxZVXd6hlRMLE\nyTm9uLTEht2lMHKGGgM0NZvbN1hHXknZDQU5lE54z8/Y//Vbsxoc68ZbKPUeeQcB\nsveRIYiYTwNObpbhxSUeM/44+yIbznqQqGhXxfVrbKdzB8RdUpCx8Iit4IKzSQ==\n-----END RSA PRIVATE KEY-----"
private_key = PrivateKey.load_pkcs1(privateKeyPem, format='PEM')

ct = bytes.fromhex("04327a40b02bf671557124f963a57b3860e92cff62c439c0425b48b4346fc60c0ebf7a7584f94d34450d20cbd877c8d5dca12f517b486c2cccb8e1f467276ac03aadc94a97fcd224994d81672eb577cf0bbd6aa948d3dc4d7f06456f6650e5620435c078787db0f36124b292349ebe011ce54b3e932fac6525a37c793846a4f08ac3694d649f4a04e24e1f5e50f11a0492a68a509cf30e565ceb9931565b4aa5c3514b2ba87c4c0937ebcd6bb2b8248abb0970d30480059daea4c6ae556f6e91b25ffa5a4f723a9bf98a0bff668a1f0c799d3b0c85b19190dbfb5d894f84fa5d72d261dd2c09013dc0981cd0c46d7a08710801590aac8ff17b237387427ab3c6d6f2a59434b37f123bc7fc0a83d5ca5793540cba582e41b262859d36eabd0aa8203ca05d4c16aaf2a7b2bc7f251497d4c8f8654deae3cfffc5d3599ab4779585bf1673196782075a91ee7c3296a2edc6ee6c30344dd0c0a82274ae17982eeb23eca5c39c7d11a2dd171c70108b0a33164fc175425586f714deb5552e90e561f7882211d3f01c07867256d0cca511e61b0cb51189d8e5124e8cacdab6042bd421447ffa7fe6cad8e7f17dd3e599bae061f85bb5181726d1c0c5bbf2c2a5c1e60f486a81782e58d90ccd5a769f98361765441de142bb0a7f7bd406a537d5be0c2773e847b1df1d49ac1daa963feec84954b72a695b74281159647a62a3c19acdda")
pt = bytes.fromhex("54657374")

try:
  message = rsa.decrypt(ct, private_key)
except:
  print("[*] Invalid decryption")
else:
  print("[!] No errors in decryption")
  print("message == pt?", message == pt)
