| 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: 26184
|
|
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: 24057
|
|
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: 24057
|
|
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.
|
 |
 |
|
|
subject: Need Help With Caesar Shift
|
|
|