Link to home
Start Free TrialLog in
Avatar of jimmyjoe
jimmyjoe

asked on

Help with code...

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;
}
Avatar of djbusychild
djbusychild

What exactly is your question? Do you want an example of this being done in a command line situation?
Avatar of jimmyjoe

ASKER

I need the HTML to make it happen...

oh, so this is an applet, then, correct?
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.
ASKER CERTIFIED SOLUTION
Avatar of superschlonz
superschlonz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial