# Cipher Program with XCode (Cocoa)

Discussion in 'Mac Programming' started by hazz25, Oct 17, 2007.

1. ### hazz25 macrumors newbie

Joined:
Oct 17, 2007
#1
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

2. ### ChrisA macrumors G4

Joined:
Jan 5, 2006
Location:
Redondo Beach, California
#2
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.

3. ### lazydog macrumors 6502a

Joined:
Sep 3, 2005
Location:
Cramlington, UK
#3
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

Joined:
Oct 17, 2007
5. ### natewsmith macrumors regular

Joined:
Sep 9, 2007
Location:
Santa Clara, CA
6. ### Sander macrumors 6502

Joined:
Apr 24, 2008
#6
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.

7. ### SRossi macrumors regular

Joined:
May 27, 2009
Location:
Glasgow, Scotland
#7
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

8. ### Sander macrumors 6502

Joined:
Apr 24, 2008
#8
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"

9. ### 3D0G macrumors regular

Joined:
Oct 7, 2009
#9
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.

10. ### miles01110 macrumors Core

Joined:
Jul 24, 2006
Location:
The Ivory Tower (I'm not coming down)
#10
It's a nice toy problem, but if you were using this to conceal something you actually wanted to keep a secret the key could be determined in about 2 seconds :-\ The Fibonacci sequence isn't exactly obscure.

11. ### Sander macrumors 6502

Joined:
Apr 24, 2008
#11
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.