Build on the software engineering skills you learned in “Java Programming: Solving Problems with Software” by learning new data structures. Use these data structures to build more complex programs that use Java’s object-oriented features. At the end of the course you will write an encryption program and a program to break your encryption algorithm.
After completing this course, you will be able to:
1. Read and write data from/to files;
2. Solve problems involving data files;
3. Perform quantitative analyses of data (e.g., finding maximums, minimums, averages);
4. Store and manipulate data in an array or ArrayList;
5. Combine multiple classes to solve larger problems;
6. Use iterables and collections (including maps) in Java.

GZ

The programming exercises are really interesting! They make programming much more fun to study. The lecturers are all great and the lessons are engaging. Enjoyed it greatly! Thank you Duke.

KE

Jan 28, 2016

Filled StarFilled StarFilled StarFilled StarFilled Star

the course content was great , thank to the teaching staff . i was so much excited about the modules... the projects were also very good , and make me feel that i became a real programmer

レッスンから

Cryptography: Keeping Information Secret

In this module, you will learn about the basics of cryptography, the science of keeping information private and secure. You will learn about simpler cryptographic systems, which were used from the Roman Empire through the early 1900s. You will learn how to implement these ciphers, as well as how to break them. To solve these problems, you will work more with processing Strings, but also learn about arrays—a way to store an indexable sequence of elements. You will be able to: (1) combine Strings using concatenation; (2) build Strings within a Java program using StringBuilder; (3) use arrays to store and manipulate collections of data; (4) refactor your programs for improved organization using object-oriented principles; (5) and practice effective algorithm design.

講師

Andrew D. Hilton

Associate Professor of the Practice

Robert Duvall

Lecturer

Owen Astrachan

Professor of the Practice

Susan H. Rodger

Professor of the Practice

字幕

Welcome back. Now you have all the concepts required to implement a Caesar Cipher. So let's get started developing the algorithm. As always, you should start with step one, working an instance of the problem yourself. Even though we have seen some instances worked, it is good to work a small instance, so you can write everything down and think it through. Let's encrypt the message I AM, which is really I, space, A-M with a key of 17, meaning you will shift each letter 17 positions through the alphabet. You might want to start by writing down the alphabet, and then writing down the alphabet shifted by 17 characters underneath it. For example, A has R beneath it, where R is 17 characters to the right of A in the original alphabet. Next you would go through and replace each character in the message with the appropriate letter from the shifted alphabet. When you are done you have the encrypted message Z RD. Great, you have finished Step 1.. Now it is time to do Step 2, and write down exactly what you just did. The first thing you did was write down the alphabet. Then you computed the shifted alphabet. The third thing you did was to look at the 0th letter of the message. Don't forget, when you index into sequences such as strings and string builders, the first element is at index zero. That letter was I, so you looked in the alphabet to find I, then you found the letter in the shifted alphabet at the same position which was Z. So, you replace the zero character of the message with Z. Next, you look at the first letter of the message which is a space If you look for space in the alphabet, you would not find it, so you would not change the character at index one of the message. Next, the second character is an A, for which you perform a very similar process as you did for the 0th character, and end up changing it to R. Finally, you do the same thing for the third character which is an M that you turned into a D. Now that you have thought through all of that, you have a list of the 17 things you did for this particular message, and this particular key. However, there's one more thing that is good to note here before you proceed. Notice that your algorithm calls for replacing characters in the message. If your message is a string, you cannot do that. As you recently learned, strings are immutable, meaning you cannot change them. If you recognize this issue now you can adjust your algorithm to reflect the fact that you want to work with a string builder. Here we've added a step at the start to create a string builder from the string message. And then we updated the algorithm to work on the string builder. If you do not realize you need to do this now, you would figure it out at a later step. But the earlier you can figure it out, everything you need to do, the better. Looking at this algorithm you can see that the first few steps are an initial setup, before you begin performing repetitive steps for each letter in the message. If you focus on the steps after the initial set-up, you can see that you are doing almost, but not quite the same thing for each character n the message. One significant difference is what you decide to do based on whether or not you find the letter in the alphabet. Replacing the current character if you find it. Or doing nothing if you do not. If you look at the steps for one particular character where the letter is in the alphabet, you will notice that the character you looked for in the alphabet is the current character in the string. And that the letter you used to replace the current character is what you found in the same position in the shifted alphabet. Now that you have thought this all through, you can write down, a much more general algorithm. Notice that the step number two here requires a little thought, and a couple of statements. But you've already seen how to do it. When you are looking for patterns, you should examine any constants, such as zero here, and ask if you always use that constant. Or if you need to look for a more general pattern. Here you always want to start from zero. What about three? Do you always want to stop counting at three? No. How high you count depends on the length of the message. Here we've written that you want to count to the length of encrypted. But noted that you want to count to less than it, not less than or equal to it. In our example, encrypted was four, and you only want to count to three. Now it's time to test out the steps. Pause the video now and try to encrypt the message, a space bat with a key of 19. Did you catch the subtle problem with this algorithm? Even though it computed everything you wanted, we never said what the final answer is. You want to be sure to explicitly say this so that you know what to return from your method when you translate the code. Your answer is the string inside of the string builder you called encrypted. Now that you have fixed this detail of your algorithm you are ready to turn it into Java code. Thank you.