6 Replies - 401 Views - Last Post: 08 October 2012 - 01:47 PM Rate Topic: -----

#1 jesusb13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-October 12

Is there a way to make a Casaer encryption without if/else statements?

Posted 05 October 2012 - 11:12 PM

I cannot use if/else statements and from what I have read online it says to use arrays but I cannot use those either. I notice that the pattern of the encryption goes from the input jgnr <-- which has to be input by a scanner. it has to make 25 of these encryption and the pattern goes 1: ifmq 2: help 3: gdko etc...... until 25:..... I have no clue where to start, all I know is that I need to make a scanner object to input, and loops, and strings.......

Is This A Good Question/Topic? 0
  • +

Replies To: Is there a way to make a Casaer encryption without if/else statements?

#2 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 851
  • View blog
  • Posts: 2,599
  • Joined: 29-July 11

Re: Is there a way to make a Casaer encryption without if/else statements?

Posted 05 October 2012 - 11:50 PM

But of course! Read all of the replies.

HERE
Was This Post Helpful? 1
  • +
  • -

#3 jesusb13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-October 12

Re: Is there a way to make a Casaer encryption without if/else statements?

Posted 06 October 2012 - 12:03 AM

View Postfarrell2k, on 05 October 2012 - 11:50 PM, said:

But of course! Read all of the replies.

HERE


Is there any specific place I should look at? I also have to use a modulus operator but don't know how to implement that.
Was This Post Helpful? 0
  • +
  • -

#4 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7877
  • View blog
  • Posts: 13,376
  • Joined: 19-March 11

Re: Is there a way to make a Casaer encryption without if/else statements?

Posted 06 October 2012 - 07:56 AM

Do you understand the logic of that example? I mean, there's your homework done for you, so you can spend the rest of your time working out how it works.

If you want further help on this one, maybe you should start by explaining as well as you can what's happening in those lines of code farrell pointed to. Once you've done that, you can point to any remaining questions, and we'll walk you through it.
Was This Post Helpful? 0
  • +
  • -

#5 jesusb13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 05-October 12

Re: Is there a way to make a Casaer encryption without if/else statements?

Posted 06 October 2012 - 09:50 AM

View Postjon.kiparsky, on 06 October 2012 - 07:56 AM, said:

Do you understand the logic of that example? I mean, there's your homework done for you, so you can spend the rest of your time working out how it works.

If you want further help on this one, maybe you should start by explaining as well as you can what's happening in those lines of code farrell pointed to. Once you've done that, you can point to any remaining questions, and we'll walk you through it.



What I have in my code so far is this. I must use a a shift number. and enter a word and get an output. I have managed to get the program to do this. the shift and the word to encrypt are entered by the user through a scanner. after doing these steps i must enter a a word then the program must make 25 encryptions of the word I enter. the shift is not constant but it is linear in sense. what i mean is that if i enter "tuvw" as the word line 1 will give me "stuv" line 2 will give me "rstu" line 3 will give me "qrst" and so on.... until it gives you the final line which is 25th. How can I do this without if/else statements, arrays, i must use strings, for loops, explicit casts and use the modulus operator
Was This Post Helpful? 0
  • +
  • -

#6 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7877
  • View blog
  • Posts: 13,376
  • Joined: 19-March 11

Re: Is there a way to make a Casaer encryption without if/else statements?

Posted 07 October 2012 - 06:56 PM

Alphabetic shift ciphers rely on treating characters as a cyclical set of integers: a,b,c,...x,y,z,a,b,... etc. That is, a +1 = b, b+2 = d, x+3 =a, and so forth.


Strings are arrays of char under the hood. Char is a numeric type - in fact, it's an integral type.

If you understand the modulo operator, it shouldn't be hard to see how (23+3)%26= 0.

If you think about the basics of chars as an integral type, it means that 'a' is another representation for some integer. You can look up that number if you like, but whatever it turns out to be, you know that 'a'-'a' is going to be zero.

I think all of that should probably get you there. I hope so.
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Is there a way to make a Casaer encryption without if/else statements?

Posted 08 October 2012 - 01:47 PM

Don't really understand your problem with the no if requirement
Anyhow, to avoid the if for the wraparound you can always

String alphabet = "abcdefghijklmnopqrstuvwxyz";
alphabet += alphabet;

:) :^:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1