使用Python或C实现DES算法,以及比较DES、AES、RSA、HMAC和SHA-1算法的性能。
实验室概述密码学的概念包括通过以下方式向不受信任的对等方隐藏秘密信息将消息篡改成只有可信的对等方才能重新排列的难以理解的文本。在这个实验室里,我们
将使用并比较三种常用的隐藏或加密技术信息:密钥加密(DES、AES)、公钥加密(RSA)和消息摘要(SHA-1)。我们还提供了一组文件,作为如何使用我们将在本讲义中提及,并且您可以在实现中使用。这些文件只是应该修改以获得预期结果的骨骼。包含在压缩文件也是“DES-CBC”实现的测试用例(test.txt和test.DES)文件,其中包含一些内置函数的一般说明。请参考骨架代码由导师提供的文件夹。
COMP4337/9337 Securing Fixed and Wireless NetworkLab
1: Introduction
Basic Cryptographic MechanismsDue: M18A Lab - Monday 27th February 2023 11.59PM AEDTW10A, W10B, W12A, W12B Labs – Wednesday 1st March 2023 11.59PM AEDTObjectivesThis lab is designed to help the students to: learn the basics of cryptography for hiding secret information from non-trusted peers, implement DES algorithm using Python or C, and compare the performance of DES, AES, RSA, HMAC, and SHA-1 algorithms.Lab OverviewThe notion of cryptography consists of hiding secret information from non-trusted peers bymangling messages into unintelligible text that only trusted peers can rearrange. In this lab, wewill use and compare three different techniques commonly employed to hide or encryptinformation: secret key cryptography (DES, AES), public key cryptography (RSA) andmessage digests (SHA-1).We also give a group of files as a reference on how to use certain built-in functions that wewill mention in this handout and that you can use in your implementations. These files are justskeletons that you should modify to obtain the expected results. Included in the compressedfile is also a test case for your DES-CBC
implementation (test.txt and test.des) and afile with general descriptions of some built-in functions. Please refer to the skeletoncodefolder provided by your tutors.Assessment and MarkingThe submission link and the deadline will be available on Moodle. The marks will be madeavailable within 2 weeks of the submission date. The details of the marks are as follows: Total mark for Lab 1 is 100. This lab combined with marks for other labs will be scaledto 20 out of 100. The weight for this Lab is 0.3/1.o Lab Performance (20),o Report (40)o Code (40) Students who do not attend the lab will lose ALL 100 marks. Please discuss with thelab tutors if there is a valid reason for not attending. Note: Lab performance involves tutor asking question, feedback, and comments aboutthe activity while the lab is in progress. Hence, if a group is found to be cheating orsubmitting a work that does not match what the tutor observes of the team performance,then NO MARK will be awarded for that group. The standard late penalty introduced under UNSW new assessment implementationprocedure will be applied for this course.o 5% per day,o capped at five days (120 hours) from the assessment deadline, after which astudent cannot submit anassessment, ando no permitted variation.SubmissionPlease follow these instructions to prepare a submission for this lab:1. You are given the option to do this lab either individually or in a pair. If you opt to doin a pair, both team members will get equal marks.2. Create a folder named Lab_1__. containing two subdirectories:code/and report.
2.In code
For Python, include a copy of tempdes.py file. Name your file_.des.py, where zid_1 and zid_2 are the zids of groupmembers. For example: z1234567_z7654321.des.py. For C, include a copy of tempdes.c file. Name your file_.des.c, where zid_1 and zid_2 are the zids of groupmembers. For example: z1234567_z7654321.des.c. For students who do not have a strong preference and an experience in using C,werecommend using Python.4. In report/, upload a written report with the following information: On the first page, include the name of the group, student names and ZIDs clearly. Python or C code implemented. Graphs showing:o DES encryption/decryption time,o AES encryption/decryption time,o RSA encryption/decryption time,o SHA-1 digest generation times, ando HMAC signature generation times.Note: In each of these graphs, the X-axis should plot the file sizes in units of bytes,and the Y-axis should plot time measurements in units of microseconds (μs). Answer the following questions:o Compare DES and AES. Explain your observations.o Compare DES and RSA. Explain your observations.o Compare DES and SHA-1. Explain your observations.o Compare HMAC and SHA-1. Explain your observations.o Compare RSA encryption and decryption time. Can you explain yourobservations?5. Compress Lab_1__ folder and its content into a .zip file andupload that file on Teams using the designated link. Only .zip file format is allowed.Part A: DES encryption and decryptionIn this part of the lab, we will be coding a tool to encrypt and decrypt files using DES in CipherBlock Chaining (CBC) mode. tempdes.py or tempdec.c (for C programmers) is a skeleton3 of 5file that encrypts/decrypts a fixed 64-bit block. In this lab, you will extend the skeleton code totake an arbitrarily sized input file and encrypt/decrypt it, by implementing the Cipher BlockChaining DES mode of operation. You must implement the CBC mode. You may use the built-in functions in tempdes.py or tempdec.c. You can find information about DES-CBC intextbooks and online.
You may want to check your work against the input file test.txt. If you have implementedthe algorithm correctly and followed the instructions below you should get the output inmytest.des. Check the output against test.des provided to see if it matches. You can findthese files in skeletoncode/.Technical Requirements Use the built-in functions that appear in tempdes.py or tempdes.c, depending onyour chosen language. For C code, use lcrypto library to compile the source code, for example:$ gcc tempdes.c -o tempdes -lcryptowhere, tempdes.c and tempdes are your source and executable, respectively. Your result should take the following arguments:For Python:$ python tempdes.py iv key inputfile outputfileFor C:$ ./tempdes iv key inputfile outputfile The parameters description isas follows:o iv: the actual IV to use, represented as a stringcomprised only of hexadecimaldigits.o key: the actual key to use, represented as a string comprised only ofhexadecimal digits.o inputfile: input file name.o outputfile: output file name.Examplecommand to run the resulting code:For Python:$ python3tempdes.py fecdba9876543210 0123456789abcdeftest.txt mytest.desFor C:$ ./tempdes fecdba9876543210 0123456789abcdef test.txtmytest.des Please note that to get the sample output files you need to use the key and IV givenin the README file. If any of the arguments is invalid, your code should return an error message to the user.Be sure to consider the case when the keys are invalid.4 of 5Part B: Performance measures for various algorithmsThe final part of this lab consists of measuring the time taken by DES, AES, PRESENT, RSA,HMAC and SHA-1 algorithms to process files of different sizes. Please follow the followingsteps:1. Generate text files with the following sizes: For DES, AES, PRESENT, HMAC, and SHA-1 (in bytes):16, 64, 512, 4096, 32768, 262144, 2047152 For RSA (in bytes):2, 4, 8, 16, 32, 642. Encrypt and decrypt all the files using the DES function that you wrote. Measure thetime it takes to encrypt and decrypt each of the files. To do this, you might want to usethe Python/C timing functions. Add these timing functions to your specificimplementation.3. Repeat the above but instead of DES use AES.4. Measure the time for RSA encryption and decryption for the file sizes listed in 1. Todo this, make appropriate changes to the file temprsa.py (or temprsa.c). Thisskeleton code shows how to use built-in RSA encryption and decryption functions, butyou will need to augment it to allow for reading from arbitrary files, and to insertnecessary instrumentation code for timing purposes.5. Measure the time for SHA-1 hash generation for the file sizes listed in 1. To do this,make appropriate changes to the file tempsha1.py (or tempsha1.c). This skeletoncode shows how to use built-in SHA-1 hashing functions, but you will need to augmentit to allow for reading from arbitrary files, and to insert necessary instrumentation codefor timing purposes. You are encouraged to test other hash functions from the library.6. Measure the time for HMAC signature generation for the file sizes listed in 1. To dothis, make appropriate changes to the file tempHMAC.py (or tempHMAC.c). Thisskeleton code shows how to use built-in HMAC functions, but you will need to augmentit to allow for reading from arbitrary files, and to insert necessary instrumentation codefor timing purposes.7. Prepare a report of your observations in the format requested under Submission.Part C: PRESENT Algorithm (Optional)Any student interested in testing more algorithms, we provided the skeleton code forPRESENT, a lightweight encryption algorithm. You can follow the following instructions totest the performance of that algorithm. For more details about PRESENT algorithm, pleaserefer to the paper here.Measure the encryption/decryption times for PRESENT lightweight encryption anddecryption for the file sizes listed in 1. To do this, make appropriate changes to the filetemppresent.py (or temppresent.cpp). This skeleton code shows how to use theimplemented PRESENT encryption and decryption functions, but you will need to augment it5 of 5to allow for reading from arbitrary files, and to insert necessary instrumentation code for timingpurposes.Note: PRESENT Python implementation may only be able to take hexadecimal string as theinput (0-9, a-f).
WX:codehelp
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。