Link to home
Start Free TrialLog in
Avatar of isarasoo
isarasoo

asked on

monoalphabetic cypher

im fairly new to cryptography, my aim is to write a program which can perform ceaser cypher on a input string and output the result in groups of 5 i.e. : kkkkk-jjjjj-lllll-mmmmm

as far as i understand i have to take letters from the input string and shift a certain amount of characters down the alphabet, which i can do.  however im having difficulties understanding how i will output the results in groups of 5 if the string is less than 5 characters long.

im implementing it in java so i will be greatful for any examples

cheers
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fostejo
fostejo

isarasoo,

The problem you have here is that the Caesar Cipher is fundementally designed to replace each character in the string to be "encrypted" with another known character somewhere else in the alphabet.

Therefore, an input string of 'n' characters long must also have "encrypted" version of 'n' characters long.

Padding any string that's not a multiple of 5 characters with anything will compromise the end result (which isn't in any way secure anyway, BTW!) - probably the 'best' you could do was to indicate padded characters with a non-alphabetic character... but that isn't really a classic Caesar Cipher and immediately tells any potential 'decryptor' that those characters can be ignored anyway.

I think the solution here would be to remove the imposed limitation.. ie. Is it really critical that you must output in groups of 5?

I'm no Java expert so can't help with the code on that front I'm afraid, but the following page gives more info about the Caesar Cipher and includes links at the bottom to some other resources including sample code.

Hope that helps..
Oops, sorry isarasoo,

Just noticed I didn't give you the link!   ;)

http://en.wikipedia.org/wiki/Caesar_cipher

> im having difficulties understanding how i will output the results in groups of 5 if the string is less than 5 characters long.

first, to check how many symbols in the input line. If less than 5 that write less than 5 symbols in output string too. Or you can first count the group numbers by dividing symbols numbers by 5.
Here is my pseudo code for output.

    for (int i = 0; i < outString.Length; i++) {
      //divide to group by 5
      if  ((i %5 )== 0)
      {
         System.out.print(" ");
      }
      System.out.print( ndoutString[i]);
    }