Welcome to the Ranch.You didn't quite get the code tags right so I have fixed them for you. The way to use them is to highlight the code and then click the 'code' button.As for your problem, your comment 'I'm kind of lost on what to do next in the code.' You shouldn't be writing any code at all until you know exactly how to solve the problem. I suggest you turn off the computer, get a pencil and paper and write down in find detail exactly how you would encrypt a using the 2 alphabets your have.
Once you have instructions a 5 year old could follow then you are ready to write code. Tony, I understand that in English I need the program to take a phrase like 'love bites' and encrypt it to 'opkd jlrdi' then print the encrypted phrase and afterwards reprint the original phrase 'love bites.' I need my phrase which is converted to a character array to take the index value of the alphabet array then input the encrypted value and output it then do the reverse. I believe I use a for loop to accomplish this but my dyslexic brain can't process it. Some pointers as to the logic the program should follow would be greatly appreciated.
I know I will never be a programmer. I just want to pass this course. Katrina Giznsky wrote:Tony, I understand that in English I need the program to take a phrase like 'love bites' and encrypt it to 'opkd jlrdi' then print the encrypted phrase and afterwards reprint the original phrase 'love bites.'
I need my phrase which is converted to a character array to take the index value of the alphabet array then input the encrypted value and output it then do the reverse. I believe I use a for loop to accomplish this but my dyslexic brain can't process it. Some pointers as to the logic the program should follow would be greatly appreciated. I know I will never be a programmer. I just want to pass this course.So here is what you wrote, broken out a little differently1) take in a phrase2) encrypt it3) print the encrypted phrase4) decrypt the encrypted phrase5) print out the decrypted phrasenote that at no point here do you talk in 'java' terms - that's GOOD!!!then you sayI need my phrase which is converted to a character array.and there you blow it.
Still not be talking in terms, so you should't be thinking about 'character arrays' yet. But ignoring that for now:to take the index value of the alphabet array then input the encrypted value and output it then do the reverse.this is where you start really thinking a little wrong. There is WAY too much in that one statement.but aside, I'd start with the above. My first run at the above would be to write a program that prints EXACTLY THIS:get a phraseencrypt the phraseprint the encrypted phrasedecrypt the encrypted phraseprint the decrypted phraseThat should't be too hard. Five System.out.println statements, and i'm done.Now I need version 2. For that, I would focus on changing the first println statement into a method call. Create a method named something like 'getUserInput'.
Instead of printing 'get a phrase' in the main method, call the method, and have IT print 'getting user input'. Once THAT works, work on changing it to actually GET the user input. Eventually, it can return the input back to the main method, and you can now use it there. Then work on one of the other methods. The idea is to focus on one part, and ignore everything else until you are sure you have the once piece right. You should end up compiling and about every 2-3 lines of code you write. The more you compile and test, the easier it is to find your mistakes.
Cryptography, or the art, science and mathematics of keeping messages secure, is at the heart of modern computer security.Primitive cryptographic operations such as one-way hash functions, also known as message digests, and encryption, either with symmetric or asymmetric algorithms, form the basis for higher level mechanisms such as MAC ( Message Authentication Code), digital signature and certificates. At yet another level, these are merely building blocks for security infrastructureconsisting of PKI, secure communication protocols such as SSL and SSH, and products incorporating these technologies.The study of principles and algorithms behind these cryptographic operations and security protocols is fascinating but oflittle practical relevance to a Java programmer.
A typical Java programmer programs at a much higher level, dealing mostlywith the APIs, configuration options, proper handling of cryptographic entities such as certificates and keystores, and interfacing with other security products to satisfy the application's security needs. At times, there may be decisionsto be made with respect to the most appropriate mechanism, algorithms, parameters and other relevant aspects for solving theproblem at hand. At other times, the challenge may be to design the application so that it can be deployed under differentsituations to satisfy different security and performance needs. At yet other times, the primary objective may be simply toachieve the best possible performance, scalability and availability of the application without compromising the level of securityby selecting the right security products. Our discussion of cryptography with Java in this and subsequent chapters is structuredaround this notion of usefulness and practicality to a typical Java programmer.Two Java APIs, JCA ( Java Cryptography Architecture) and JCE ( Java Cryptography Extension) both part of J2SE SDK v1.4, define the general architecture and specific services for cryptographic operations.
Among these,JCA was introduced first and specifies the architectural framework for cryptographic support in Java. It also includes Java classesfor digital signature, message digest and other associated services.
JCE classes follow the same general structure as JCA classes, and include classes for encryption and decryption, MAC computation and a few others. We discuss the JCA architectural framework and explore various cryptographic services available with JCA and JCE in this chapter. Toward this, we develop simple programs making use of these APIs and look at their source code.Though we talk about some of the JCA and JCE APIs and present code fragments, the discussion of Java interfaces, classes and methods is anything but exhaustive.
Our intentis to get a better view of the overall picture and understand their inter-relations. If you do need the complete informationon any specific topic, refer to the J2SE SDK Javadocs and the respective specification documents. Keep in mind that the purposeof this chapter is to make you, a Java and J2EE programmer, feel at home with cryptographic capabilities of Java and not tomake you an expert on developing security software.Example Programs and crypttoolAs mentioned in the JSTK (Java Security Tool Kit) section of the Preface, this book is accompanied by a collection of utilities and example programs, termed as JSTK software. This software includes not only the source files of example programs presented throughout this book but also thevarious utility programs that I wrote in the course of researching and using Java APIs for this book. Refer to Appendix C for more information on this software.Example programs are usually good for illustrating use of specific APIs but are not written for flexible handling of input,output and other user specified parameters. In this book, we come across situations when it would be handy to have a toolthat could perform some of the operations illustrated earlier in the text but in a more flexible manner.
You will find mostoperations of this kind available through an appropriate command line tool packaged within JSTK.Example programs illustrated in this chapter can be found in the directory%JSTKHOME%srcjsbookch3ex1, where the environment variable JSTKHOME points to the JSTK home directory. The utility program covering most of the operations is crypttooland can be invoked by command 'bincrypttool' on a Windows machine and by 'bin/crypttool.sh' on a UNIX or Linux machine, from the JSTK home directory. We talk more about this utility in later in this chapter.