Prof. Pellegrino has dropped his challenge on the website and added another. So I think it's okay to publicize this solution.
Last active
February 2, 2023 18:24
-
-
Save kargaranamir/705e32e27bbd6393f330206bf7b76f73 to your computer and use it in GitHub Desktop.
cispa-prof-pellegrino-challenge.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "CISPA-Challenges.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"authorship_tag": "ABX9TyPMET+Cne/CUOLgQanzaTMW", | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/kargaranamir/705e32e27bbd6393f330206bf7b76f73/cispa-prof-pellegrino-challenge.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"## Challenge 1\n", | |
"Base64 decode.\n" | |
], | |
"metadata": { | |
"id": "36UJkbyO1UGR" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import base64" | |
], | |
"metadata": { | |
"id": "onHMS29RDkBU" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"id": "2j40X-mIwCg_" | |
}, | |
"outputs": [], | |
"source": [ | |
"string_ch1 = \"\"\"Q29uZ3JhdHVsYXRpb24hIFlvdSBzb2x2ZWQgdGhlIGNoYWxsZW5nZSBudW1iZXIgMS4gQWZ0ZXIgeW91ciBoYXZlIHN1Ym1pdHRlZCB5b3VyIGFwcGxpY2F0aW9uIGRvY3VtZW50cyB0aHJvdWdoIHRoZSBDSVNQQSBwb3J0YWwsIHNlbmQgYW4gZW1haWwgdG8gcGVsbGVncmlub0BjaXNwYS5kZS4gVGhlIHN1YmplY3Qgb2YgdGhlIGVtYWlsIG11c3QgYmUgdGhlIHN0cmluZyB0b2tlbiBQSUVDRS1PRi1DQUtFIGZvbGxvd2VkIGJ5IHlvdXIgbmFtZS4gRm9yIGV4YW1wbGUsIGlmIHlvdSBuYW1lIGlzIEpvaG4gRG9lLCB0aGUgc3ViamVjdCB3aWxsIGJlIHRoZSBzdHJpbmcgIlBJRUNFLU9GLUNBS0UgSm9obiBEb2UiLiBUaGVuLCB5b3UgbXVzdCBhZGQgdG8gdGhlLi4uIHNlZSB0aGUgbmV4dCBjaGFsbGVuZ2UgOyk=\"\"\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"encode_bytes_ch1 = string_ch1.encode('ascii')\n", | |
"message_bytes_ch1 = base64.b64decode(encode_bytes_ch1)\n", | |
"message_ch1 = message_bytes_ch1.decode('ascii')\n", | |
"message_ch1" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 71 | |
}, | |
"id": "a8igdym_zxa_", | |
"outputId": "d8eabec3-ab14-4afa-d344-8e60fff36aba" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"'Congratulation! You solved the challenge number 1. After your have submitted your application documents through the CISPA portal, send an email to [email protected]. The subject of the email must be the string token PIECE-OF-CAKE followed by your name. For example, if you name is John Doe, the subject will be the string \"PIECE-OF-CAKE John Doe\". Then, you must add to the... see the next challenge ;)'" | |
], | |
"application/vnd.google.colaboratory.intrinsic+json": { | |
"type": "string" | |
} | |
}, | |
"metadata": {}, | |
"execution_count": 143 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"## Challenge 2\n", | |
"Combination of Base32 and Base64 decodes." | |
], | |
"metadata": { | |
"id": "oHo1UJoi09eX" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import base64" | |
], | |
"metadata": { | |
"id": "9RShT9fIDi8M" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"string_ch2 = \"\"\"MRQXIYJ2ORSXQ5BPNB2G23B3MJQXGZJWGQWFAR3IGBRFO5ZLKBDWQ3CZK5ISWUCDHFXVUV2GNNIGU6DJMIZFENKQNJ4G6TKUGVCGCR2GONREOVTVLIZFKZ2NNJ3XMYKEIUVVASCBFNITEOLVLIZUU2DEJBLHGWKYKJYGEMRUNBEUM3DWMRJUE6TCGJ4DEWSXKFTWIR3INREUOTTPLFLXQ422K42W4WSTIJ2WIVZRNFNFQSLHJVUTIZ2UNU4TGTCDII2WEM2VM5RFQVT2MRBUE2C2I5IWOZCHNBWESSCOGBRW23DVLJ4UEMDCGJ2GYYTJIJGVEVSRORKXSMKTKQYE4TCJI5DDASKIKJXVUU2CNRRG2ULHMIZFSZ3EI5UGYSKIJYYVS3LQNRMTGULVKBBTS52QNJ3XMWLNHFVWKVBUHBGDE2BQMJLXOKY=\"\"\"" | |
], | |
"metadata": { | |
"id": "sjFbiDfj1gEY" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"string_ch2.isupper()" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "ZD-8yfkB6H7f", | |
"outputId": "863ea0ab-da7e-4b9e-96d2-df1a6f6de257" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 146 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"for i in ['O', '0', 'I', '1']:\n", | |
" if i in string_ch2:\n", | |
" print(f\"{i} is in string\")" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "SoN_zOv_6Li0", | |
"outputId": "79e884a5-4371-463e-d8e6-19a00a449337" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"O is in string\n", | |
"I is in string\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"encode_bytes_ch2 = string_ch2.encode(\"UTF-8\")\n", | |
"message_bytes_ch2 = base64.b32decode(string_ch2)\n", | |
"message_ch2 = message_bytes_ch2.decode('ascii')\n", | |
"message_ch2" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 53 | |
}, | |
"id": "itFM3MZO1qny", | |
"outputId": "bcd73cf4-64e7-46de-a09e-f1b27ee8abd7" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"'data:text/html;base64,PGh0bWw+PGhlYWQ+PC9oZWFkPjxib2R5PjxoMT5DaGFsbGVuZ2UgMjwvaDE+PHA+Q29uZ3JhdHVsYXRpb24hIFlvdSBzb2x2ZWQgdGhlIGNoYWxsZW5nZSBudW1iZXIgMi4gTm93LCB5b3UgbXVzdCBhZGQgdGhlIHN0cmluZyB0b2tlbiBMRVQtUy1ST0NLIGF0IHRoZSBlbmQgb2YgdGhlIHN1YmplY3QuPC9wPjwvYm9keT48L2h0bWw+'" | |
], | |
"application/vnd.google.colaboratory.intrinsic+json": { | |
"type": "string" | |
} | |
}, | |
"metadata": {}, | |
"execution_count": 148 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"string_ch2p2 = message_ch2.split(',')[-1]" | |
], | |
"metadata": { | |
"id": "-33Ylw8P3_1n" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"encode_bytes_ch2p2 = string_ch2p2.encode('ascii')\n", | |
"message_bytes_ch2p2 = base64.b64decode(encode_bytes_ch2p2)\n", | |
"message_ch2p2 = message_bytes_ch2p2.decode('ascii')\n", | |
"message_ch2p2" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 53 | |
}, | |
"id": "8i5hIsl12V_Z", | |
"outputId": "5200df86-5518-45a2-bd49-e4eda44a88e1" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"'<html><head></head><body><h1>Challenge 2</h1><p>Congratulation! You solved the challenge number 2. Now, you must add the string token LET-S-ROCK at the end of the subject.</p></body></html>'" | |
], | |
"application/vnd.google.colaboratory.intrinsic+json": { | |
"type": "string" | |
} | |
}, | |
"metadata": {}, | |
"execution_count": 150 | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"## Challenge 3\n", | |
"Combination Base32 + Reverse + Cessar + Finding `CONGRATULATION!`" | |
], | |
"metadata": { | |
"id": "WeH3cohJ2WSz" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"import base64" | |
], | |
"metadata": { | |
"id": "iSNbLfmcDgaU" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"string_ch3 = \"\"\"FZTGOYLWMJRSAYTBEBQXMIDGM54WQZTSMUQHIYLWM5XHE5KQEAXGO2DDM5UGEIDRMVXHCYLOM5TCA4TVM4QGC5RAMFRHMZ3IPFRGMIDSOVTSAYLFNBTXEZJAMJTSA4LSM5YHEY3LOIQGM5RAM53CA4LBNYQCY3DDFZQWE5THNB4WEZS7GNZHIYLSPF4W45LQEBQWE5LHNRRSALBOOIXHMIBMFFKUMTSPFAQHEYLWPEQHCYLOPJ5GE4BANZ3GSIDROJTWQ4DSNNZCA4TPEB4XS5TKEBTWG5TFOBTCA4TVI4QC44LSOFRHALLRMVXHKIDSN4QGC3TQEB2GC5TFM5TCAZ3IMNQXMIDROJYWE4DBOIQHE5KHEAXCS4TUNZTGM4T2EBTHM5LHEAWC44ROOYUCAYLCOZTWQ6LCMYQHE5LHEBQXE4TFOBTCAYLCEBTWC5TFMMQHS6LWNIQGOY3WMVYGMIDSOVDSALRTEMQHE5DBOJ4XS3TVOAQHGYRAMFZHQYTHEB2GC5TFM5TCA4TVM4QHE4LCOBZHCIDCM4QHU5LHOZSWE5DZNYQHE5LHEBTGOYLSPJZHSY32OYQGOY3WMVYGMIDSOVDSALTMMMXGCYTWM5UHSYTGL4ZXE5DBOJ4XS3TVOAQHC4TZPFXHAIDSPF3HGIDHMN3GK4DGEBQWE5LHNRBSA3RAPF3G46TSEBZHKZZAMJTSA5LQNZTWO3RAOJTG44TZIMQC4MZAMVZG66TIMEQHE5DBOJ4XS3TVOAQHE5LHEBYXE2LZMJTCA2DCJQQCCYLCOZTW46LIM5XGK5DBMJIA====\"\"\"" | |
], | |
"metadata": { | |
"id": "9BFm-pi94iu0" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"string_ch3.isupper()" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "g_DXNK_s5Zry", | |
"outputId": "1ff2003c-241a-4a2b-f042-8ec933fe3b8f" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"metadata": {}, | |
"execution_count": 153 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"for i in ['O', '0', 'I', '1']:\n", | |
" if i in string_ch3:\n", | |
" print(f\"{i} is in string\")" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "knCj5TZs5axP", | |
"outputId": "82759249-65ea-495a-ccb2-1520527b8663" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"O is in string\n", | |
"I is in string\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# Base 32 Decode\n", | |
"encode_bytes_ch3 = string_ch3.encode(\"UTF-8\")\n", | |
"message_bytes_ch3 = base64.b32decode(encode_bytes_ch3)\n", | |
"message_ch3 = message_bytes_ch3.decode('ascii')\n", | |
"message_ch3" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 89 | |
}, | |
"id": "blSl8PTR6voA", | |
"outputId": "e30bb2c2-2b25-4c36-cc28-f30155669eaf" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"'.fgavbc ba av fgyhfre tavgnruP .ghcghb qenqangf rug av abvghybf rug aehgre bg qrgprckr fv gv qan ,lc.abvghybf_3rtaryynup abuglc ,.r.v ,)UFNO( ravy qanzzbp nvi qrghprkr ro yyvj gcvepf ruG .qrqbp-qenu ro anp tavegf ghcav qrqbpar ruG .)rtnffrz fvug ,.r.v( abvghybf rug arrepf ab gavec yyvj gcvepf ruG .3# rtaryynup sb arxbg tavegf rug rqbprq bg zugvebtyn rug fgarzryczv gcvepf ruG .lc.abvghybf_3rtaryynup qryynp ryvs gcvepf abuglC n yvnzr rug bg upnggn rfnryC .3 erozha rtaryynup rug qriybf hbL !abvgnyhgnetabP'" | |
], | |
"application/vnd.google.colaboratory.intrinsic+json": { | |
"type": "string" | |
} | |
}, | |
"metadata": {}, | |
"execution_count": 155 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# Mirror\n", | |
"message_ch3p2 = message_ch3[::-1]\n", | |
"message_ch3p2" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 89 | |
}, | |
"id": "2yU--nEa7-SF", | |
"outputId": "24f00f41-a5f9-4d51-9f13-0e9cb7c45eed" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": [ | |
"'Pbatenghyngvba! Lbh fbyirq gur punyyratr ahzore 3. Cyrnfr nggnpu gb gur rznvy n Clguba fpevcg svyr pnyyrq punyyratr3_fbyhgvba.cl. Gur fpevcg vzcyrzragf gur nytbevguz gb qrpbqr gur fgevat gbxra bs punyyratr #3. Gur fpevcg jvyy cevag ba fperra gur fbyhgvba (v.r., guvf zrffntr). Gur rapbqrq vachg fgevat pna or uneq-pbqrq. Gur fpevcg jvyy or rkrphgrq ivn pbzznaq yvar (ONFU), v.r., clguba punyyratr3_fbyhgvba.cl, naq vg vf rkcrpgrq gb erghea gur fbyhgvba va gur fgnaqneq bhgchg. Purngvat erfhygf va ab cbvagf.'" | |
], | |
"application/vnd.google.colaboratory.intrinsic+json": { | |
"type": "string" | |
} | |
}, | |
"metadata": {}, | |
"execution_count": 158 | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"# define alphabet \n", | |
"l_alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' #large case\n", | |
"s_alphabet = l_alphabet.lower() #lower case\n", | |
"\n", | |
"length = len(l_alphabet) # len of alphabet\n", | |
"\n", | |
"\n", | |
"# iterate on alphabet key possibles, i.e., 0 to 26 (26 is not included)\n", | |
"for key in range(0, length):\n", | |
" decrypted_massage_ch3p3 = \"\"\n", | |
"\n", | |
" # iterate on encrypted massage\n", | |
" for s in message_ch3p2:\n", | |
" # find out which alphabet it uses. switch to that.\n", | |
" alphabet = \"\"\n", | |
" num = -1\n", | |
" # find the appropiate alphabet\n", | |
" num_l = l_alphabet.find(s) \n", | |
" num_s = s_alphabet.find(s)\n", | |
"\n", | |
" # override the apptpiate alphabet variables \n", | |
" if num_l != -1:\n", | |
" alphabet = l_alphabet\n", | |
" num = num_l\n", | |
" elif num_s != -1:\n", | |
" alphabet = s_alphabet\n", | |
" num = num_s\n", | |
"\n", | |
" # do the cessar\n", | |
" if s in alphabet:\n", | |
" num = num - key\n", | |
" if num < 0:\n", | |
" num = num + length\n", | |
" decrypted_massage_ch3p3 = decrypted_massage_ch3p3 + alphabet[num]\n", | |
" # if the symbol is not in alphabet just leave it unchanged.\n", | |
" else:\n", | |
" decrypted_massage_ch3p3 = decrypted_massage_ch3p3 + s\n", | |
"\n", | |
" # check if the CONGRATULATION! or any other type of it (upper, lower) is in the result.\n", | |
" if 'CONGRATULATION!' in decrypted_massage_ch3p3.upper():\n", | |
" print(decrypted_massage_ch3p3)" | |
], | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "Asbp2Rs97nRP", | |
"outputId": "e878282f-bfe2-48b4-9d61-d38f4c9e413d" | |
}, | |
"execution_count": null, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Congratulation! You solved the challenge number 3. Please attach to the email a Python script file called challenge3_solution.py. The script implements the algorithm to decode the string token of challenge #3. The script will print on screen the solution (i.e., this message). The encoded input string can be hard-coded. The script will be executed via command line (BASH), i.e., python challenge3_solution.py, and it is expected to return the solution in the standard output. Cheating results in no points.\n" | |
] | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment