Solved

Help with code...

Posted on 2001-06-09
5
189 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
  • 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 300 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
strDist challenge 35 84
maven java path setting 5 50
base64 decode encode 12 97
Unexpected HttpURLConnection connection behavior 2 51
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now