Not getting last character

I wrote a method that decrypts encoded text. I have used it before (in another class) so I know that it works. Perhaps I may have just copied it wrong...though I did a copy/paste...or maybe its my coding itself. Either wasy its driving my bonkers. Here is the code I believe is the problem:
        //Decryption method
        private String Decode(String inData){
            int ans2, rn, tmp;
            String ans=new String();
            oldRN=LCG_seed;
            for(int i=0;i<inData.length();i=i+2){
                tmp=Integer.parseInt(inData.substring(i,i+2),LCG_m);
                rn=RN();
                ans2=(tmp^rn)%0xff;
                ans=ans+(char)ans2;
            return ans;
        }//Close Decode methodand it relies on this code:
        //Random Number Generator
        public int RN(){
            int rn;
            rn=(LCG_a*oldRN+LCG_c)%LCG_m;
            oldRN=rn;
            return rn;
        }and
            LCG_a=a;
            LCG_c=c;
            LCG_m=m;
            LCG_seed=s;
            oldRN=LCG_seed;Now the problem is that no matter what I use as the string input, I am always able to decrypt everything but the last character. I wish you guys better luck than I have on finding my error. Oh, and thanks for taking the time to help me. :)

I take in two at a time because the encryption puts it in hexidecimal (not exactly a hardcore encryption, but its what my teacher wants...). Maybe so though. I'm starting to doubt myself on that being the cause though. I keep goig through it and through it without finding an error. So, I am going to post my entire code.
package cryptology;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
* <p>Title: Cryptology</p>
* <p>Description: File to encrypt and decrypt general files using a keyword for
* the decryption and hidden numbers for the encryption.</p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author Joshua Williams
* @version 1.0
public class Cryptology{
    private static JTextArea input=new JTextArea();
    private static JTextArea output=new JTextArea();
    private static int Found;
    //GUI class
    public class CryptoFrame extends JFrame{
        Container contentPane;
        JMenuBar jMenuBar1=new JMenuBar();
        JMenu jMenuFile=new JMenu();
        JMenuItem jMenuFileExit=new JMenuItem();
        JMenuItem jMenuFileLoad=new JMenuItem();
        JLabel statusBar=new JLabel(" Type the text you wish to encrypt or load the file you wish to decrypt.");
        JLabel origLabel=new JLabel(" Input to Encrypt/Decrypt");
        JLabel outputLabel=new JLabel(" Encryption/Decryption of Input");
        JButton encode=new JButton("Encode");
        JButton decode=new JButton("Decode");
        JScrollPane jScroll=new JScrollPane();
        JScrollPane jScroll2=new JScrollPane();
        public CryptoFrame(){
            contentPane=getContentPane();
            contentPane.setLayout(null);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setSize(new Dimension(522, 430));
            setTitle("Encryption/Decryption");
            setLocationRelativeTo(null);
            setResizable(false);
            jMenuFile.setText("File");
            jMenuFileExit.setText("Exit");
            jMenuFileExit.addActionListener(new Exit());
            jMenuFileLoad.setText("Load");
            jMenuFileLoad.addActionListener(new Load());
            encode.addActionListener(new Encode());
            decode.addActionListener(new Decode());
            input.setBorder(BorderFactory.createLineBorder(Color.black));
            output.setBorder(BorderFactory.createLineBorder(Color.black));
            encode.setBorder(BorderFactory.createEtchedBorder());
            decode.setBorder(BorderFactory.createEtchedBorder());
            origLabel.setBounds(new Rectangle(8,0,400,20));
            input.setBounds(new Rectangle(8,20,500,155));
            jScroll.setBounds(new Rectangle(8,20,500,155));
            jScroll.getViewport().add(input);
            encode.setBounds(new Rectangle(290,180,100,25));
            decode.setBounds(new Rectangle(400,180,100,25));
            outputLabel.setBounds(new Rectangle(10,190,400,20));
            output.setBounds(new Rectangle(8,210,500,155));
            jScroll2.setBounds(new Rectangle(8,210,500,155));
            jScroll2.getViewport().add(output);
            statusBar.setBounds(new Rectangle(8,363,400,20));
            jMenuBar1.add(jMenuFile);
            jMenuFile.add(jMenuFileLoad);
            jMenuFile.add(jMenuFileExit);
            setJMenuBar(jMenuBar1);
            contentPane.add(origLabel,null);
            contentPane.add(encode,null);
            contentPane.add(decode,null);
            contentPane.add(outputLabel,null);
            contentPane.add(jScroll,null);
            contentPane.add(jScroll2,null);
            contentPane.add(statusBar,null);
            show();
        }//Close frame constructor
        //Exit class needed for the Exit menubar menu button
        public class Exit implements ActionListener{
            public void actionPerformed(ActionEvent e){
                System.exit(0);
            }//Close exiting action
        }//Close Exit class
        //Load class needed for the Load menubar menu button
        public class Load implements ActionListener{
            public void actionPerformed(ActionEvent e){
                //--------Script a load file action here--------//
            }//Close loading action
        }//Close Load class
        //Encode class needed for the Encode button
        public class Encode implements ActionListener{
            public void actionPerformed(ActionEvent e){
                Crypto c=new Crypto();
                output.setText("");
                output.append(c.Encode(input.getText()));
            }//Close encoding action
        }//Close Encode class
        //Decode class needed for the Decode button
        public class Decode implements ActionListener{
            public void actionPerformed(ActionEvent e){
                output.setText("");
                Crypto c=new Crypto();
                JFrame frame=new JFrame();
                String s="";
                boolean done=false;
                while(done==false){
                    s=(String)JOptionPane.showInputDialog(frame,"Enter a word to search for.",null,JOptionPane.PLAIN_MESSAGE,null,null,null);
                    if((s!=null)&&(s.length()>0)){
                        done=true;
                    else{
                        JOptionPane.showMessageDialog(frame,"A keyword for searching is required for decryption of text.");
                output.append(c.Decode(input.getText()));
                c.Search(s);
            }//Close decoding action
        }//Close Decode class
    }//Close frame class
    public static class Crypto{
        //Global variables for the Crypto class
        private static int LCG_a, LCG_c, LCG_m, LCG_seed, oldRN;
        //Default constructor
        public Crypto(){
            LCG_a=5;
            LCG_c=7;
            LCG_m=16;
            LCG_seed=2;
            oldRN=LCG_seed;
        }//Close default constructor
        //Advanced Constructor
        public void Crypto(int a, int c, int m, int s){
            LCG_a=a;
            LCG_c=c;
            LCG_m=m;
            LCG_seed=s;
            oldRN=LCG_seed;
        }//Close advanced constructor
        //Random Number Generator
        public int RN(){
            int rn;
            rn=(LCG_a*oldRN+LCG_c)%LCG_m;
            oldRN=rn;
            return rn;
        //Encyption method
        private String Encode(String inData){
            char tmp;
            int ans2, rn;
            String ans=new String();
            oldRN=LCG_seed;
            for(int i=0;i<inData.length()-1;i++){
                tmp=inData.charAt(i);
                rn=RN();
                ans2=(int)tmp;
                ans2=(ans2^rn)%0xff;
                ans=ans+Integer.toHexString(ans2);
            return ans;
        }//Close Encode method
        //Decryption method
        private String Decode(String inData){
            int ans2, rn, tmp;
            String ans=new String();
            oldRN=LCG_seed;
            for(int i=0;i<inData.length();i=i+2){
                tmp=Integer.parseInt(inData.substring(i,i+2),LCG_m);
                rn=RN();
                ans2=(tmp^rn)%0xff;
                ans=ans+(char)ans2;
            return ans;
        }//Close Decode method
        //Search method
        public void Search(String s){
            HighlightPainter kolor=new HighlightPainter(Color.red);
            JTextArea Area=new JTextArea();
            Highlighter hl=Area.getHighlighter();
            int StringSize=s.length();
            int Index=0;
            Found=0;
            hl.removeAllHighlights();
            while((Index=output.getText().indexOf(s, Index)) >= 0){
                try{
                    hl.addHighlight(Index, Index+StringSize, kolor);
                    Index=Index+StringSize;
                    Found++;
                }//Close try
                catch(BadLocationException e){
                }//Close catch
            if(Found<=0){
                output.append("\n\nSorry but the keyword was never found.\n\n");
            else{
                output.append("\n\nCongratulations!!! Your keyword was found "+Found+" times.\n\n");
        }//Close Search method
        public static class HighlightPainter extends DefaultHighlighter.DefaultHighlightPainter{
            public HighlightPainter(Color color){
                super(color);
            }//Close HighlightPainter constructor
        }//Close HighlightPainter class
    }//Close crypto class
    public Cryptology(){
        CryptoFrame CF=new CryptoFrame();
    }//Closes cryptology constructor
    //Required main
    public static void main(String[] args){
        Cryptology c=new Cryptology();
    }//Closes the main
}//Closes cryptology classThanks for the quick response by the way.

Similar Messages

  • Not getting Last year data in query

    Hi All
    i have created one query on cost element cube.i have two col in the query i.e amount(present year) and amount (past year).
    For getting the past year data I have set the offset -12 for the fiscalyear/ period variable in the query i also restricted the fiscal year variant v3 in the amount. but i am not getting the corect value  for the past year . if i run for 2011 and 2010 for the same period i am getting right value in Amount(present year) but if i run the query for 2011 for same period i am not geting right value in amount previous year data. Kindly help me how to  get right data.

    Hi Atul,
    There are certain restrictions when you are reporting over multiple time frames,
    1) You should not put the global restriction of the time period on which you want to display data e.g. 0CALMONTH or 0FISCPER etc.
    you can put the global restriction but it should be at high granularity. for e.g. when you are reporting on Present month and last month then you can put restriction on Year, here you should take care when you are giving input as first month then last month of previous year data will not be displayed untill year is restricted for current as well as previous year.
    Another thing is
    2) You should not put time characteristic in drill down otherwise data aggregation doesn't happen.
    If you want to take any time characteristic input then it should be included in the specific RKF only, though Input ready variables.
    Regards,
    Durgesh.

  • In IPCC express,last 4 month report i;m not getting in historical report. in report it shows blank.

    Hi all,
    we are using IPCC express 5.0 with high availability and call manager 6.0.
    Now i;m facing an issue in historical reports.i'm not getting last 4 month reportin the historical report and the report is blank.
    when i troubleshooted, i checked for filter in scheduler file, logs and i couldn;t find any issues in that.
    i observed in datastore control center, agent, historical, repository status is stopped in publisher and replication status also stopped. i tried to start it but it stopped again.
    as per customer information, also agent phones are communicating with standby server not with publisher for last 4 months.
    so i'suspect it is database replication problem for long time that is why i;m getting the report also for these 4 months.
    please find the attachment for your reference..
    please anybody can help me in this..
    thanks in advance..

    Jneklason wrote:
    ~snip~
    I know this email is confusing and really hard to understand...perhaps now you will know how i've been feeling--lost and confused with all the mis-information, with a hit and miss phone, and out of time with all the 1 1/2 hr to 2 hrs EACH wasted on this issue.
    On top of all this, I can't even find out how to file a complaint with anyone higher up than Customer Service.
    I hate to tell you this, but you didn't write an email. You wrote a discussion post on the Verizon Wireless Community forum which is a public peer to peer forum. Unfortunately since you didn't mark your post as a question, the VZW reps that roam this community won't ever see your post. Before you re-post it, don't. Duplicate posts get removed from the community.
    I see there were several missteps both by the reps and yourself in your post. First you should have insisted on returning the phone within the 14 day return policy period. Second which Samsung Galaxy mini model did you purchase? The S3 mini or the S4 mini? Did you do any research prior to deciding on this device. The reps at that time deflected the easiest course of action, by trying to get you to replace the phone under insurance instead of returning the phone. The Early Edge payment option requires the current phone on the line using the early Edge must be returned to Verizon Wireless. Did you once considered going to a third party site like Swappa to purchase a gently used device for your daughter?

  • Terms and conditions not getting displayed on the last page

    Hi All,
    I have to display a smartform, on the front side of the page i have to display material details and on the back side of the page i have to display terms and conditions. I' am unable to print the material details and terms and conditions in duplex mode, but on the last page only material details are getting displayed, terms and conditions are not getting displayed.
    Can you please help me how to make the terms and conditions get printed on the back side of the last page.
    Thanks,

    I'm a bit confused by the statement "I' am unable to print the material details and terms and conditions in duplex mode".
    I suppose you meant to say "I am able to print the material details and terms and conditions in duplex mode", correct?
    If the problem is that on the last form page, the T&C is not getting printed on the back of the form, you could force the T&C page by using a flow logic command as the very last element of the main window, which gets processed when all the data is already output. For the command, use the 'Go to New Page' and specify the page name for the Terms & Conditions.
    In case this causes an issue that the last page is printed twice (since the T&C page is likely defined with the next page being NEXT_PAGE), then copy the already existing T&C page, call it LASTPAGE and leave the Next Page attribute empty.

  • Not only do web pages not load properly but we're doing calculus on-line and only 1 video can be viewed at a time. last week we didn't have problem. wish i could call someone. not getting any help.

    a number of site say done and we see a blank page. on-line calculus class, last week could view more than 1 video at a time now only 1 can be viewed. this course need to be completed by may 3. career builders some of the drop downs aren't working. need to find a job. these are serious errors that we did not experience before. we haven't updated to 4.0. now i see the one's who have are having these problems. daughter can't gt to e-mail. wish i could talk to someone. i'm going to try the live session at 2 but i'm not a techy. can take care of most problems, but this seems beyond me. HELP
    s

    If you are wondering why you are not getting any responses, it is because you have vented a complaint without any details that make any sense or give anyone something to work on.
    If you want help, I suggest actually detailing what has happened, with versions of software etc. Anything that would let us assist.
    As a start I am guessing that you have not really got the hang of "How it all works". Firstly download the Pages09_UserGuide.pdf from under the Help menu. Read that and view the Video Tutorials in the same place. A good addition would be the iWork 09 Missing manual book and something to help you learn how to use your Mac.
    If there are specific tasks you need help with:
    http://www.freeforum101.com/iworktipsntrick/index.php?mforum=iworktipsntrick
    Is a good resource.
    Peter

  • Hi, I m using an iPhone 4 and my yahoo push email was working just fine but for the last few days I am experiencing some problem that is the emails are not getting pushed , I have to manually fetch the mails. So what could be the reason for this....

    Hi, I m using an iPhone 4 and my yahoo push email was working just fine but for the last few days I am experiencing some problem that is the emails are not getting pushed , I have to manually fetch the mails. So what could be the reason for this.....I have set the email setting to "push" mode. Moreover I can't edit the mail server address ....current it's on Yahoo SMTP server

    Will it get rectified and restored...if so after how long. What could be the reason for such outage kindly share,  as I am facing real problem because of this...

  • I set iCloud up last week and the next day when out in the field I could not get Outlook to open up.  I want to change my settings so I can get mail at home or in the field

    I set iCloud up last week and the next day when out in the field I could not get Outlook to open up.  I want to change my settings so I can get mail at home or in the field, not just when i'm at home.  I have a PC and fios internet with Verizon at home.  I have a Sprint air card in the field or access an available wifi.  I want to change my settings to allow for receiving email in the field.  What's the point of an air card and icloud for backup fi it doesn't work in the field for some odd reason?

    Apple - Support - Mail Setup Assistant

  • TS2988 I had to reset my phone and I only have one of my ringtones I had 4.. Why'd it delete 3 and not the last one and now I can't get em back without paying for them again!!! What the **** is up with that??

    I had to reset my phone and I only have one of my ringtones I had 4.. Why'd it delete 3 and not the last one and now I can't get em back without paying for them again!!! What the **** is up with that??

    Yup, your question and Diane's answer helped me also. Tho' I had had problems before getting into the iTunes store I always managed to find a way. Today they had me blocked cold with the "Update to 10" advert no matter what I did. Other questioners are being told, incorrectly as it turns out, that they have to update their OS to accomodate iTunes 10 and upgrade to iTunes 10. I did the download which did not take up much more room on my crowded old hard drive and now I'm back in business.

  • Lost all my iPhone notes during last synch - how do I get them from time machine?

    I lost all my iPhone notes in last synch - how do i get them back?

    hope that you have a back up in itunes or icloud

  • Vendor list - not get transaction from last three years

    Dear Sir,
    Can we have a list of vendor which are not get transaction from last three years ?
    Vijay Vadgaonkar
    SAP MM

    either you write a z-report
    or you download all vendor numbers from LFA1 table
    then run MC$4  transaction for analyzing period of last 3 year.
    download the vendor numbers from this report as well.
    Finally compare the both download (easiest with VLOOKUP formula) to find the delta, which are the inactive vendors.
    However, these are the inactive vendors from purchasing point of view only.
    vendors like restaurants and customs and tax authorities may only have financial postings and never purchasing activities.

  • I can not get itunes to install and open on my new laptop i am so frustrated i have uninstalled and reinstalled at least a dozen times in the last month

    i can not get itunes to install and open on my new laptop i am so frustrated i uninstalled and reinstalled at least a dozen times in the last month
    i got a error 7 this time but have had diff ones befpre please help

    Will iTunes open in safe mode? Hold down CTRL+SHIFT as, or immediately after, you click the icon that starts iTunes and keep holding until you see this prompt.
    Click Continue.
    Assuming iTunes has opened, enable the menu bar, if necessary, with CTRL+B. Then go to Edit > Preferences > Store and untick Show iTunes in the Cloud purchases. Press OK, close iTunes, wait until it has had a chance to fully close then reopen.
    Will iTunes open normally now?
    If not, see Troubleshooting issues with iTunes for Windows updates for genral advice.
    The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
    Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
    tt2
    tt2
    Message was edited by: turingtest2

  • How to get last 24 months data (if user not enter any kind of information)

    Hi all,
    I am want a report such that
    1. if user does not enter months he has to get last 24 months data(from current month)
    eg1.
    Sales
    currentmonth     300
    currentmonth-1  400
    currentmonth-20 500
    2. if user  enter months he has to get required months data(from current month)
    eg1.assume that user entered the interval of last two months.
    Sales
    currentmonth     300
    currentmonth-1  400.
    friends please me in desinging this query.
    It's very urgent,waiting for responses.
    Thanks,
    James.

    Hi james,
    1. if user does not enter months he has to get last 24 months data(from current month)
    ANS: U have to create variable Of  Currentmonth with The following
             Process Type: SAP Exit
             Variable Represent: Single value
            Variable Entry: Optional
    Check chekboxes for <b>Ready for Input</b> & Can be change in Query navigation.
    b) After this u have to give offsets by restricting this variable
    2. if user enter months he has to get required months data(from current month)
    ANS:
    For this U have to use Process Type: User-exit( User Entry)
    & After that specify the offsets by restriction.
    Thanks,
    kiran.
    Message was edited by:
            kiran manyam

  • I updated my phone last Wed. and now I am not getting my emails pushed to my phone from yahoo.  What's the problem?

    I updated my phone last Wed with IOS 6 and now I am not getting my emails pushed to my phone from yahoo.  any idea why or how to fix this?

    you'll have to set it up as a new phone.  You have no choice.  If you've been using your phone as recommended, you should have little, if any, data loss.

  • TS4036 my last auto backup was on 10/8 talked to apple because I was not getting e-mail so we ended up resetting phone only got back contacts no pics or apps nobody can help me

    my last auto backup was on 10/8 talked to apple because I was not getting e-mail so we ended up resetting phone only got back contacts no pics or apps nobody can help me

    solved

  • I am not getting my iCloud or other mail thru...I had an update last week and it quit also.  I simply turned mail off and on and it solved the problem.  Now simply nothing is coming thru....I think I've tried everything....can anyone give me suggestions

    I am not getting my iCloud or other mail thru...I had an update last week and it quit also.  I simply turned mail off and on and it solved the problem.  Now simply nothing is coming thru....I think I've tried everything....can anyone give me suggestions

    I am not getting my iCloud or other mail thru...I had an update last week and it quit also.  I simply turned mail off and on and it solved the problem.  Now simply nothing is coming thru....I think I've tried everything....can anyone give me suggestions

Maybe you are looking for

  • Dvd1270i multiformat rom no longer found on pc

    hello everyone i have an hp dvd 1270i multiformat dvd/cd rom. Don't know the exact date when i bought it. However, it was working fine. But for the past several months, when i attempt to eject the door, it would make a clicking noise, and eventually

  • The iPhone 5 is terrible...want to return!!!

    I bought my iPhone 5 in December and I spent a ridiculous amount of money for it...even buying it at discount! Since then, my data has been exponential and I end up owing over a hundred dollars plus in data overage charges! I was told to turn of the

  • Lenovo A3500-FL Android Tablet. Won't Enrypt

    Hello. Not sure if anyone else has run into this problem, but my A3500-fl won't encrypt. It starts to reboot but that's all it does. Never encrypts, and it's keeping me from adding my work email to it.

  • HT201320 Which Apple ID should I use to set up my iPad?

    If I have 2 Apple IDs, one for iTunes and one for mail, calendars, etc., which do I use when setting up my iPad?

  • SQL within PL/SQL block

    This question sound funny. I just want to make sure this rule. In Oracle database before 10g, we can only use DML and transaction control code within PL/SQL block. We can not use DDL or other control languages within PL/SQL block. How about 10g? can