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
Solved

Help with code...

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 104
login jsp example 24 65
Html Table Looping (part 2) 5 27
java mysql insert application 14 28
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 …
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.

860 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