|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
I want help with a program with JAVASCRIPT in an HTML window. I was thinking of something like this....
----- [ BOX 1 ] [Output BOX 1] ----- Lets say, that in BOX 1, you put the letter 'H'. It would then put in the outbox, the letter 'G' or something....so it takes the first letter, and converts it to another. It takes a letter / number and converts it to another preset letter / number. Was planning on a secret chat language or something...maybe could incorporate it into my flash games too. Thank you for all your help and suggestions! I am new to this website, so thank you very much for your time! My idea is that it would be able to be put into an HTML window. I know HTML very well too. Have no idea about JS, but have been to w3schools.com. ![]() |
|
#2
|
||||
|
||||
|
Hallo & welcome!!!
There are a lot of algorithms that perform such tranformations. Unfortunatelly I cannot send any link as I read all of them in books only, but I bet u'll find numerus in the inet. I will show u an example of how u can do this, but it is just one way that can be done......, there are inoumerous things like that, that u can think yourshelf, & a lot more u can find. I hope sb else may have suitable links for u. Here is the working example: Code:
<html>
<head>
<Script language="javascript" >
function startEncoding(str) {
document.getElementById("outoutStr").value = encodeTxt(str);
}
function encodeTxt(str) {
var tmp = -1;
var codedPhr = "";
var codePhrase = "PutYourCodePhraseHereAndMakeSureItWillBeLargerInLe ngthThanAnyPossibleLengthOfPhraseThatSTRwillHold";
for (var i=0; i<str.length; i++) {
tmp = codePhrase.charCodeAt(i) + str.charCodeAt(i);
if (parseInt(tmp) > 128) {
tmp = (tmp - 128);
}
codedPhr += String.fromCharCode(tmp);
}
return codedPhr;
}
function startDecoding(str) {
document.getElementById("originalStr").value = decodeTxt(str);
}
function decodeTxt(str) {
var tmp = -1;
var codedPhr = "";
var codePhrase = "PutYourCodePhraseHereAndMakeSureItWillBeLargerInLe ngthThanAnyPossibleLengthOfPhraseThatSTRwillHold";
for (var i=0; i<str.length; i++) {
tmp = str.charCodeAt(i) - codePhrase.charCodeAt(i);
if (parseInt(tmp) < 0) {
tmp = (tmp + 128);
}
codedPhr += String.fromCharCode(tmp);
}
return codedPhr;
}
</Script>
</head>
<body>
My input uncoded Phrase:</br>
<input type="text" name="inputStr" id="inputStr" value="" size="120"><br>
<input type="button" name="btnConvert" id="btnConvert" value="Convert" onClick="javascript: startEncoding(document.getElementById('inputStr'). value);"></br>
Here I can see the character transformation of the phrase I just wrote:</br>
<input type="text" name="outoutStr" id="outoutStr" value="" size="120"></br>
<input type="button" name="btnConvert" id="btnConvert" value="Convert Back" onClick="javascript: startDecoding(document.getElementById('outoutStr') .value);" ></br>
And finally, the initial phrase decoded again:</br>
<input type="text" name="originalStr" id="originalStr" value="" size="120">
</body>
</html>
Good Luck! ![]() |
|
#3
|
|||
|
|||
|
I like the code, but I do not understand how it works. I did use it and put it in an HTML. I do NOT need explaining, but would also like if you could help further...
Is there a way to make a key, such as...[var] a=z b=a c=h t=u etc.... There is no pattern to that however. Those are just examples... But thanks for helping. You rule :-O ![]() |
|
#4
|
||||
|
||||
|
1. U could create a double array,
e.g.: var my2Darr = [["a", "z"], ["b", "a"], ["c", "h"], ["d", "t"], ["e", "6"], ["f", "#"], ["t", "u"]]; where in ["a", "z"] "a" is the letter to be replaced by the "z" in ["b", "a"] "b" is the letter to be replaced by the "a" e.t.c. Then loop through the given phrase & replace the letters one by one. 2. U can do it hard coded, looping through the given phrase & using 26 (the No of the characters) switch cases....(too much to write but straight forward) 3. U can use two single arrays & switch the letters according to their possition in the array... Or a single array & use a pattern on the possition... It is exactly the same idea (difference is only in coding). I would also propose u to try to anderstand the code i sent u before what it does, since u liked it...., because it is pretty close to what u ask... |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > JavaScript - Convert JAVASCRIPT Simple; Help!! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
![]() |
|