• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Help With Caesar Shift

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]
 
author & internet detective
Posts: 41905
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jeff Johnson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jeff Johnson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic