Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help with code...

Posted on 2001-06-09
5
Medium Priority
?
234 Views
Last Modified: 2010-03-31
I want to have the user enter encrypted text in a text box then click a button to view it unencrypted.

Assume
#1: user already has the encrypted text
#2 The text needs to be unencrypted by the following


Public String decode(String s)
{
   byte byte0 = 20
   s = s.trim();
   int j = s.length();
   char ac[] = s.toCharArray();
   for(int i = 0; i < j; i++)
   {
       int k = ac[i] - byte0;
       if(k < 32)
           ac[i] = (char) (95 + k);

       else
           ac[i] = (char)k;
   }

   String s1 = new String(ac);
   return s1;
}
0
Comment
Question by:jimmyjoe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 5

Expert Comment

by:djbusychild
ID: 6171730
What exactly is your question? Do you want an example of this being done in a command line situation?
0
 

Author Comment

by:jimmyjoe
ID: 6171764
I need the HTML to make it happen...

0
 
LVL 5

Expert Comment

by:djbusychild
ID: 6171777
oh, so this is an applet, then, correct?
0
 
LVL 5

Expert Comment

by:djbusychild
ID: 6171788
when you embedd the applet, give it a name
<APPLET name="myapplet"> or something

make sure your decode method is public, and
write a little script that calls it from the html side
<script language="javascript">
function decode(inputfield) {
 var encodedstring=inputfield.value;
 var decodedform=inputfield.form["decoded"];
 var decodedstring=document.myapplet.decode(encodedstring)
 decodedform.value=decodedstring;
}
</script>

then you can have a text box like so
<form method="get" action="#">
<input type="text" name="encoded">
<input onclick="decode(this);" type="button" value="decode"><br />
Decoded: <input name="decoded" type="text"><br />
</form>

That's the rought idea, try it out.. hope it helps

I heard that there was a limiation on the IE MAC's jvm that doesn't allow scripting applets, you might want to make sure.
0
 
LVL 3

Accepted Solution

by:
superschlonz earned 1200 total points
ID: 6171796
Her is some code which might do what you want (decode.java):

import java.applet.Applet;
import java.awt.TextArea;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class decode extends Applet implements ActionListener
{
     TextArea ta = new TextArea();

     public void init()
     {
          setLayout( new BorderLayout() );
          add( ta, BorderLayout.CENTER );
          Button b = new Button( "decode" );
          add( b, BorderLayout.NORTH );
          b.addActionListener( this );
     }
     public void actionPerformed(ActionEvent e)
     {
          ta.setText( decode( ta.getText() ) );
     }
     public String decode( String s )
     {
          byte byte0 = 20;
          s = s.trim();
          int j = s.length();
          char ac[] = s.toCharArray();
          for(int i = 0; i < j; i++)
          {
               int k = ac[i] - byte0;
               if(k < 32)
                    ac[i] = (char) (95 + k);
               else
                    ac[i] = (char)k;
          }

          String s1 = new String(ac);
          return s1;
     }
}

and the html file which embeds the applet:

<html>
<head>
<title>decode</title>
</head>
<body>
<applet code="decode" codebase="." width="400" height="300">
</applet>
</body>
</html>

I hope this will help.

superschlonz
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

636 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