Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

hazz25

macrumors newbie
Original poster
Oct 17, 2007
2
0
I want to make a program that will translate any text typed into a text box into a cipher and print it in another text box below.

The process will be as follows.

Each letter (excluding punctuation and spaces) wil be assigned a number in the order they are typed. For example:

123 4567 87
Hey this is a test

etc.

The numbers will correspond to the Fibonacci sequence.

i.e. 1 1 2 3 5 8 13 21 34 55 etc...

Every letter will Caesar Shift (jump forward in the alphabet) the number of letters that corresponds to the number it has been assigned.

e.g.

Testing

1 1 2 3 5 8 13
T E S T I N G

Ufuvnvt

Obviously this is quite a complicated process and as i am a relative newbie to XCode and programming in general any help would be appreciated :)

Thanks

Harry
 
I would devide the problem in half. Write the part that takes in a string and writes the cypher out as a text based program. Get that to work. The user interface part would then only have a accept a string, send it to a program and then display the result. each program is very simple and pretty easy to write.

In general this is how you write a complex program: divide it into a set of simpler parts. For each complex part repeat as required. The trick is to choose the place to draw the dividing line such that communication across the line does not add to much complexity. A an extra bonus you choose the place for the line so you eand up with general purpose parts that can be re-used for your next project.
 
Hi
Just a quick note, you might want to read up on the modulus operator, %, when you are shifting letters. This will make calculating the cipher easier.

For example say you need to shift the letter A by 55 then A would actually map to D. One way of doing this would be something like:-

new_letter = ( old_letter + 53 ) % 26 + 'A'

I'm using 26 because there are 26 letters in the alphabet.

b e n
 
I think it wouldn't work anyway, because the resulting cypher will not be unique. Suppose you have the plaintext "CBA", which are shifted by 1, 1, and 2 values, respectively. You'll get "dcc" as cypher; so a "c" in the cypher maps to multiple values in the plaintext.
 
I think it wouldn't work anyway, because the resulting cypher will not be unique. Suppose you have the plaintext "CBA", which are shifted by 1, 1, and 2 values, respectively. You'll get "dcc" as cypher; so a "c" in the cypher maps to multiple values in the plaintext.

That wouldn't matter because all you would have to do is run it through the cipher backwards to gain the plain text, having "c" map to multiple values would actually make the cipher strong because it would be harder to crack.

Stephen
 
That wouldn't matter because all you would have to do is run it through the cipher backwards to gain the plain text, having "c" map to multiple values would actually make the cipher strong because it would be harder to crack.

I assume you are joking. Otherwise, I have a perfect cypher for you: Simply replace every letter in your plaintext with the letter "q" (I could have picked "a", but "q-cypher" sounds cooler). When decoding, every letter in the cypher gets replaced by "Could be anything from a to z" :)
 
I assume you are joking. Otherwise, I have a perfect cypher for you: Simply replace every letter in your plaintext with the letter "q" (I could have picked "a", but "q-cypher" sounds cooler). When decoding, every letter in the cypher gets replaced by "Could be anything from a to z" :)

SRossi is not joking and is correct. Because the position of the letter in the complete ciphertext determines the shift, the corresponding plaintext letter can always be uniquely determined. The problem you suggest would occur only if you were to take a ciphertext letter out of context, but with the context of the entire ciphertext, you will always be able to determine the plaintext.
 
SRossi is not joking and is correct. Because the position of the letter in the complete ciphertext determines the shift, the corresponding plaintext letter can always be uniquely determined. The problem you suggest would occur only if you were to take a ciphertext letter out of context, but with the context of the entire ciphertext, you will always be able to determine the plaintext.

You are right of course, and so is SRossi. It's actually a version of the Vigenere cipher, which is quite difficult to break. (Provided, of course, you don't use Fibonacci numbers as the key, like miles01110 said.)

I must have been sleeping when I posted.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.