3 Replies - 4170 Views - Last Post: 04 December 2012 - 12:02 PM Rate Topic: -----

#1 Quang Pham  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 74
  • Joined: 18-November 12

How to use a substitution cipher to encode and decode a message.

Posted 04 December 2012 - 05:00 AM

I am having problems with encoding and decoding a message. I'm trying to program a substitution cipher. Does anyone have any idea where to start?
/**
 * Write a description of class SubstitutionCipher here.
 * 
 * @Quang Pham
 * @12/3/12
 */
public class SubstitutionCipher
{
    private int shift;
   {
    public interface Message Decoder
     {
         public String decode(String cipher text);
         {
            }
        }
    public interface Message Encoder
    {
         public String encode(String plain text);
         { character c;
           String ciher text = "  ";
           for (int i = 0, i < plaintext.length, i++)
           {c = plaintext char At(i);
            cipher text = cipher text + code character
           }
         return cipher text;
        }
        private character code character (character, 6)
        {
            return (char)(ct shift)j;
    }
}

Attached File(s)

  • Attached File  Lab8.zip (3.03K)
    Number of downloads: 129


Is This A Good Question/Topic? 0
  • +

Replies To: How to use a substitution cipher to encode and decode a message.

#2 Kinaces  Icon User is offline

  • D.I.C Head

Reputation: 78
  • View blog
  • Posts: 230
  • Joined: 04-October 12

Re: How to use a substitution cipher to encode and decode a message.

Posted 04 December 2012 - 07:45 AM

Boy is this general...Are you talking about a simple substitution? polygraphic? The ROT_13? Polyalphabetic? I'm going to assume you just mean the simple ROT-13 cipher.

Well it all depends if you want to use ASCII or hard code the alphabet into 2 parallel arrays. I suppose I can give a solution to both.

A parallel array would be easy. One array with A-M, and the other has N-Z. Loop through the array to find the index of the letter you are looking for. Then use that index on the other array to find out what character you should be using.

As for ASCII you would have to convert the message to all lower case or all upper case. (I suggest upper case since that's how most ciphers are represented.) ASCII for A - Z is 65 - 90 respectively. If you have a character that is 77 or lower just add 13, and you have your new character.(This is why this method is called rotate 13.) Anything above 77 you would subtract 13.

These are both very simple, but should satisfy basic requirements.
Was This Post Helpful? 1
  • +
  • -

#3 pbl  Icon User is offline

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

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: How to use a substitution cipher to encode and decode a message.

Posted 04 December 2012 - 09:23 AM

http://www.dreaminco...-ceasar-cipher/
http://www.dreaminco...igenere-square/
http://www.dreaminco...-playfair-code/
http://www.dreaminco...he-adfgvc-code/
http://www.dreaminco...e-computer-era/
http://www.dreaminco...e-xor-operator/
http://www.dreaminco...-prime-numbers/
http://www.dreaminco...-quadruple-xor/
http://www.dreaminco...xchanging-keys/

:)
Was This Post Helpful? 1
  • +
  • -

#4 Quang Pham  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 74
  • Joined: 18-November 12

Re: How to use a substitution cipher to encode and decode a message.

Posted 04 December 2012 - 12:02 PM

Thank you for your replies. I will try to implement them in my code.
Quang Pham
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1