Introduction基本思路:对字符串的加密与解密,作业中的加密是简单的对应字符换成密码中的字符,密码长度为26个不重复字符如密码为bcdefghyjklmnopqrstuvwxyza 那对应文章中的a字母都换成b字母,b字母换成c字母,类推解密的时候倒过来就行注意点:给你一篇密文文章,得到他密码的方法是作业中统计字母出现频率的高低,如果密文中b出现频率最高,而现实中假设人们用a字母最多,那b字母就是a字母的密码RequirementINFO1103 Introduction to Programming, Semester 2, 20161Task 3: CryptographySubmission deadline: 5pm on Saturday, 15 th October (Week 11)Submission: Submit a zip file containing your Encrypter.java, SecretMessages.java andFrequencyDecryption.java files via the online system PASTA.Weight: 7 marks = 7% of your final mark.This assessment must be completed individually.IntroductionYou, being a studious student, open this task description, ready for whatever challenge you may need to face.However, you are suddenly faced with a big problem! Your instructors have literally encrypted a large sectionof the task description!What!Uq hyygd hugk wyr’sk ckbuzakjkc qaud ikddmok. Byxojmq - rhmquyxd!Lk jkmhhw ayzk wyr’sk kxfywkc cyuxo qaud mdduoxikxq.(Lk bkjqmuxhw kxfywkc ljuquxo uq!)Lk qayroaq uq lyrhc tk xubk qy amsk dyik zjuekd nyj qak nujdq qajkk zkyzhkqy nuxuda qak mdduoxikxq.Cy wyr qauxg wyr byrhc tk yxk yn qaydk zkyzhk?Qy tk khuouthk, wyr irdq amsk zmddkc mhh yn qak xyx-aucckx qkdqd yxZMDQM.Un wyr amsk zmddkc qakdk qkdqd, qakx prubghw bakbg zumeem. Amdmxwyxk imck m zydq qamq dmwd…‘Au kskjwyxk. Qaud iuoaq tk m tuq jmxcyi, trq prujgw pryggmd mjk p-rjuyrdhw p-rqk!!!’Un xyq, wyr iuoaq tk qak nujdq qy nuxuda!Qy bhmui wyrj zjuek, imgk drjk wyr’sk zmddkc mhh qak ZMDQM qkdqd.Un wyr amsk, qakx imgk m zydq qamq dmwd kvmbqhw qak dmik qauxo mdmtysk.Qamq ud, imgk m zydq qamq dmwd:‘Au kskjwyxk. Qaud iuoaq tk m tuq jmxcyi, trq prujgw pryggmd mjk p-rjuyrdhw p-rqk!!!’XYQK: Nkkh njkk qy zydq mxyxwiyrdhw, trq imgk drjk qaud zydq ud zrthub, dy yqakjd gxyl wyr’sknuxudakc.Qak dkbjkq ikddmok nyj dkbyxc zhmbk ud: ‘Pryggmd pryqk pryggmd pruqk prubghw.’.Zhkmdk zydq qaud ux nyhhyl-rz cudbrdduyx dkbquyx yn qak nujdq zydq un wyr mjk dkbyxc! :)Nuxmhhw, qak dkbjkq ikddmok nyj qaujc zhmbk ud: ‘Zkcmxqub zjyojmiikjd zkjnyji zjmbqumhhwzkjnkbqhw… zkjamzd’.Momux, zhkmdk zydq qaud ux nyhhyl-rz cudbrdduyx dkbquyx yn qak nujdq zydq un wyr mjk qaujc! :)Xyq nujdq, dkbyxc yj qaujc, trq dquhh lmxq qy fyux ux yx qak nrx? Imgk rz wyrj ylx qmrqyojmi mxc zydquq ux qaknyhhyl-rz cudbrdduyx dkbquyx.INFO1103 Introduction to Programming, Semester 2, 20162Nuxmhhw, qakjk mjk frdq m nkl qauxod lk lmxqkc qy dmw.Dyikquikd, wyr iuoaq nuxc qamq qak yjckjkc hudq yn iydq byiiyx hkqqkjd ux yxk qkvqud dhuoaqhw cunnkjkxq njyi qak yqakj.Qamq’d ygmw qayroa! Wyr bmx dquhh rdk qaud ikqayc, trq luhh mhdy xkkc qy rdk dyik frcokikxq qy nuvmxw kjjyjd.Mhh juoaq, qamq’d kskjwqauxo!Lk ayzk wyr amc nrx, mxc luda wyr oyyc hrbg nyj qak jkdq yn qak byrjdk! :)Nooooo!!!How can this be? How can you do your assignment when half of it is gibberish!? You didn’t ask for a taskdescryption! As you are thinking this, something suddenly occurs to you. You are a Java programmer now!You have all the skills you need to crack this silly cipher, and you’re going to do it!Before You BeginRemember that this task is here to help you improve your programming skills. When doing this task, youmight find some parts tricky, but this is normal and also a good thing (if we were never challenged, we wouldnever learn anything!). The most important things are to start this task as soon as you can, to ask questionswhen you need help and to be persistent! It’s often good to work on one part of the assignment at a time, thensubmit to PASTA to see how you went with it. Try to be creative when approaching problems - usually thereare many ways to do something. We hope you enjoy this cryptography-themed task! :)Part 1 – Your Own Secret MessagesIn the first part of this assignment, your task is to write a program to encrypt and decrypt your very own secretmessages using a substitution cipher! This substitution cipher will involve swapping each letter of the alphabetwith a different letter and sometimes also removing spaces. For example, maybe “a” might be replaced with“e”, “b” might be replaced with “a”, “c” might be replaced with “f” and so on.In order to encrypt and decrypt these kinds of messages, the sender and receiver must both know a secret key.A key is a set of rules that tell you which letters to swap with which. One way that you can represent this keyis with a string that contains all of the letters from a to z exactly once. The first letter in the string should bethe letter that replaces “a” when encrypting, the second letter in the string should be the letter that replaces“b”, the third letter should be the one that replaces “c” etc.For example, if the string is “bzcdefghijklmnopqrstuvwxya”, then “a” would be replaced with “b”, “b” wouldbe replaced with “z”, “z” would be replaced with “a” and everything else would stay the same. So, a word like“zebra” would become “aezrb”.When decrypting, the reverse would be done: “b” would be replaced with “a”, “z” would be replaced with“b”, “a” would be replaced with “z” and everything else would stay the same. So, “aezrb” would become“zebra”.All right, with that in mind, are you ready to make your own secret messages?INFO1103 Introduction to Programming, Semester 2, 20163Step 1 ‐ Getting the skeleton codeIn this task description, there is a section called Setting Up. Please read this section carefully for informationabout the skeleton code and follow the instructions to set up your workspace.Step 2 – Understanding the Encrypter classFor this part of the assignment (i.e. Part 1), we will be focusing on only two of the three skeleton code classes:Encrypter and SecretMessages. You could think of the Encrypter class as a set of instructions formaking encrypters. That is, things that can encrypt and decrypt secret messages. Each encrypter has its ownspecial key for encrypting and decrypting messages, and also a setting for removing whitespace. (Recall thatin programming, all characters that are not visible when displayed are called collectively whitespace. Thus,the whitespace includes the normal space “ ” but also the tab “ ”, new line “ ” and some other characters.)This option to remove whitespace is useful, because messages withoutspaces are harder to guess. For example, it might be easy to guess thatsomething like “T od Dto” by looking at word length, but “TodDto”would be harder!Sometimes you might not want to remove whitespace, though,because then it’s more difficult to read the message after decryptingit. For example, “IamMia” is more difficult to read than “I am Mia”.Perhaps when testing your code, it would be nicer if the decryptionwas very easy to read. So, in some cases, not removing whitespacecould be helpful.This is why each encrypter has a removeSpaces setting. If removeSpaces is set to true, then the encrypterwill remove all whitespace when encrypting. If it is set to false, then the encrypter will not remove whitespace.Note that the encrypter should never remove whitespace when decrypting, as this just makes the messageunnecessarily difficult to read.Step 3 – Writing the Encrypter ClassYou are welcome to complete this task in any order you like, but if you’re not sure where to begin, try startingwith the getKey and isRemovingSpaces methods in the Encrypter class.The blue comments above each method tell you exactly what the method should do, and give you informationabout input and output. Please read this carefully!After you have written a method, it’s a good idea to check that it works correctly. You can do this by submittingyour code to PASTA. Even if you have only written one method, you can still submit your code. Rememberthat you are allowed as many attempts as you like, so there really is no harm in doing this. To submit yourcode, first make sure your code compiles (i.e. no red errors in Eclipse), then follow the submission instructionsat the end of this task description.If anything seems unfamiliar, try looking at the lecture slides, tutorial questions and textbook sections onobject oriented design. Also, here are a few hints that you might find useful when completing these methods!INFO1103 Introduction to Programming, Semester 2, 20164Hint 1 If you have a character and want to check if it is a letter or whitespace, you can use the Charactermethods isWhitespace and isLetter.Here’s an example of how you could check if the character ‘T’ is a letter:if (Character.isLetter(‘T’))System.out.println(“This is a letter”);Hint 2 You can easily check if a letter character is lowercase or uppercase using the following Charactermethods: isUpperCase, isLowerCase.Here is an example of how you could check if the character ‘B’ is uppercase:if (Character.isUpperCase(‘B’))System.out.println(“This character is an uppercase letter!”);Hint 3 Want to get the lowercase equivalent of an uppercase letter, or the uppercase equivalent of alowercase letter? Well then, these Character methods are just what you need: toUpperCase,toLowerCaseHere’s an example of how you could get ‘B’ in lowercase:char lowercaseB = Character.toLowerCase(‘B’); //lowercaseB will be ‘b’Hint 4 Say you have a character which is a lowercase letter, and you want to know its position in thealphabet. For example, ‘a’ is in position 0, ‘b’ is in position 1, ‘c’ is in position 2 etc.Here’s a simple way you can do it (note that charName is the name of the character you’re interestedin).int position = charName - ‘a’;How does this work? Well, charName and ‘a’ are converted to certain integers. ‘a’ is converted to97, ‘b’ is converted to 98, ‘c’ to 99 etc. (see this table for reference). Then, these integers aresubtracted.So, something like ‘c’ – ‘a’ becomes 99 – 97, which is 2. Ah! And 2 is the position of ‘c’ in thealphabet. :D.To find the position of an uppercase letter, just convert it to lowercase first and follow the sameprocess!Hint 5 What about going backwards? What if you know the position of a letter in the alphabet and youwant to know what character it is? Well, we can do something similar to before!Here’s how we could find the character in position 4 of the alphabet:int character = (char) (4 + ‘a’); //character will be eWhy is this e? Well, ‘a’ is converted to 97, so we have 4+97, which is 101. Then, we convert 101to a character and get ‘e’.INFO1103 Introduction to Programming, Semester 2, 20165Step 4 – SecretMessages ClassNow that we’ve made our Encrypter class, it’s time to use it!Write a program in the class SecretMessages that creates an encrypter and allows the user to do variousthings with this encrypter.This encrypter should initially: use the key “zabcdefghijklmnopqrstuvwxy” to encrypt and decrypt messages be set to not remove spacesThe program should give the user 5 different choices of things to do with the encrypter:1. encrypt a message2. decrypt a message3. check the key4. change the key5. change the space-removal mode.After the user has made a choice, the program should use the encrypter to perform. their choice. Then, it shouldallow them to make another choice and it should perform. that action. It should keep allowing the user to makechoices until they decide to quit. See the next section for some examples.Example Input/OutputThe following are some examples of input/output. Note that the black text is output, and the green text isinput.Example 1:What would you like to do?1 ‐ encrypt a message2 ‐ decrypt a message3 ‐ check the key4 ‐ change the key5 ‐ change space modeother ‐ quit1Enter a message to encryptQuokkas are amazing! :DThe encrypted message is: Ptnjjzr zqdzlzyhmf! :CWhat would you like to do?1 ‐ encrypt a message2 ‐ decrypt a message3 ‐ check the key4 ‐ change the key5 ‐ change space modeother ‐ quit2Enter a message to decryptPtnjjzr zqd zlzyhmf! :CThe decrypted message is: Quokkas areamazing! :DWhat would you like to do?1 ‐ encrypt a message2 ‐ decrypt a message3 ‐ check the key4 ‐ change the key5 ‐ change space modeother ‐ quitqQuitting. Goodbye.INFO1103 Introduction to Programming, Semester 2, 20166Example 2:What would you like to do?1 ‐ encrypt a message2 ‐ decrypt a message3 ‐ check the key4 ‐ change the key5 ‐ change space modeother ‐ quit1Enter a message to encryptDo you like quokkas?The encrypted message is: Cn xnt khjdptnjjzr?What would you like to do?1 ‐ encrypt a message2 ‐ decrypt a message3 ‐ check the key4 ‐ change the key5 ‐ change space modeother ‐ quit5Changing modeWhat would you like to do?1 ‐ encrypt a message2 ‐ decrypt a message3 ‐ check the key4 ‐ change the key5 ‐ change space modeother ‐ quit1Enter a message to encryptDo you like quokkas?The encrypted message is: Cnxntkhjdptnjjzr?What would you like to do?1 ‐ encrypt a message2 ‐ decrypt a message3 ‐ check the key4 ‐ change the key5 ‐ change space modeother ‐ quitqQuitting. Goodbye.Example 3:What would you like to do?1 ‐ encrypt a message2 ‐ decrypt a message3 ‐ check the key4 ‐ change the key5 ‐ change space modeother ‐ quit3This is the key: zabcdefghijklmnopqrstuvwxyWhat would you like to do?1 ‐ encrypt a message2 ‐ decrypt a message3 ‐ check the key4 ‐ change the key5 ‐ change space modeother ‐ quit4Enter a new keyquokkaThe new key was invalid so the key couldn’tbe changedWhat would you like to do?1 ‐ encrypt a message2 ‐ decrypt a message3 ‐ check the key4 ‐ change the key5 ‐ change space modeother ‐ quit4Enter a new keyabcedfghijrstuvwxyzklmnopqThe key was successfully changedWhat would you like to do?1 ‐ encrypt a message2 ‐ decrypt a message3 ‐ check the key4 ‐ change the key5 ‐ change space modeother ‐ quit3This is the key: abcedfghijrstuvwxyzklmnopqWhat would you like to do?1 ‐ encrypt a message2 ‐ decrypt a message3 ‐ check the key4 ‐ change the key5 ‐ change space modeother ‐ quitqQuitting. Goodbye.INFO1103 Introduction to Programming, Semester 2, 20167Part 2 – Descryption DecryptionIn the last section, you made your own encrypter to encrypt and decrypt your own secret messages. Thisworked by swapping letters around. You also saw that you could remove spaces to make those messages moredifficult to decrypt. Of course, if you wanted to go a step further, you could also remove capitalisation andpunctuation. This would leave just a big block of letters.If someone handed you a long block of letters like that and you had to decrypt the message without the key,what would you do? It might seem like a difficult task, but we can use a special trick!Say you read a text in plain English, and found that the most common letter was “e”. Then, you read anencrypted message and found that the most common letter was “z”. Would you be able to guess what that “z”actually was? Probably! If the most common letter in English was ‘e’, then there would be good evidence tothink that that “z” was actually an “e”!You could do something similar with the rest of the letters! You could get a list of all the letters in Englishranked based on how frequently they occur and a list of all letters in the encrypted message ranked in the sameway. Then you could try to match up the letters in the lists to guess the key!Of course, this might not always work out exactly. For example, it might be tricky trying to decrypt a novelwith no e’s in it! () ). However, it can be useful in giving you ageneral idea of which letter could be which, and you could try out different combinations! Generally, thelonger the encrypted message, the better this method will work.With all of this in mind, it’s time to finally discover what the encrypted part of the task description says!The encrypted message is quite short, which means that the distribution of letters not exactly the same asgeneral English. So, to make things a little simpler, we are providing a reference text to use. If you count thenumber of times each letter appears in the reference text, and sort the letters based on how often they appear,the list will be the same as the encrypted text.A reference text of standard EnglishThis is some sample text to use as a reference. Have you heard of quokkas? They’re reallycute Australian animals that seem like little roos with big puffy cheeks! If you want tosee one, the best way is to fly to Perth, then catch a ferry over to Rottness island.There are apparently about 10,000 on Rottness island. Wow! Sometimes, if you have superbselfie skills, you can take a selfie with them! They often look like they’re smiling,which makes them very photogenic! Tortoises are also very q-ute. They have shells, yousee. Tortoises might eat juicy fish. Did you hear fish is ‘poisson’ in French? Tortoisesare better than fish. Juice is tastier than wine. Is juice a good prize?Nnnnnooooooooooooo! This sentence is still strange. quip, quid, quiz, quote, quit. Gooddogs/ pups meet bugs under beds. Ponds. Pepper. Mind mood.*Actually spelt “Rottnest”, but we needed less t’s….Your task now is to finish the class FrequencyDecryption. We have written many of the methods for you– you only need to write getKey and printTaskDescription.What could the secret message say?INFO1103 Introduction to Programming, Semester 2, 20168Example OutputThe secret message is:Well, we can’t tell you what the secret message is in the example output, butit should be in this form. at least. Blah blah blah blah blah blah blah blahblah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blahblah blah blah blah blah etc.Setting UpSetting up your workspaceIn Eclipse, create a project “info1103_task3”. In this project, create a package “cryptography”. Then, createthree classes within this package: Encrypter, SecretMessages and FrequencyDecryption.Downloading the skeleton codeDownload the skeleton code from PASTA for these three classes. Then, you can either import these classes,or copy and paste the skeleton code into each of the classes you made.Methods to completeTake a quick look at the skeleton code. You’ll notice that, in some methods, there is one of the followingcomments://TODO complete this method//TODO complete this constructorThese are the methods that you will need to write for this assignment. You don’t need to modify any of themethods that don’t have one of these comments – we have already done these for you!NOTE: we recommend that you read the rest of the task description before you start writing any of themethods!!INFO1103 Introduction to Programming, Semester 2, 20169Methods already return values!You might notice that, in some of the methods you need to complete, we have added a return statement tothe skeleton code. For example,public String getKey(){return “”; //TODO delete this when you write this method}This has been done to make your code compile. That way, you can submit to PASTA even if you haven’twritten some of the methods.When you start writing a method, delete this return statement and replace it with your own code.Method headersEach method has a header, such as:public boolean setKey(String newKey)Please do not modify these headers at all because we use them to test your code.Additional methodsYou are welcome to add any additional methods to the skeleton code if you would like to.Method CommentsFinally, you’ll notice there are blue comments above each method, which describe what each method does,what the parameters should be, and what the method will return depending on the input. Before writing anymethods, it’s very important to read these comments carefully, so you can make sure your method does exactlywhat it should!Submission InstructionsSubmitting in PASTA1. Before submitting, you should zip your source code files. Open the folder containing the classesEncrypter.java, SecretMessages.java and FrequencyDecryption.java. If you havetrouble finding the src folder, first find and open your workspace folder. Then, open the folder“info1103_task3”. The src folder will be inside. Navigate into the src folder, right click on the“cryptography” folder and choose “Send to -> Compressed (Zipped) folder”.2. Log in to PASTA () with your Unikey login and password.Note: If you are off-campus, you will need to establish a VPN connection to access PASTA. This means installinga program called “VPN client” on your computer and running it every time when you use PASTA off-campus.Instructions how to do this are available here:INFO1103 Introduction to Programming, Semester 2, 201610access-the-university-network%3FIf you have problems with VPN, try synchronising your password:If this doesn’t work, contact the ICT helpdesk: 3. Find Task 3 and press “Submit”. Then press “Choose File” and attach the zipped source files, thenpress “I accept” (after reading the University policy on academic honesty).4. If you see a message indicating that your code is queued for testing under Task 3, this means that yourcode has been uploaded successfully.5. If you see a red error box, you need to fix any problems indicated before your submission will beaccepted.6. Once your program has been tested, the page will tell you to refresh for results, so refresh the page.You should see green, red and grey boxes. Each box corresponds to a test; a red box indicates that yourprogram has failed the respective test, a green box indicates that your program has passed the test, anda grey box indicates that the test is hidden (you will not see the result of the test until after the duedate).7. If you have red boxes, you can see which tests were not passed by clicking on the task name. Correctthe errors (go to Eclipse, re-write your code and test it carefully) and then submit again in PASTA.8. For further help on using PASTA, check the INFO1103 User Manual, or post a question on Piazza.You can submit as many times as you want. Please make sure that your program compiles and runs beforeyou submit it in PASTA. Your last submission will be the one that will be marked.Marking5 marks will be allocated for the Encrypter and SecretMessages classes (core part of the task) and 2marks for the FrequencyDecryption (extension part of the task).Your mark is the percentage of the tests that you have passed. For example, if you pass half of the tests for thecore part of the task and all of the tests for the extension, you will receive 50% of 5 marks + 100% of 2 marks= 4.5 marks total. If you do not attempt the extension part of the test, the maximum mark you can get is 5/7.本团队核心人员组成主要包括BAT一线工程师,精通德英语!我们主要业务范围是代做编程大作业、课程设计等等。我们的方向领域:window编程 数值算法 AI人工智能 金融统计 计量分析 大数据 网络编程 WEB编程 通讯编程 游戏编程多媒体linux 外挂编程 程序API图像处理 嵌入式/单片机 数据库编程 控制台 进程与线程 网络安全 汇编语言 硬件编程 软件设计 工程标准规等。其中代写编程、代写程序、代写留学生程序作业语言或工具包括但不限于以下范围:C/C++/C#代写Java代写IT代写Python代写辅导编程作业Matlab代写Haskell代写Processing代写Linux环境搭建Rust代写Data Structure Assginment 数据结构代写MIPS代写Machine Learning 作业 代写Oracle/SQL/PostgreSQL/Pig 数据库代写/代做/辅导Web开发、网站开发、网站作业ASP.NET网站开发Finance Insurace Statistics统计、回归、迭代Prolog代写Computer Computational method代做因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com 微信:codehelp
网友评论