Solved

Help with code...

Posted on 2001-06-09
5
199 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Saving Tweets with emojis using Twitter4J in a Mysql table 2 73
base64 decode encode 12 119
Error with Java/Cache JDBC Classpath 2 30
expectj telnet failing 5 17
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

930 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

19 Experts available now in Live!

Get 1:1 Help Now