473,473 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How would I make a secret code on Javascript?

2 New Member
Here is what I have now as a base code. Basically, it is two text inputs, one on top of the other. In one, you enter text, and in the other, the text is changed. What I would like to do is have you enter text in one box and in the other, have it turn out like this:
A=B
B=C
C=D
D=F
E=E
F=H
G=G
H=I
I=J
K=K
L=M
M=N
N=P
O=O
P=Q
Q=S
R=R
S=T
T=U
U=V
V=W
W=X
X=Y
Y=Z
Z=A

So for instance, if I entered the word "hi" in the first box and clicked the submit button, in the second box, "ij" would appear.
Here is my base code. Can anyone kindly help me?

Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3.  
  4. <SCRIPT LANGUAGE="JavaScript">
  5. <!-- Beginning of JavaScript -
  6.  
  7. function encode(text) { Ref="0123456789abcdefghijklmnopqrstuvwxyz.-~ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  8. Result=""
  9. for (Count=0; Count<text.length; Count++) {
  10.  
  11. Char=text.substring (A=b);
  12. Num=Ref.indexOf (Char);
  13. EncodeChar=Ref.substring(Num+1, Num+2)
  14. Result += EncodeChar
  15. } document.form1.result.value=Result
  16. }
  17. // - End of JavaScript - -->
  18. </SCRIPT>
  19.  
  20. </HEAD>
  21. <BODY bgcolor="beige">
  22.  
  23.  
  24. <FORM name="form1">
  25. <table border=0><tr><td>
  26. Type your word<td><INPUT NAME="input" TYPE=Text><br><td>
  27. <INPUT TYPE=Button VALUE="submit" onClick="encode(this.form.input.value)"><tr><td>
  28. Result:<td><INPUT NAME="result" TYPE=Text>
  29.  
  30. </table>
  31. </FORM>
  32. </BODY>
  33. </HTML>
  34.  
May 16 '10 #1
3 2134
acoder
16,027 Recognized Expert Moderator MVP
You could use "BCD...XYZA" for Ref. This would give you the correct code for each letter if you get the next letter.

Note that you can use charAt to get a particular letter from the input.
May 16 '10 #2
Calla
2 New Member
@acoder
Wait, so I can just replace Ref with BCD...XYZA? Also, whre do I enter the A=B, and so on?
May 16 '10 #3
acoder
16,027 Recognized Expert Moderator MVP
I meant the rest of the letters of the alphabet there.

You don't need to define the encoding because that's being done in your code. On line 11 you either need to use charAt or substring like you've used it on line 13
May 17 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Daylor | last post by:
how can i protect my code from decompile ?
8
by: Mike9900 | last post by:
Hello, We want to add a secret code which is the expiration date and the number of uses of the trial software in storage. Saving this code in the Windows Registry is not a good choice, because...
2
by: Arnold | last post by:
For some of my secondary students studying bits and bytes, I'd like to make a form in which they can create secret codes with bytes. I'd like the form to have a memo field that can only accept 0s...
24
by: St33med | last post by:
Making a hangman code (I'm a n00b, still in the tutorial stage) Anyway, here's my (top-secret) code: def guess(): choice=raw_input("Guess!(lowercase only please!)") if len(choice)>1: ...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
6
by: coldwind2010 | last post by:
Hi! I want to post a form to a page,and get the output of the page. But the post value includes a authentication code which is 13 figures and change every time. I use curl fuction to do so. I...
8
by: Torben Laursen | last post by:
Hi I need to be sure that my C# code is as hard as possible to decompile. Can anyone tell what is the best tool for that job? Also will this be a part of Visual Studio 2008? It seems...
1
by: Sanoski | last post by:
What would you guys says about this secret code? The key was apparently lost. The guy never sent it, and he was never seen again. It must stand for letters in the alphabet, but it almost looks like...
2
by: sanjay.bidi1 | last post by:
I have puzzle in which I need to hash a value comprised of 2 form fields and a shared password before submitting form to external web application. My question is, what are the possibilities for...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.