aspose file tools*
The moose likes Beginning Java and the fly likes Need Help With Caesar Shift Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need Help With Caesar Shift" Watch "Need Help With Caesar Shift" New topic
Author

Need Help With Caesar Shift

Jeff Johnson
Greenhorn

Joined: Mar 29, 2009
Posts: 3
Hi,
I need help with the Caesar Shift formula in this program. Any help would be appreciated.

Here is what I have:

//packer



Thanks

[edited to add code tags]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30516
    
150

Jeff,
What's the problem - does it not compile? Does it not do what is expected?

Please state what is happening vs what you expect.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeff Johnson
Greenhorn

Joined: Mar 29, 2009
Posts: 3
When I enter a three letter password such as "zip" and the amount of times for it to shift to the right, the output comes out as: Encrypted password is: 

Here is an example of what the program should do:

Input:
zip (three letter password)
25 (amount of times for it to shift)

Output:
yho (encrypted password)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

I think in this line:

System.out.println("Encrypted password is: " + (char)i);

you meant for that last "i" to be "character", eh? The variable "i" is the loop index; cast to a char, it'd be a non-printing character.


[Jess in Action][AskingGoodQuestions]
Jeff Johnson
Greenhorn

Joined: Mar 29, 2009
Posts: 3
Sorry, but when I changed the last "i" to "character", the output came out as:

Encrypted password is: z
Encrypted password is: {
Encrypted password is: |
Encrypted password is: }
Encrypted password is: ~
Encrypted password is: 
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: i
Encrypted password is: j
Encrypted password is: k
Encrypted password is: l
Encrypted password is: m
Encrypted password is: n
Encrypted password is: o
Encrypted password is: p
Encrypted password is: q
Encrypted password is: s
Encrypted password is: t
Encrypted password is: v
Encrypted password is: w
Encrypted password is: x
Encrypted password is: y
Encrypted password is: z
Encrypted password is: {
Encrypted password is: |
Encrypted password is: }
Encrypted password is: ~
Encrypted password is: 
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: p
Encrypted password is: q
Encrypted password is: s
Encrypted password is: t
Encrypted password is: v
Encrypted password is: w
Encrypted password is: x
Encrypted password is: y
Encrypted password is: z
Encrypted password is: {
Encrypted password is: |
Encrypted password is: }
Encrypted password is: ~
Encrypted password is: 
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?
Encrypted password is: ?

I'm not sure what else to do?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Well, what is that loop over "n" supposed to do? The outer loop runs once for each character; then the inner loop runs 26 times each time around the outer loop. So you're getting 26 x stroriginal.length() lines printed.

You need to get rid of that inner loop, then work on the expression "(character + n % 26) " so it represents the actual encoded character.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Need Help With Caesar Shift