{ "info": { "author": "p4-team", "author_email": "team@p4.team", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# crypto-commons\n\nSmall python module for common CTF crypto functions.\nFeel free to contribute if you think there is something missing, or if you have some interesting code to share.\n\nIn general we want to keep this as much dependency-free as possible, so most likely pull requests with a lot of external dependencies will not get merged.\n\nFor the record: this is not a generic-purpose crypto library, nor production-level cryptography implementation!\nYou should not use any of this code in real-life applications.\n\nThe problems we want to solve here:\n\n- The need to constantly look for implementations for some less common algorithms (like Damgard-Jurik) or less common scenarios (like RSA with prime powers).\n- The need to install many different libraries in order to use some simple function.\n- Issues with installing dependencies on different environments. \nEspecially with Python 2/3 incompatibility and compiled C-modules.\n- Repeating the same code over and over again, and wasting time on debugging typos and small mistakes.\n\nGeneral guidelines we hope to follow:\n- Split implementation into small steps. CTF tasks often require changes in some of the algorithms, \nso it would be nice to be able to assemble an algorithm from smaller blocks. \n- Expose clear interfaces.\nObject-oriented code might be nice for production-level software, \nbut makes it more complicated when you're trying to translate primitives you have into objects the library requires.\nEspecially when you're missing some parameters, which are not necessary for the function you need.\n- Don't make asserts and checks other than the necessary ones for current function.\nSome libraries are not usable in CTF environment because they will automatically fail detecting some \"invalid\" parameters, \nwhile in reality we know the parameters are wrong and we need a few more steps to solve the task.\n\n## Installation\n\n``` bash\nsudo python setup.py install\n```\n## Usage example\n\nBasic usage:\n\n``` python\nfrom crypto_commons import generic\n\n#xor a hex array with a string and print the result\na = [0x61, 0x53, 0x40, 0x47, 0x42, 0x59, 0x45, 0x5c, 0x08]\nb = \"123456789\"\n\nb = map(ord, b)\n\nxored = map(chr, generic.xor(a, b))\n\nprint(''.join(xored))\n\n```\n\n[qiwi CTF, crypto 400](https://github.com/p4-team/ctf/blob/master/2016-11-17-qiwi-2016/hastad/README.md)\n\n```python\nfrom crypto_commons.generic import long_to_bytes\nfrom crypto_commons.rsa.rsa_commons import hastad_broadcast\n\n\ndef main():\n n1 = 95118357989037539883272168746004652872958890562445814301889866663072352421703264985997800660075311645555799745426868343365321502734736006248007902409628540578635925559742217480797487130202747020211452620743021097565113059392504472785227154824117231077844444672393221838192941390309312484066647007469668558141\n n2 = 98364165919251246243846667323542318022804234833677924161175733253689581393607346667895298253718184273532268982060905629399628154981918712070241451494491161470827737146176316011843738943427121602324208773653180782732999422869439588198318422451697920640563880777385577064913983202033744281727004289781821019463\n n3 = 68827940939353189613090392226898155021742772897822438483545021944215812146809318686510375724064888705296373853398955093076663323001380047857809774866390083434272781362447147441422207967577323769812896038816586757242130224524828935043187315579523412439309138816335569845470021720847405857361000537204746060031\n c1 = 64830446708169012766414587327568812421130434817526089146190136796461298592071238930384707543318390292451118980302805512151790248989622269362958718228298427212630272525186478627299999847489018400624400671876697708952447638990802345587381905407236935494271436960764899006430941507608152322588169896193268212007\n c2 = 96907490717344346588432491603722312694208660334282964234487687654593984714144825656198180777872327279250667961465169799267405734431675111035362089729249995027326863099262522421206459400405230377631141132882997336829218810171728925087535674907455584557956801831447125486753515868079342148815961792481779375529\n c3 = 43683874913011746530056103145445250281307732634045437486524605104639785469050499171640521477036470750903341523336599602288176611160637522568868391237689241446392699321910723235061180826945464649780373301028139049288881578234840739545000338202917678008269794179100732341269448362920924719338148857398181962112\n print(long_to_bytes(hastad_broadcast([(c1, n1), (c2, n2), (c3, n3)])))\n\n\nmain()\n```\n\n[qiwi CTF again, crypto 400](https://github.com/p4-team/ctf/blob/master/2016-11-17-qiwi-2016/hensel/README.md)\n\n```python\nimport gmpy2\nfrom crypto_commons.generic import long_to_bytes\nfrom crypto_commons.rsa.rsa_commons import hensel_lifting, modinv\n\n\ndef main():\n n = 158168890645747636339512652656727367370140893295030333823920833363025940906055891357316994482461476576118114207681214323912652527927215053128809927932495206979837034713724140745400652922252749994983891690894724877897453440237829719520264826887839607084620792280551479756249230842706713662875715392719130358089\n e = 65537\n c = 140823625180859595137593494178968497314300266616869468408596741823165198698204065579249727536890649445240801729293482339393915146972721826733382396566284303449925618355682242041225432010603850355326962069585919704623290128021782032477132287121179121257196031074006842188551083381364957799238533440938240326919\n p = gmpy2.isqrt(n)\n k = 2\n base = pow(c, modinv(e, p - 1), p) # solution to pt^e mod p\n f = lambda x: pow(x, e, n) - c\n df = lambda x: e * x\n r = hensel_lifting(f, df, p, k, base) # lift pt^e mod p to pt^e mod p^k\n for solution in r:\n print(long_to_bytes(solution))\n\nmain()\n\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/p4-team/crypto-commons", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "crypto-commons", "package_url": "https://pypi.org/project/crypto-commons/", "platform": "", "project_url": "https://pypi.org/project/crypto-commons/", "project_urls": { "Homepage": "https://github.com/p4-team/crypto-commons" }, "release_url": "https://pypi.org/project/crypto-commons/0.0.4/", "requires_dist": [ "future ; python_version < \"3.0\"" ], "requires_python": "", "summary": "Small python module for common CTF crypto functions.", "version": "0.0.4" }, "last_serial": 5738234, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "7b19c4f7c487abfe3b88b4383fc3211e", "sha256": "0cac0eac86f575f7fb2b1550dbbf5e7da8d3376a48838686637321392d813764" }, "downloads": -1, "filename": "crypto_commons-0.0.1-py2-none-any.whl", "has_sig": false, "md5_digest": "7b19c4f7c487abfe3b88b4383fc3211e", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 18403, "upload_time": "2019-08-27T17:11:15", "url": "https://files.pythonhosted.org/packages/89/53/0fd54a6e403657c1b0ed846ed25e0f207d1843c3e455f22b1f839533f950/crypto_commons-0.0.1-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a005ae606b8e0f2022112ec8800276b4", "sha256": "9dd946258344305faed437c5b34dce243bc573419c7e7dbba0138c4f85b64dc6" }, "downloads": -1, "filename": "crypto-commons-0.0.1.tar.gz", "has_sig": false, "md5_digest": "a005ae606b8e0f2022112ec8800276b4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17245, "upload_time": "2019-08-27T17:11:17", "url": "https://files.pythonhosted.org/packages/b9/d3/ac8af0775c8d18bc655a9a305d97353bb0cee0feeae0948d8de6f214cce0/crypto-commons-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "08e2ae11564632e1bcb9e17664f30e8d", "sha256": "8226546886598e00a27a5dafb01d36dcc4b0b035d3863c6df99d5b151797cc94" }, "downloads": -1, "filename": "crypto_commons-0.0.2-py2-none-any.whl", "has_sig": false, "md5_digest": "08e2ae11564632e1bcb9e17664f30e8d", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 21423, "upload_time": "2019-08-27T17:15:43", "url": "https://files.pythonhosted.org/packages/b5/64/4ff1ba4d11db187375bc88b9aaad65eef7952915d091033e78acf0fd36a6/crypto_commons-0.0.2-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ee5b966a754d2cacd96527cf9f2b1c82", "sha256": "32892581aaf1d5a6db7a4fa9713ec1f53b392efe1c4d5a50be493a2f8003cf6d" }, "downloads": -1, "filename": "crypto-commons-0.0.2.tar.gz", "has_sig": false, "md5_digest": "ee5b966a754d2cacd96527cf9f2b1c82", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17892, "upload_time": "2019-08-27T17:15:45", "url": "https://files.pythonhosted.org/packages/ef/e6/f5f7495ad10694740fcdab84b85c58b028613e52b0c529f364d688383e69/crypto-commons-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "f49b37f6f0aa03a49aa9be131b5b16c5", "sha256": "cc0507d8950b56d8e063d95c6ec907d85c184ca825b374cf87773987a66ceae4" }, "downloads": -1, "filename": "crypto_commons-0.0.3-py2-none-any.whl", "has_sig": false, "md5_digest": "f49b37f6f0aa03a49aa9be131b5b16c5", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 21420, "upload_time": "2019-08-27T17:20:58", "url": "https://files.pythonhosted.org/packages/9e/54/d7efbe40be0678092b5292371506e47ef56a44a5524338059bfd51416152/crypto_commons-0.0.3-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5d7c3b462ecc91d741228dd0a1d9c9ca", "sha256": "2c8a59ce22cef4e32585ed9b0abb97130bf907af2ea7293835609197bbff65cc" }, "downloads": -1, "filename": "crypto-commons-0.0.3.tar.gz", "has_sig": false, "md5_digest": "5d7c3b462ecc91d741228dd0a1d9c9ca", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17889, "upload_time": "2019-08-27T17:21:00", "url": "https://files.pythonhosted.org/packages/4a/33/57d9367bf3154c7c93146ff81568aa597e2459a7db5aaa8c3b19cc3d37c2/crypto-commons-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "43be6be3e65fab57bf510e3c53db9aed", "sha256": "113713ce5dddb00885df1b4c3cab8545696b511bb80286050a02a62a6e2b9c28" }, "downloads": -1, "filename": "crypto_commons-0.0.4-py2-none-any.whl", "has_sig": false, "md5_digest": "43be6be3e65fab57bf510e3c53db9aed", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 21413, "upload_time": "2019-08-27T17:22:01", "url": "https://files.pythonhosted.org/packages/5a/86/97388a9a17689e2001a72e67c85b701e67efd1fd42b05e717db4719806b3/crypto_commons-0.0.4-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "72c3e673771f9734fe42cac172dc3d8f", "sha256": "b1edb8f81b291fed86ce051d3abce82e8569fcb7884f9bfcf70fd65ac114e432" }, "downloads": -1, "filename": "crypto-commons-0.0.4.tar.gz", "has_sig": false, "md5_digest": "72c3e673771f9734fe42cac172dc3d8f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17874, "upload_time": "2019-08-27T17:22:03", "url": "https://files.pythonhosted.org/packages/37/b2/bd39fb31cdbd8088142698cd46170a6d25976313ee9688bf7f598dcbecb6/crypto-commons-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "43be6be3e65fab57bf510e3c53db9aed", "sha256": "113713ce5dddb00885df1b4c3cab8545696b511bb80286050a02a62a6e2b9c28" }, "downloads": -1, "filename": "crypto_commons-0.0.4-py2-none-any.whl", "has_sig": false, "md5_digest": "43be6be3e65fab57bf510e3c53db9aed", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 21413, "upload_time": "2019-08-27T17:22:01", "url": "https://files.pythonhosted.org/packages/5a/86/97388a9a17689e2001a72e67c85b701e67efd1fd42b05e717db4719806b3/crypto_commons-0.0.4-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "72c3e673771f9734fe42cac172dc3d8f", "sha256": "b1edb8f81b291fed86ce051d3abce82e8569fcb7884f9bfcf70fd65ac114e432" }, "downloads": -1, "filename": "crypto-commons-0.0.4.tar.gz", "has_sig": false, "md5_digest": "72c3e673771f9734fe42cac172dc3d8f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17874, "upload_time": "2019-08-27T17:22:03", "url": "https://files.pythonhosted.org/packages/37/b2/bd39fb31cdbd8088142698cd46170a6d25976313ee9688bf7f598dcbecb6/crypto-commons-0.0.4.tar.gz" } ] }