• Post Reply Bookmark Topic Watch Topic
  • New Topic

simple encryption/decryption program  RSS feed

 
Katrina Giznsky
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to write an encryption/decryption program for a sentence entered by the user that uses arrays. Here is my code so far and I apologize in advance for any posting errors. I'm kind of lost on what to do next in the code.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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." says it all. 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 string using the 2 alphabets your have. Once you have instructions a 5 year old could follow then you are ready to write code.
 
Katrina Giznsky
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 differently

1) take in a phrase
2) encrypt it
3) print the encrypted phrase
4) decrypt the encrypted phrase
5) print out the decrypted phrase

note that at no point here do you talk in "java" terms - that's GOOD!!!

then you say
I need my phrase which is converted to a character array...

and there you blow it. you should still not be talking in java 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 phrase
encrypt the phrase
print the encrypted phrase
decrypt the encrypted phrase
print the decrypted phrase


That 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 testing about every 2-3 lines of code you write. The more you compile and test, the easier it is to find your mistakes.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!