美文网首页
COMP122作业代做、代写Caesar cipher作业、代做

COMP122作业代做、代写Caesar cipher作业、代做

作者: zhazhuanxiang | 来源:发表于2019-03-25 13:52 被阅读0次

COMP122 Assessment 2Interfaces and ExceptionsDue 2019-04-05 at 5pm COMP122 Assessment 2 Due 2019-04-05 at 5pmThe Caesar cipherThe Caesar cipher is an ancient method of encrypting text, i.e. attempting to transform text into aformat that is unreadable by others.The Caesar cipher is a ‘rotation cipher’ and operates by translating each letter into the one that isshi�ed along the alphabet by a fixed distance. This distance is called the shi�. It is the same for allletters in the alphabet and therefore can be seen as the secret key to encrypt and decrypt: To encryptyour text using a given shi�, you translate letters by that many places later in the alphabet. A Caesarcipher with shi� 3 can be illustrated as follows.For example, if your text to encrypt is ‘Meet me at midnight under the bridge’ and your shi� is 3, theencrypted text is ‘Phhw ph dw plgqljkw xqghu wkh eulgjh’, as the letter ‘b’ gets translated into an ‘e’,and ‘e’ gets translated into ‘h’ and so on. We ‘wrap around’ at the end of the alphabet, so a ‘z’ getschanged to a ‘c’ given a shi� of 3. We can interpret a negative value for the shi� as translating lettersbackwards (e.g. an ‘f’ gets encrypted as the letter ‘b’ if the shi� is 4).It is believed that Julius Caesar actually used such a cipher for his correspondence. Unfortunately forhim, this type of cipher is easily broken using a frequency analysis method. This method is outlinedbelow and your assignment is to implement it in Java.Cracking the Caesar cipher.Suppose we are given a cipher text, i.e. text that has already been encrypted with some (unknown)shi�, and we want to determine the original unencrypted text (typically referred to as the plaintext).To reconstruct the original text we could decode with each of the 26 possible shi�s, and take the resultthat looks ‘closest’ to an English sentence.How do we measure ‘closeness’? This is where letter frequencies and a small statistical trick comesin. First of all, we know how o�en each letter occurs on average in English text. For instance, ‘e’ is themost common letter, then ‘t’, and so on. To decode our cipher text, we can compute the frequencies ofeach letter as they appear in the text. To measure how ‘close’ these are to the known English letterfrequencies, we use the χ2-score (that is the Greek letter ‘chi’, so it’s the ‘chi-squared score’). This scoreis defined asχ2 =Xzα=a(freqα Englishα)2Englishα2COMP122 Assessment 2 Due 2019-04-05 at 5pmwhere freqα denotes the frequency of a letter α (the number of occurrences divided by the total numberof letters in the text), and Englishαis the corresponding English letter frequency. In other words, wesum the fraction over all 26 possible letters to determine this score.The χ2score will be lower when the frequencies are closer to English. Note that when we do this, weare ignoring the case of letters (we want to treat upper and lower case equally for our purposes).We will be using the following known frequencies for the letters in English, given here in a Java-stylearray arranged in the usual alphabetical order (see frequencies.java, you’re welcome).1 double[] freq = {0.0855, 0.0160, 0.0316, 0.0387, 0.1210, 0.0218,2 0.0209, 0.0496, 0.0733, 0.0022, 0.0081, 0.0421,3 0.0253, 0.0717, 0.0747, 0.0207, 0.0010, 0.0633,4 0.0673, 0.0894, 0.0268, 0.0106, 0.0183, 0.0019,5 0.0172, 0.0011};RequirementsFor this exercise you will develop two programs. The first one rotates a given plain text for a given shi�.The second one will crack a given cipher text and display the original plain text on the screen.a. (15%)Write a Java Interfacefor rotation ciphers. The interface should be calledRotationCipherand declare the following public methods. rotate, which should take a string s and an integer n as parameters and return the strings rotated by shi� n. decipher, that translates a (cipher text) string to a (plain text) string. frequencies, which computes the letter frequencies in a given string (as size-26 arrays ofdouble, as displayed above). chiSquared, which returns the χ2-score (a double) for two given sets of frequenciesb. (25%) Implement your interface in a class called Caesar. Note the hints and comments belowto help you in case you’re lost.You may assume that the original plain text is in English and that the cipher text has beenproduced using a Caesar cipher by some (unknown) shi�. This shi� has only been applied toletters, not anything else that may appear in the text, so spaces are spaces, any punctuation isle� untouched, etc. Lower case letters are transformed to lower case letters. When computingletter frequencies you need not distinguish between lower case and capital letters.c. (15%) Write an application called Rotate, which rotates a given (plain text) string by a givenshi�. This should make use of your Caesar class from part b). The shi� as well as the input3COMP122 Assessment 2 Due 2019-04-05 at 5pmstring should be read as the first and second command line parameters, respectively. The (only!)output should be the rotated string in case all goes well. See below for sample outputs.$ java Rotate 3 The ships hung in the sky in much the same way that bricks dont.Wkh vklsv kxqj lq wkh vnb lq pxfk wkh vdph zdb wkdw eulfnv grqw.$ java Rotate -13 The ships hung in the sky in much the same way that bricks dont.Gur fuvcf uhat va gur fxl va zhpu gur fnzr jnl gung oevpxf qbag$ java Rotate 13 The ships hung in the sky in much the same way that bricks dont.Too many parameters!Usage: java Rotate n cipher text$ java Rotate 13Too few parameters!Usage: java Rotate n cipher textd. (15%) Write an application called BreakCaesar, which finds out and prints a plain text messagefor a given cipher text string. As in part c), the input string should be read as (the only) commandline parameter. Sample output below.$ java BreakCaesar Vg vf n zvfgnxr gb guvax lbh pna fbyir nal znwbe ceboyrzf whfg jvgucbgngbrf.It is a mistake to think you can solve any major problems just with potatoes.$ java BreakCaesarToo few parameters!Usage: java BreakCaesar cipher text$ java BreakCaesar Too Many ParametersToo many parameters!Usage: java BreakCaesar cipher texte. (10%) Draw an UML class diagram that includes all classes and interfaces that you’ve written.This should be part of your report.f. (10%) Document your code (i.e., all interfaces, classes and methods) using javadoc comments.Generate HTML documentation and put the generated files in a separate directory called ‘docs’.g. (5%) Caesar would have written in Latin instead of English. What would we do di�erently if weknow the language we’re examining isn’t English but some other language?h. (5%) Suppose we (somehow) know that the person doing the encryption uses one shi� valuefor lower case letters, and a di�erent shi� value for upper case letters. What would we haveto do di�erently? How would that a�ect our calculations, or how would we have to alter ourprogram/calculations to account for this?Parts g) and h) are bonus questions and require no code to be written. Just comment on these questionsin your report.4COMP122 Assessment 2 Due 2019-04-05 at 5pmFor parts c) and d), make sure that your program handles the case where a user provides unexpectedinput (no, too few, too many, not the right kind of parameters) and complains with an appropriateerror message. Test your application appropriately and document expected and observed behaviourin your report.Hints and Comments1. In Java, char and int variables are (more or less) interchangeable. A Java statement like1 int diff = e - b;is perfectly legal, i.e. Java can interpret the ‘di�erence of two letters’ with no problem, andthis will give an integer value. If the two letters are of the same case, then this will give a valuebetween ?25 and 25. In particular, if ch is a lower case (char) letter, then1 int diff = ch - a;tells you how many places a�er ‘a’ that letter is in the alphabet. (The value of diff will bebetween 0 and 25 inclusive). We can use this idea in encrypting/decrypting letters. Assumingthat is a nonnegative integer, we can encrypt the (lower case) letter ch by doing the following:1 char newChar = (char) ((ch - a + shift) % 26 + a);What is this doing? First we find out the number of characters a�er ‘a’ for the letter ch, and addthe shi�. The % operator is ‘mod’, so we get the remainder le� over a�er dividing by 26. That isdoing the ‘wrap around’. Then we turn this back into a by adding the letter a and typecasting toa char variable.2. When translating letters, notice that If ch-a is between 0 and 25 (inclusive), then ch is a lowercase letter, and we encrypt as above. Alternatively, if ch-A is between 0 and 25 (inclusive), weencrypt ch similarly to get a new upper case letter. You may also use helper methods isLetter,isLowerCase etc from the Character class.3. In order to translate whole strings, recall the Java String methods we discussed in the practicals.In particular, if str is a String, then str.charAt(i) gives you the char at index i in str.4. When counting letter frequencies remember that for this exercise, we consider upper and lowercase to be the same and do not consider spaces and punctuation characters. For example, in thestring Mississippi moon!, the frequency of the letter ‘m’ is 2/15, while the frequency ofthe letter ‘s’ is 4/15.5COMP122 Assessment 2 Due 2019-04-05 at 5pmSubmission Instructions Deadline: Friday, 5 April 2019, 5:00pm Submission server: https://sam.csc.liv.ac.uk/COMP/Submissions.plYour submission should be a single compressed .zip file called comp122_assessment_2_SID.zipwhere SID should be replaced by your student ID. This file should include:1. Your implementation. This must include the .java source files, not .class files! Put everythinginto a subfolder called ‘src’2. The generated HTML documentation from part f). This should be in a subfolder called ‘docs’.3. A report in .pdf format. Include sections for each relevant part of the exercise.Marking SchemeEach part counts towards the final mark of this coursework as follows.a b c d e f g h15% 25% 15% 15% 10% 10% 5% 5%If your code does not compile and run on departmental computer systems you will su�er a penalty of5%. The same applies if your submission does not exactly follow the submission instructions regardingfile name and type.Your submission is an individual piece of work. No collaboration with other students is allowed!Expect that plagiarism detection so�ware will be run on your submission to compare your work tothat of other students. Late submissions and plagiarism/collusion are subject to the University Codeof Practice on Assessment, available here1. In particular, since these are online submissions, a latepenalty of 5% applies for every calendar day, starting on and including Saturday, 6 April.Notice that I will not grant extensions requested a�er the submission deadline on 05/04/2019!1https://www.liverpool.ac.uk/media/livacuk/tqsd/code-of-practice-on-assessment/code_of_practice_on_assessment.pdf6本团队核心人员组成主要包括硅谷工程师、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

相关文章

网友评论

      本文标题:COMP122作业代做、代写Caesar cipher作业、代做

      本文链接:https://www.haomeiwen.com/subject/ehbvvqtx.html