Ask  help  for a question about Caesar cipher

"Caesar ciphers are among the simplest devised, and rely solely on remapping characters to others in the alphabet using a constant shift modulo the size of the alphabet. The amount shifted is the key used to encipher, or decipher, the message. This remapping is usually restricted to letters, so that with a key of 2, `A' is replaced by `C', `B' by `D', ..., `X' by `Z', `Y' by `A', and `Z' by `B'. Lower case letters are mapped in an identical way to give their lower case replacements. Thus here the key is an integer in the range 1 to 25 (not 0 to 25, as there is no point replacing every `A' by an `A' etc.).
Straightforward Caesar ciphers are rather too easy to recognise however. In an attempt to maintain the basic idea, but complicate the result, what we will do is systemmatically jumble up the letters. Treating `I' and `J' as one letter from the start (so now there are only 24 different keys, assuming we still exclude mapping `A' to `A'), the 25 letters will be written to a 5 by 5 grid, by rows, and read back by columns. So, for example, with a key of 10, `A' is mapped into `L', and the grid produced is:
L M N O P
Q R S T U
V W X Y Z
A B C D E
F G H I K
and the uppercase alphabet upon encryption becomes: LQVAFMRWBBGNSXCHOTYDIPUZEK Note that here the `B' is doubled up because it represents both `I' and `J'. Thus, with this key of 10, the following line is enciphered to the one after it.
Caesar ciphers are child's play.
Vlfylt vbhwfty ltf vwbna'y hnle.
An acceptable drawback of the treatment of `I' and `J' in the grid is that a decoded message will have all `J's mapped to `I's, and all `j's to `i's"
this is a part of requirement in the whole program,I almost finished it, but I do not know thata how to make" a decoded message will have all `J's mapped to `I's, and all `j's to `i's". "Treating `I' and `J' as one letter from the start"?what does that mean?
this is my code about the part:
public static char encode(char ch,int n)  {
  while (!Character.isLetter(ch))
   return ch;
  if(ch>='A'&&ch<='Z')
  return (char)('A'+(ch-'A'+n)%26);
if(ch>='a'&&ch<='z')
  return (char)('a'+(ch-'a'+n)%26);
return ch;
public static char decode(char ch,int n)  {
  while (!Character.isLetter(ch))
   return ch;
  if(ch>='A'&&ch<='Z')
  return (char)('A'+(ch-'A'-n)%26);
if(ch>='a'&&ch<='z')
  return (char)('a'+(ch-'a'-n)%26);
return ch;
}but
how to make" a decoded message will have all `J's mapped to `I's, and all `j's to `i's". "Treating `I' and `J' as one letter from the start"?

Your teacher/instructor/professor would obviously be the final authority on this, but I think all it's saying is that when you encode, treat each 'j' you come across as an 'i', and therefore, when you decode, because you've lost information that it was a 'j' to start with, it will be mapped back to an 'i'.
One easy way to accomplish this (that would save special cases later in your for-loop) would simply be a:
String toEncode = "Djibouti"
toEncode = toEncode.replaceAll("j","i"); //obviously handle both cases instead
String encoded = encode(toEncode);
String decoded = decode(encoded);
System.out.println(decoded); //this would print "Diibouti"The other way is to simply add a special case to your encode/decode (char) methods.
Edited by: endasil on 28-Sep-2009 9:35 AM

Similar Messages

  • Asking help for performance issues about concurrent package

    One of my friends is developing a service based on resin. They use thread pool of current package in jdk1.5. The service will create a lot of threads in the thread pool. And most of the threads are waiting. What they can not make sure is how the large amount of waiting threads will affect the performance. These threads surely will occupy a lot of memory. But how will they affect the cpu?
    Some documents on the Internet say that the large amount of waiting threads will largely increase the thread switching overhead. And some others say no because the scheduler will not be affected by waiting threads. I'm not sure which one is true. Would anyone like to give me some tips? It's better if you can point out any our documents about it.
    Thanks!

    No, it just depends on Data Structures 101.
    You would have a list of ready threads, from which you would allocate one to the processor on some priority and fairness scheme, and another list of non-ready threads which you would only promote to the ready list when something happened to them that made them ready.
    And among the ready threads you would most likely use a priority queue, so that operations on it were O(log(N)). And if the ready list also included the unready list for some strange reason, operations on it would still be O(log(N)), i.e. less than linear in the total number of threads.
    And if for some strange reason it was implemented in a less efficient way than that, I would complain vociferously to the vendor. Scheduling has been going on for fifty years after all.

  • HT1420 hi im trying to buy some song but its asking me for this questions what was the first car you owned? where was your leat favorite job

    hi im trying to buy some song but its asking me for som questions
    what was the first car you owned?
    where was your leat favorte job?
    i for got can u guys help me

    hi im trying to buy some song but its asking me for som questions
    what was the first car you owned?
    where was your leat favorte job?
    i for got can u guys help me

  • HT5312 why can't I sign into my account and add a rescue email so I will be able to redo my security questions? I have been unable to buy anything from Itunes because it's asks me for security questions that I don't remember what I put

    why can't I sign into my account and add a rescue email so I will be able to redo my security questions? I have been unable to buy anything from Itunes because it's asks me for security questions that I don't remember what I put in the first place

    1. Because if you could, someone who breaks into your account could do it as well.
    2. You need to ask Apple to reset your security questions; ways of contacting them include clicking here and picking a method for your country, phoning AppleCare and asking for the Account Security team, and filling out and submitting this form.
    (96882)

  • HT5699 i can't buy  a song because it ask me for security questions and i answer and it says you did not  provide the right answer

    i can't buy  a song because it ask me for security questions and i answer and it says you did not  provide the right answer

    Go back to the article you asked this question from and pick a method of contacting Apple. Posting in these boards isn't one of them.
    (103148)

  • HT5621 Need help for security question. I forgot passwrd rescuee email. How to reset rescuee email?

    Need help for security question. I forgot passwrd rescuee email. How to reset rescuee email?

    How to reset your Apple ID security questions.
    Go to appleid.apple.com, click on the blue button that says 'Manage Your Apple ID'.
    Log in with your Apple ID and password. (If you have forgotten your Apple ID password, go to iforgot.apple.com first to reset your password with a password recovery email)
    Go to the Password & Security section on the left side, and click on the link underneath the security questions that says 'Forgot your answers? Send reset security info email to [email]'.  This will generate an automated e-mail that will allow you to reset your security questions.
    If that doesn't work, or  there is no rescue email link available, then click on 'Temporary Support PIN' that is in the bottom left side, and generate a 4-digit PIN for the Apple Account Security Advisor you will be contacting later.
    Next, go to https://getsupport.apple.com
    (If you see a message that says 'There are no products registered to this Apple ID, simply click on 'See all products and services')
    Choose 'More Products & Services', then 'Apple ID'.
    A new page will open.
    Choose 'Other Apple ID Topics', then 'Forgotten Apple ID Security Questions'.
    Click the blue 'Continue' button.
    Select the contact option that suits your needs best.

  • My iTunes isn't allowing me to purchase anything, since pre-ordering a song a little while ago, it's been asking me for security questions. I've typed in what a believe to be the answers but it doens't work, how do I reset my security questions?

    help?

    From a Kappy  post
    The Best Alternatives for Security Questions and Rescue Mail
    1.  Send Apple an email request at: Apple - Support - iTunes Store - Contact Us.
    2.  Call Apple Support in your country: Customer Service: Contact Apple support.
    3.  Rescue email address and how to reset Apple ID security questions.
    An alternative to using the security questions is to use 2-step verification:
    Two-step verification FAQ Get answers to frequently asked questions about two-step verification for Apple ID.

  • I Need Help for 2 questions please!

    Earlier I asked a question about how I can get notifications in the "Notification Center" on my MAC. Someone suggested that I reset the "App Store" by doing the following steps: PLEASE SEE THE PICTURE BELOW
    I did this. Now I cannot get the "Debug" off the screen each time I launch the "App Store". My first question is: How can I fix this?
    My second question pertains to my original question of not receiving ANY notifications of updates from the App Store in "Notifications". I have ALL the settings under "Software Update" in System Preferences set correctly to my knowledge (the first 3 boxes are selected). I don't know if the reset of the App Store worked or not as I have yet to get any notifications and there have been no new updates in the last hour since I did this. I did read this however http://support.apple.com/kb/PH11502 and I'm wondering if that could be my problem. If it is, how can I fix this? I have never disabled Spotlight on my "startup volume". I don't even know what that is. Can ANYONE please help?

    I don't know if you have Spotlight enabled or disabled at this point. Read the following article. Although it refers to Lion, the same commands to enable/disable Spotlight are available on Mountain Lion.
    The following may help clarify Spotlight for you.
    OS X Mountain Lion: What is Spotlight?
    Mac Basics: Spotlight.
    OS X Mountain Lion: Spotlight preferences
    Spotlight: How to re-index folders or volumes
    OS X Mountain Lion: Keywords to use in Spotlight searches
    OS X Mountain Lion: Shortcuts for searching with Spotlight

  • Need help for study work (About Java)

    Hello all,
    I am student and I am writing bachelor work for Riga Technical University (Java technology in telecommunications) and I want to know what will be the correct Java technologies about which I can write?
    Does anyone have idea or can give me content?
    Thanks.
    Regards,
    Girts

    I am student and I am writing bachelor work for Riga Technical University (Java technology in telecommunications) and I want to know what will be the correct Java technologies about which I can write?Ask your instructor.
    Seriously.
    I'm not intending any insult by being dismissive, but it just doesn't make sense to ask that question here. If you have questions about your academic curriculum, the place to resolve those questions are with your institution.
    Does anyone have idea or can give me content?If you're just hunting for ideas, do a little research to find a topic interesting to you and pertinent to your course. That's your responsibility as a student.
    That said, what I think would be a decent enough question for the forum would be, "I've done some looking into X as it relates to the Java platform, and I've come to the conclusion that Y. What issues, concerns, or feedback do you see regarding my conclusion?" And then people can answer and discuss as they choose.
    ~

  • Where 2 go for help with some questions about a logo design?

    I'm an absolute novice Illustrator user (CS4). Im doing a web site for a mate and he's given me a logo that I have made a vector drawing of. It was black and white, and I made it coloured but I have discovered that colour gets difficult when you go for grayscale! You all knew that, didn't you?
    I'm not putting the logo up here because I don't want to ask a question that's too far off the purpose of the board. So, if I can't show it here can anyone suggest another forum where people do that kind of stuff and are kind to novices please?
    Many thanks
    Martin
    Well, having a look around I think I might not be going to far off by asking so...
    http://www.imagesandwords.org.uk/test/illylogo.html
    Anything really, but bear in mind It's very like the original except it had no style, no color and less er.. precision

    >How can I make the logo better for colour and B&W?
    As I understand it, you are troubled -- among many things -- by the lack of differentiation among the spheres when you convert to grayscale. Is that correct?
    If so, there are some things to consider. For example, the original uses only two attributes -- color and size -- to differentiate the spheres. Otherwise, you have the same shapes and the same gradient fills (other than base color).
    When you remove color from the equation, you're left with only one differentiating attribute: size. Not surprisingly, you find yourself facing a dull uniformity -- the monotonicity produces monotonousness. Now, the challenge is to add back some differentiating features.
    Not a whole lot of choices here. You can develop different gradient fills for a subtle effect, but you have to be careful: If the "lighting" changes dramatically among spheres, you'll end up with an unnatural look.
    You might consider forgetting about gradient fills altogether and go with solid or texture fills. Sometimes, simpler is better... especially with a logo.

  • TS1389 My I tune a/c wont let me. It keep asking me for security question .an I give the request.this is from my ipad

    Can you help me log in my I tune store purchases .it keep asking security question

    If it's saying that your answer is wrong, then from http://support.apple.com/kb/HT5665 :
    If you have three security questions and a rescue email address, sign in to My Apple ID and select the “Password and Security” tab to send an email to your rescue email address to reset your security questions and answers.
    If you have one security question and you know your Apple ID password, sign in to My Apple ID and select the “Password and Security” tab to reset your security question.
    If you have one security question, but don't remember your Apple ID password, contact Apple Support for assistance. Learn more about creating a temporary support PIN to help Apple confirm your identity when you contact Apple Support.
    If you can’t reset them via the above instructions (you won't be able to add a rescue email address until you can answer your questions) then you will need to contact iTunes Support / Apple in your country to get the questions reset (these are user-to-user forums).
    Contacting Apple about account security : http://support.apple.com/kb/HT5699
    When they've been reset (and if you don't already have a rescue email address) you can then use the steps half-way down this page to add a rescue email address for potential future use : http://support.apple.com/kb/HT5312

  • Please, help a newbie:  Question about animating expanding containers

    Hi All,
    Short Version of my Question:
    I'm making a media player that needs to have an animation for panels sliding up and down and left and right, and the method I've been using to do this performs far slower than the speed I believe is possible, and required. What is a fast way to make a high performance animation for such an application?
    Details:
    So far, to do the animation, I've been using JSplitPanes and changing the position of the divider in a loop and calling paintImmediately or paintDirtyRegion like so:
    public void animateDividerLocation( JSplitPane j, int to, int direction) {
    for(int i=j.getDividerLocation(); i>=to; i-=JUMP_SIZE) {
    j.setDividerLocation(i);
    j.validate();
    j.paintImmediately(0, 0, j.getWidth(), j.getHeight());
    The validate and paintImmediately calls have been necessary to see any changes while the loop is going. I.e., if those calls are left out, the components appear to just skip right to where they were supposed to animate to, without having been animated at all.
    The animation requirement is pretty simple. Basically, the application looks like it has 3 panels. One on the right, one on the left, and a toolbar at the bottom. The animation just needs to make the panels expand and contract.
    Currenly, the animation only gets about, say, 4 frames a second on the 800 MHz Transmeta Crusoe processor, 114 MB Ram, Windows 2000 machine I must use (to approximate the performance of the processor I'll be using, which will run embedded Linux), even though I've taken most of the visible components out of the JPanels during the animation. I don't think this has to do with RAM reaching capacity, as the harddrive light does not light up often. Even if this were the case, the animation goes also goes slow (about 13 frames a second) on my 3 GHz P4 Windows XP if I keeps some JButtons, images etc., inside the JPanels. I get about 50 frames/sec on my 3 GHz P4, if I take most of the JButtons out, as I do for the 800 MHz processor. This is sufficient to animate the panels 400 pixels across the screen at 20 pixels per jump, but it isn't fast or smooth enough to animate across 400 pixels moving at 4 pixel jumps. I know 50 frames/sec is generally considered fast, but in this case, there is hardly anything changing on the screen (hardly any dirty pixels per new frame) and so I'd expect there to be some way to make the animation go much faster and smoother, since I've seen games and other application do much more much faster and much smoother.
    I'm hoping someone can suggest a different, faster way to do the animation I require. Perhaps using the JSplitPane trick is not a good idea in terms of performance. Perhaps there are some tricks I can apply to my JSplitPane trick?
    I haven't been using any fancy tricks - no double buffering, volatile images, canvas or other animation speed techniques. I haven't ever used any of those things as I'm fairly new to Swing and the 2D API. Actually I've read somewhere that Swing does double buffering without being told to, if I understood what I read. Is doing double buffering explicitly still required? And, if I do need to use double buffering or canvas or volatile images or anything else, I'm not sure how I would apply those techiniques to my problem, since I'm not animating a static image around the screen, but rather a set of containers (JSplitPanes and JPanels, mostly) and components (mostly JButtons) that often get re-adjusted or expanded as they are being animated. Do I need to get the Graphics object of the top container (would that contain the graphics objects for all the contained components?) and then double buffer, volatile image it, do the animation on a canvas, or something like that? Or what?
    Thanks you SO much for any help!
    Cortar
    Related Issues(?) (Secondary concerns):
    Although there are only three main panels, the actual number of GUI components I'm using, during the time of animation, is about 20 JPanels/JSplitPanes and 10 JButtons. Among the JPanels and the JSplitPanes, only a few JPanels are set to visible. I, for one, don't think this higher number of components is what is slowing me down, as I've tried taking out some components on my 3GHz machine and it didn't seem to affect performance much, if any. Am I wrong? Will minimizing components be among the necessary steps towards better performance?
    Anyhow, the total number of JContainers that the application creates (mostly JPanels) is perhaps less than 100, and the total number of JComponents created (mostly JButtons and ImageIcons) is less than 200. The application somehow manages to use up 50 MBs RAM. Why? Without looking at the code, can anyone offer a FAQ type of answer to this?

    You can comment out the lines that add buttons to the panels to see the behavior with empty panels.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.Timer;
    public class DancingPanels
        static GridBagLayout gridbag = new GridBagLayout();
        static Timer timer;
        static int delay = 40;
        static int weightInc = 50;
        static boolean goLeft = false;
        public static void main(String[] args)
            final GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            gbc.weighty = 1.0;
            gbc.fill = gbc.HORIZONTAL;
            final JPanel leftPanel = new JPanel(gridbag);
            leftPanel.setBackground(Color.blue);
            gbc.insets = new Insets(0,30,0,30);
            leftPanel.add(new JButton("1"), gbc);
            leftPanel.add(new JButton("2"), gbc);
            final JPanel rightPanel = new JPanel(gridbag);
            rightPanel.setBackground(Color.yellow);
            gbc.insets = new Insets(30,50,30,50);
            gbc.gridwidth = gbc.REMAINDER;
            rightPanel.add(new JButton("3"), gbc);
            rightPanel.add(new JButton("4"), gbc);
            final JPanel panel = new JPanel(gridbag);
            gbc.fill = gbc.BOTH;
            gbc.insets = new Insets(0,0,0,0);
            gbc.gridwidth = gbc.RELATIVE;
            panel.add(leftPanel, gbc);
            gbc.gridwidth = gbc.REMAINDER;
            panel.add(rightPanel, gbc);
            timer = new Timer(delay, new ActionListener()
                    gbc.fill = gbc.BOTH;
                    gbc.gridwidth = 1;
                public void actionPerformed(ActionEvent e)
                    double[] w = cycleWeights();
                    gbc.weightx = w[0];
                    gridbag.setConstraints(leftPanel, gbc);
                    gbc.weightx = w[1];
                    gridbag.setConstraints(rightPanel, gbc);
                    panel.revalidate();
                    panel.repaint();
            JFrame f = new JFrame("Dancing Panels");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(panel);
            f.setSize(400,300);
            f.setLocation(200,200);
            f.setVisible(true);
            timer.start();
        private static double[] cycleWeights()
            if(goLeft)
                weightInc--;
            else
                weightInc++;
            if(weightInc > 100)
                weightInc = 100;
                goLeft = true;
            if(weightInc < 0)
                weightInc = 0;
                goLeft = false;
            double wLeft = weightInc/ 100.0;
            double wRight = (100 - weightInc)/100.0;
            return new double[]{wLeft, wRight};
    }

  • Need help reinstalling Yosemite/Question about external hard drive

    I have an early MacBook Pro and I have to reinstall Yosemite because I've been getting nothing but spinning beach balls, slow loading, lag in type showing up, and wi-fi issues.  I took the laptop to the Genius Bar at the Apple store last week and they ran diagnostics on everything and all was perfectly OK.  No hardware issues, no memory issue and he said my laptop was very clean.  He saw the spinning beach ball many times while he was working on my laptop and suggested that I turn off File Vault as that could be causing the slowdown.  He said if that didn't work (it didn't) to buy an external hard drive (which I received today) and to back up everything through Time Machine then reinstall Yosemite.  I specifically bought an external HD that says "for Mac" and as soon as I connected it Time Machine opened and did the backup.
    Now these are my questions.  Are all my photos on iPhoto, and my Word for Mac documents backed up so that when I reinstall Yosemite, everything is going to be right where I left it?  Will I lose Word for Mac and have to reinstall it?  Isn't Word for Mac a one time use/install and will I have trouble and have to call Microsoft to input my authentication key in again and will they let me? I know silly questions but I'm really worried about losing stuff.
    Also step-by-step detailed instruction on how to reinstall Yosemite would really be appreciated.  Thank you!

    YoJoLo wrote:
    Are all my photos on iPhoto, and my Word for Mac documents backed up so that when I reinstall Yosemite, everything is going to be right where I left it? 
    If you have taken the backup using the Time machine then there is nothing to worry as all your photos from iPhotos and Word for mac documents are backup safely by your time machine.
    Only keep one thing in mind that the external HDD which you use for the time machine backup should have the capacity size of about 3-4 times that of your backup data size. Or else, the time machine external drive will start deleting the files if the external drive is about to be full.
    YoJoLo wrote:
    Will I lose Word for Mac and have to reinstall it?  Isn't Word for Mac a one time use/install and will I have trouble and have to call Microsoft to input my authentication key in again and will they let me?
    You absolutely don’t have to reinstall the Word for mac if its install in the first place because Time machine will backup the system installed files of your MS Word which you had installed.
    Word for mac is a one time install and you don’t have to call Microsoft for any authentication key after you have restored your Word backup files from the time machine drive. As I said before the time machine will backup your Word system installed files leaving you no chance to reinstall it again.
    YoJoLo wrote:
    Also step-by-step detailed instruction on how to reinstall Yosemite would really be appreciated.  Thank you!
    Here, Yosemite reinstall procedure......
    Important:    To reinstall OS X, you must be connected to the Internet. Make sure your power adapter is plugged in. Reinstall OS X using the built-in recovery disk.
    In the menu bar, choose Apple menu > Restart. Once your Mac restarts (and the gray screen appears), hold down the Command and R keys.
    Select Disk Utility, then click Continue.
    Select your startup disk on the left, then click the Erase tab.
    Choose Mac OS Extended (Journaled) from the Format menu, enter a name, then click Erase.
    Important:    Erasing the disk removes all the information from the disk. Be sure to back up the information you want to keep to an external device. 
    After the disk is erased, choose Disk Utility > Quit Disk Utility.
    Select Reinstall OS X, click Continue, then follow the onscreen instructions.
    Hope this helps.....

  • HT201209 I cant buy something when input my apple id it ask me some security questions about whats your avorite car?

    I need to know why i cannt buy any game on my apple id

    Forgotten Security Questions/Answers
    You need to contact Apple by:
    1 - Use the Express lane and start here:
    https://expresslane.apple.com
    then click More Products and Services>Apple ID>Other Apple ID Topics>Forgotten Apple ID security questions.
    or
    Apple - Support -form iTunes Store - Contact Us
    2 - Call Apple in your country by getting the number from here:
    http://support.apple.com/kb/HE57
    or           
    Apple ID: Contacting Apple for help with Apple ID account security
    3 - Use your rescue email address if you set one up
    Rescue email address and how to reset Apple ID security questions
    For general  information see:
    Apple ID: All about Apple ID security questions

  • I cannot buy apps. It keeps asking me for security questions.

    I cannot buy any apps. It takes me to a security questions page and when I enter the questions/answers it returns an error message.

    Philly;
    I'm sure I could be forgiven for thinking that you're having a dig at me there, with your use of the phrase "Apple won't miss your business". As in me.
    Either I've misunderstood you, or you've misunderstood me.
    My point is that we're customers. Not just me, but you, the original poster and everyone else. As customers, we have choice.
    I was simply pointing out that if a business makes it too difficult to do business with them, shop somewhere else.
    There is no law saying that anyone has to buy music from the iTunes Store, but from the reaction within the forums, you would think there was. If you look at blizzard10's post above, there appears to be more anger or frustration with the Store than is justified. Why? Simply shop elsewhere (for music). Yes, I know that doesn't answer the issue with Apps, but I believe I have covered that point sufficiently, although I will mention it again.
    When these posts about problems with the new security questions arose, I assumed it was probably simply user error. However, there appear to be so many of these posts (and therefore, a lot of people with the issue), that I now wonder if Apple have made the process either; a.) too difficult for some people, or b.) impossible for some people.
    If the problem is significant enough (and it now looks as though it is), then eventually someone at Apple will notice that sales have dropped. Yes, Apple is huge and "won't notice mine or any other individual's business". But, that's at Corporate level. Every sensible business will have someone watching a department's sales figures and the Store shuld be no exception. If those figures go down, then they will start asking questions - and fix the problem.
    In the meantime, customers, all customers, buy from the business that makes it easy to do so. Why give yourself a headache over someone else's (Apple's) mistake?
    Message was edited by: the fiend

Maybe you are looking for