Hello EZ,
a member here asked me if I could teach some Java.
I did some Skype sessions in the past, however, that won't work anymore, since I have to care for a little baby and I can't plan anything. But I promised to give assignments, answer questions and review the code.
The final goal will be a cryptography application with a Swing GUI, so not only learning Java, but also some cryptography on the way.
I will post the assignments here for everyone who wants to join, so that maybe more people can profit from that.
The first assignment only needs some basics in command line input/output and loops.
If you have any questions, just ask.
1. Assignment - basic IO Write a program that asks a user for input. If the user presses enter, the input is echoed back to the command line. The computer asks again for input (and echoes it back) until the user enters "exit" or "quit".
An example output might look like this:
your input?
aaa
aaa
your input?
Hello
Hello
your input?
exit
2. Assignment - encoding a stringModify your program from assignment 1.
Instead of repeating the user input the computer prints out the letters that follow right after in the ASCII chart.
Have a look at the ASCII chart here:
http://www.asciitable.com/Example output:
your input?
a
b
your input?
ab;
bc<
your input?
zZ8
{[9
Hint: Make use of the data type
char. The value of a char is the same as in the ASCII table, i.e. 'a' == 97.
3. Assignment - a shift cipherModify your program from assignment 2.
You have to add a little feature now. In assigment 2 every character of the string was shifted by one character. Now let the user decide how many characters should be shifted.
Set bounds to the characters used. The bounds should be from 32 (= ' ') to 126 ('~').
So if your program shifts over the bounds (overflow) it should shift the rest from the lower bounds (32). If the user enters a negative shift value and the bounds are underflowed, it should shift the rest from the higher bounds (126).
---------------------------------------------------------------------------------------------
Info: This is a very simple cipher now, called shift cipher or caesar's cipher:
https://en.wikipedia.org/wiki/Caesar_cipherThe key of the encryption in this case is the number the characters are shifted.
The key of decryption is -key of encryption (so you shift it back).
This cipher is a good one to implement (it is simple) and to show vulnerabilities of ciphers (it is easy to crack). That's the reason I chose it.
But if you stay tuned we will also use Java for something that is used today (like AES)
For more theoretical background:What is a cipher? (
https://en.wikipedia.org/wiki/Cipher)
In cryptography, a cipher (or cypher) is an algorithm for performing encryption or decryption—a series of well-defined steps that can be followed as a procedure.
[...]
When using a cipher the original information is known as plaintext, and the encrypted form as ciphertext. The ciphertext message contains all the information of the plaintext message, but is not in a format readable by a human or computer without the proper mechanism to decrypt it. The operation of a cipher usually depends on a piece of auxiliary information, called a key (or, in traditional NSA parlance, a cryptovariable). The encrypting procedure is varied depending on the key, which changes the detailed operation of the algorithm. A key must be selected before using a cipher to encrypt a message. Without knowledge of the key, it should be difficult, if not nearly impossible, to decrypt the resulting ciphertext into readable plaintext
The shift cipher is a substitution cipher. (
https://en.wikipedia.org/wiki/Substitution_cipher)
In cryptography, a substitution cipher is a method of encryption by which units of plaintext are replaced with ciphertext, according to a regular system; the "units" may be single letters (the most common), pairs of letters, triplets of letters, mixtures of the above, and so forth. The receiver deciphers the text by performing an inverse substitution.
---------------------------------------------------------------------------------------------
Preparation assignment 4In preparation for the next assignment try to answer those questions (if you are sure you are right, it is enough to answer this for yourself, if not ask me):
How do you decrypt an encrypted message with a shift of 5?
How many keys has your shift cipher?
Which vulnerabilities has this cipher?
How would you try to crack a (large) message encrypted by shift cipher?
If you have absolutely no idea, read the wikipedia article about the shift cipher:
https://en.wikipedia.org/wiki/Shift_cipherIt helps if you first go away (mentally) from how to code the cracking. Just think about a way you could crack a message that you get on paper.
4. Assignment - shift cipher crackWrite a program that cracks a message which was encrypted by a shift cipher.
If you have no idea how to start, tell me how you want to crack the cipher and I will help you by separating your task into steps.