• Post Reply Bookmark Topic Watch Topic
  • New Topic

Encoding a message using Caesar shift  RSS feed

 
carlos reyes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good afternoon everyone

I have an assignment, similar to ones of seen in the past. The assignment is to take a users text input and to encrypt it using 3 different types of encryptions: Caesar, Transpose, and Reverser. The professor gave us the bulk of the code, and more specifically how to tokenize and shift the letters using Caeser shift. The problem im coming across is that it is not showing anything past the users input. After running it, it just stays there running without showing anything.
Cipher:


Caeser Class


The constants have their own separate class, and they appear to work fine. I know that the Transpose and Reverser are incomplete, hence them commented out. But if i cant finish with Caeser first, it wont work at all.

Thank you all for any hlep.
 
Campbell Ritchie
Marshal
Posts: 56522
172
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Divide and rule. Start by copying all that code somewhere so you can restore it later, and delete about 95% of it. Cut it down to the absolute minimum and gradually put it back together. Put some print statements in, for example this after your line 16:-
System.out.printf("You entered \u201c%s\u201d%n", input); //test
Whenever you get one bit to work, take out the test code and apply similar test code to the next bit.
 
carlos reyes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

Divide and rule. Start by copying all that code somewhere so you can restore it later, and delete about 95% of it. Cut it down to the absolute minimum and gradually put it back together. Put some print statements in, for example this after your line 16:-
System.out.printf("You entered \u201c%s\u201d%n", input); //test
Whenever you get one bit to work, take out the test code and apply similar test code to the next bit.


I started doing that, and where it starts to not work is at line 66. When the c is created, it stops doing anything from there. It doesnt even show the console SOUT. However before it, everything works fine.
 
Campbell Ritchie
Marshal
Posts: 56522
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't understand, I am afraid. Please explain exactly what happens, and also post the code you are using at that stage, complete with print instructions, and minus the commented‑out lines.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
carlos reyes wrote:After running it, it just stays there running without showing anything...

First, I totally agree with everything that Campbell said. There is no way you should have got to 150 lines of code without at least 20 stops along the way to check that what you've done works. Unfortunately, you've also got a lot of code that's been handed to you, but even so...

A great mantra to get to know; at least while you're learning:
5 lines of code...compile...and TEST. The key to a happy life.

I don't know how your code looks now, but your constructor at line 13 seems odd.
First: If you're passing in text, why are you ALSO creating a Scanner?
Second: I can't see anywhere that 'message' is actually set, so all that other StringTokenizer stuff (which is a legacy class, BTW) would appear to be irrelevant.

HIH

Winston

 
carlos reyes
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I literally got 95% of thr code from my professor. It was essentialy "Fil in the blanks". I eventually figured this out, by removing everything I did. As you said, scanner doesnt need to be there. Once I removed that and initialozed message, it worked out. Thanks for the help.
 
Campbell Ritchie
Marshal
Posts: 56522
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote: . . . StringTokenizer stuff (which is a legacy class, BTW) . . .
Unfortunately, that was probably in the code the other CR was given. Obviously that is an exercise which has been repeated unchanged for 15 years, ever since tokenizer was up‑to‑date

Otherwise I would have commented similary.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once I removed that and initialozed message, it worked out. Thanks for the help.

You're most welcome. Glad we could help.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!