Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cipher

Status
Not open for further replies.

hazz25

Technical User
Feb 29, 2008
2
GB
Hi,

I'm brand new to this forum, so please excuse any ignorance.

I really need some help, as I don't really know javascript much at all. I need a web script (I think a form will fit the bill) that has an two input boxes.

One will be a text input box and one will be a number input box.

1. When a character is inserted in the first box, if it is any of the letters of the english alphabet, the script assigns it the first number (n) that has been typed in the number box (the numbers will have to be separated with a space).

2. Then if the number that the letter has been assigned (n) is lower than 26, the script jumps to stage 3, treating (nMod) as (n). If it is higher than 26, the script then runs the calculation (n)%26

(i.e. this finds the remainder after dividing the number by 26, but you already knew that).

3. The script then adds the answer (nMod) to the number (nCor) that corresponds to the original letter if you use the rule "A=1, B=2 etc." So (nMod)+(nCor)

4. If the answer to this (nMC) is lower than 26, it then finds the letter that corresponds to it according to the above rule. This letter is then printed out in another text box.

5. If the answer is higher than 26, it minuses 26 from the number and then does the above. So (nMC)-26

6. It does this for each letter, and for anything that is not part of the english alphabet, it just prints it out in the text box without changing it.

So, if I put the letter R in the text input box, and the number 40 in the number input box, it will assign 40 to R, then do 40%26, which is 14. It will then add 14 to the number which corresponds to R, which is 18. The answer to this is 32. As this is greater than 26, it will do 32-26, which is 6. It will then print out the letter that corresponds with 6, which is F.

The problem is, I have a basic grasp of Javascript, (kind of.) and can do else...if...else functions, but I have no idea how you would get the script to see a letter in a text box, and then do things with it. Any help would be appreciated.

Harry.

Oh and BTW, the variables I defined above are just to make my explanation a bit clearer, they don't necessarily represent variables in the script.
 
So, how many points is this homework assignment worth?

If you have questions about course work, go ask your teacher instead of cheating by trying to get someone to do it for you here.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Thank you for that helpful answer; for your information I do not study Javascript or in fact anything of the sort. This is something I have devised using my limited to non-existent knowledge of the language to automatically encrypt words into a Cipher I have also created. I understand that you probably get a lot of people doing such things, but please do not think that, firstly, I would study computer language, and secondly, that I would get someone else to do it for me.

Again I apologise if this looks like I want you to do my dirty work, all I would like is some kind of help as to how the hell I would go about creating this.
 
There are many useful online Javascript tutorials you can find in a Google search. You could probably find some in your language that would make it real easy for you to understand.

Tek-Tips isn't a place to have someone write code for you or provide tutorials, but for you to bring what you've written that you have questions about.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top