?
Solved

Help with code...

Posted on 2001-06-09
5
Medium Priority
?
229 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

770 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