Solved

monoalphabetic cypher

Posted on 2006-11-17
4
391 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:isarasoo
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 125 total points
ID: 17970354
You can pad it with extra characters to make a multiple of 5
0
 
LVL 10

Expert Comment

by:fostejo
ID: 17971220
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..
0
 
LVL 10

Expert Comment

by:fostejo
ID: 17971879
Oops, sorry isarasoo,

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

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

0
 
LVL 16

Expert Comment

by:AlexNek
ID: 17972938
> 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]);
    }
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question