As I stated before I am trying to make a specific for
loop for an encryption machine (a toy machine, not one that is secure from the NSA).
When I press the encrypt button, I need the encryption to run and then produce the info encrypted in another text box. So I have a text box where the user enters the numbers to be encrypted (between 10000 and 99999) and then press encrypt and the info shows up in the second bar. I have the set up but the for loop is tricky.
These are my directions:
Add the necessary code to the “Encrypt” button to do the following:
a) Create a for loop to add 10 to the number entered on the first box and multiply the
result by 3, add 20 to this result and then multiply it by 5, add 30 to this result and then
multiply it by 7, etc. Follow that pattern 5 times (5 iterations).
b) After the iterations have been completed, there will be a resulting number in
memory, let's say 75432179
c) Now, this number needs to be turned into characters (letters) by matching each digit
to its corresponding letter of the alphabet based on the positions of the letters (0 will
be matched with the 10th letter of the alphabet). For our example: the resulting letters
will be: gedcbagi (g is the 7th letter of the alphabet, e is the 5th letter, d is the 4th
letter, etc.)
d) The last step of the encryption process is to further scramble the letters by using the
ancient Caesar's cipher: each letter replaced by another letter three positions to the
right. Therefore, the final result in our example would be: jhgfedjl (Notice that you
may also do steps c) and d) combined)
This is what I have so far for my script tags; please tell me what I'm doing wrong:
<script type="text/javascript">
q=1
for (encryptThis=1; encryptThis <=5; encryptThis++){
if (encryptThis>=10000 && encryptThis<=99999){
encryptinfo=((q+2)*10+encryptThis);
}else{
alert("number should be between 10000 and 99999");
}}
</script>
then for the bottom of my table by my inputs:
<tr>
<td>Plaintext (Plain information)</td>
<td><input type="text" name= "encryptThis" size="16" onchange=' '/></td>
<td><input type="button" value=" Encrypt " onclick='
system.out.encryptinfo.print((q+2)*10+encryptThis);
'/></td>
and....
<tr>
<td>Ciphertext (Encrypted information)</td>
<td><input type="text" name= "encryptinfo" size="16" onchange=' '/></td>
<td></td>
</tr>
See Question&Answers more detail:
os