Solved

How do extract each individual value front the array result??

Posted on 2009-04-13
9
123 Views
Last Modified: 2012-05-06
I have this encryption script that encrypts 4 variables in a loop.  I would like to access them individually at the end.  How can i do tha??
<html>

<head>

 <title></title>
 

<script language="javascript">

	

  	var input = new Array(4); 

	input[0] =  "USERI     ";

	input[1] =  "PASSWRD   ";

	input[2] = "123456789                     ";

	input[3] = "";

	

	function makeURL()

	{

		
 

		

   		for(i = 0; i < input.length; i++)

		{

  

			 //	the following letters and numbers and other characters are going to be encrypted, there are a total of 70

    	   

		var Alpha = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J",

					"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",

					"U", "V", "W", "X", "Y", "Z",

					"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",

					"k", "l", "m", "n", "o", "p", "q", "r", "s", "t",

					"u", "v", "w", "x", "y", "z",

					"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",

					"!", "@", "$", "*","-", ".", ":", ";");

		

		var AlphaL = Alpha.length

		var iInStrLen = input[i].length;	

		

	

		

		

		// if the the length of the input string is less than 10 then add a 0

		var appendix = "";

		

		if(iInStrLen < 10)

		{

		var appendix = "0";

		}

		

		var szRanStr = new Array();

 		

		var temp3 = "";

		

		//it will choose 32 random characters from your list of 70

		for (y=0; y<32; y++) 

		{

		

		var AlphaR = (Math.round((Math.random()*70)+1))

		

		szRanStr[y] =   Alpha[AlphaR];

		

		temp3 =  szRanStr.toString();

		temp3 = szRanStr.join("");

		 }

	

			 

		 if (iInStrLen == 10)

		 {

	      

		 encryptcod  = temp3.substring(0,20)

		 }

		 else if(iInStrLen == 8)

		 {

	     encryptcod  = temp3.substring(0,22)

		 }

		 else if(iInStrLen  >= 30)

		 {

	     encryptcod  = "";

		 }

		

        
 

		var preparedStr = input[i] + encryptcod + appendix +  iInStrLen;

     

		//create new array that contains the data to encrypt

		var SecVal = new Array();

 		SecVal = preparedStr.split('');

		

		var j = 3;

		

		while (j > 0) {

		temp = SecVal[0];

		SecVal[0] = SecVal[1];

		SecVal[1] = SecVal[2];

		SecVal[2] = SecVal[3];

		SecVal[3] = temp;

		

		temp = SecVal[4];

		SecVal[4] = SecVal[5];

		SecVal[5] = SecVal[6];

		SecVal[6] = SecVal[7];

		SecVal[7] = temp;

		

		temp = SecVal[8];

		SecVal[8] = SecVal[9];

		SecVal[9] = SecVal[10];

		SecVal[10] = SecVal[11];

		SecVal[11] = temp;

		

		temp = SecVal[12];

		SecVal[12] = SecVal[13];

		SecVal[13] = SecVal[14];

		SecVal[14] = SecVal[15];

		SecVal[15] = temp;

		

		temp = SecVal[16];

		SecVal[16] = SecVal[17];

		SecVal[17] = SecVal[18];

		SecVal[18] = SecVal[19];

		SecVal[19] = temp;

		

		temp = SecVal[20];

		SecVal[20] = SecVal[21];

		SecVal[21] = SecVal[22];

		SecVal[22] = SecVal[23];

		SecVal[23] = temp;

		

		temp = SecVal[24];

		SecVal[24] = SecVal[25];

		SecVal[25] = SecVal[26];

		SecVal[26] = SecVal[27];

		SecVal[27] = temp;

		

		temp = SecVal[28];

		SecVal[28] = SecVal[29];

		SecVal[29] = SecVal[30];

		SecVal[30] = SecVal[31];

		SecVal[31] = temp;

		

		

		j=j-1;

		

		

		}

		

		temp = SecVal[1];

		SecVal[1] = SecVal[30];

		SecVal[30] = SecVal[3];

		SecVal[3] = SecVal[28];

		SecVal[28] = SecVal[5];

		SecVal[5] = SecVal[26];

		SecVal[26] = SecVal[7];

		SecVal[7] = SecVal[24];

		SecVal[24] = SecVal[9];

		SecVal[9] = SecVal[22];

		SecVal[22] = SecVal[11];

		SecVal[11] = SecVal[20];

		SecVal[20] = SecVal[13];

		SecVal[13] = SecVal[18];

		SecVal[18] = SecVal[15];

		SecVal[15] = SecVal[16];

		SecVal[16] = temp;

     

	 

   

		encrypted = SecVal.join("");

			 

		encrypted =  escape(encrypted);

		

			
 
 
 
 

outputf =  'SPACE9=' +    '&SPACE10='   +     '&SPACE11='  ;
 

}
 

document.write("//"+encrypted);
 

}
 
 

</script>  
 
 
 

</head>
 

<body  onload="makeURL()">
 
 
 
 
 
 

</body>
 

</html>

Open in new window

0
Comment
Question by:kkoehler
  • 4
  • 3
9 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24135749
What do you mean?

for (var i=0;i<arr.length;i++) alert(arr[i])

?
0
 

Author Comment

by:kkoehler
ID: 24138402
mplungjan:

I have tried that, but after the encryption it dors not work as it seems to have jumbled up everything together.  I'm trying to find a way to separate it so I can access them individually.

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24138426
erm... Isn't the idea of an encryption to "jumble up everything together" ??
0
 

Author Comment

by:kkoehler
ID: 24138524
Yes, but I'm adding four separate variables and need to access each one of these variables encryption together.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24138786
I have no clue as to what you are trying to do
0
 

Author Comment

by:kkoehler
ID: 24139145
I'm trying to encrypt these variablesL:

input[0] =  "USERI     ";
input[1] =  "PASSWRD   ";
input[2] = "123456789                     ";

After then have been encrypted I want to get each one of them individually to assemble a URL.  Each of these will be placed in a different part of a URL whic is why I need to access them separately.   In other words I need to encrypt "USERI     " and place it in its corresponding place in the URL and the same for the other variables.    Does that make sense?




 
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 125 total points
ID: 24140729
Like this?

<html>

<head>

 <title></title>

 

<script language="javascript">

    var encryptedArr = new Array();    

        var input = new Array(4); 

        input[0] =  "USERI     ";

        input[1] =  "PASSWRD   ";

        input[2] = "123456789                     ";

        input[3] = "bla";

        

        function makeURL()

        {

                

 

                

                for(i = 0; i < input.length; i++)

                {

  

                         //     the following letters and numbers and other characters are going to be encrypted, there are a total of 70

           

                var Alpha = new Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J",

                                        "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",

                                        "U", "V", "W", "X", "Y", "Z",

                                        "a", "b", "c", "d", "e", "f", "g", "h", "i", "j",

                                        "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",

                                        "u", "v", "w", "x", "y", "z",

                                        "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",

                                        "!", "@", "$", "*","-", ".", ":", ";");

                

                var AlphaL = Alpha.length

                var iInStrLen = input[i].length;        

                

        

                

                

                // if the the length of the input string is less than 10 then add a 0

                var appendix = "";

                

                if(iInStrLen < 10)

                {

                var appendix = "0";

                }

                

                var szRanStr = new Array();

                

                var temp3 = "";

                

                //it will choose 32 random characters from your list of 70

                for (y=0; y<32; y++) 

                {

                

                var AlphaR = (Math.round((Math.random()*70)+1))

                

                szRanStr[y] =   Alpha[AlphaR];

                

                temp3 =  szRanStr.toString();

                temp3 = szRanStr.join("");

                 }

        

                         

                 if (iInStrLen == 10)

                 {

              

                 encryptcod  = temp3.substring(0,20)

                 }

                 else if(iInStrLen == 8)

                 {

             encryptcod  = temp3.substring(0,22)

                 }

                 else if(iInStrLen  >= 30)

                 {

             encryptcod  = "";

                 }

                

        

 

                var preparedStr = input[i] + encryptcod + appendix +  iInStrLen;

     

                //create new array that contains the data to encrypt

                var SecVal = new Array();

                SecVal = preparedStr.split('');

                

                var j = 3;

                

                while (j > 0) {

                temp = SecVal[0];

                SecVal[0] = SecVal[1];

                SecVal[1] = SecVal[2];

                SecVal[2] = SecVal[3];

                SecVal[3] = temp;

                

                temp = SecVal[4];

                SecVal[4] = SecVal[5];

                SecVal[5] = SecVal[6];

                SecVal[6] = SecVal[7];

                SecVal[7] = temp;

                

                temp = SecVal[8];

                SecVal[8] = SecVal[9];

                SecVal[9] = SecVal[10];

                SecVal[10] = SecVal[11];

                SecVal[11] = temp;

                

                temp = SecVal[12];

                SecVal[12] = SecVal[13];

                SecVal[13] = SecVal[14];

                SecVal[14] = SecVal[15];

                SecVal[15] = temp;

                

                temp = SecVal[16];

                SecVal[16] = SecVal[17];

                SecVal[17] = SecVal[18];

                SecVal[18] = SecVal[19];

                SecVal[19] = temp;

                

                temp = SecVal[20];

                SecVal[20] = SecVal[21];

                SecVal[21] = SecVal[22];

                SecVal[22] = SecVal[23];

                SecVal[23] = temp;

                

                temp = SecVal[24];

                SecVal[24] = SecVal[25];

                SecVal[25] = SecVal[26];

                SecVal[26] = SecVal[27];

                SecVal[27] = temp;

                

                temp = SecVal[28];

                SecVal[28] = SecVal[29];

                SecVal[29] = SecVal[30];

                SecVal[30] = SecVal[31];

                SecVal[31] = temp;

                

                

                j=j-1;

                

                

                }

                

                temp = SecVal[1];

                SecVal[1] = SecVal[30];

                SecVal[30] = SecVal[3];

                SecVal[3] = SecVal[28];

                SecVal[28] = SecVal[5];

                SecVal[5] = SecVal[26];

                SecVal[26] = SecVal[7];

                SecVal[7] = SecVal[24];

                SecVal[24] = SecVal[9];

                SecVal[9] = SecVal[22];

                SecVal[22] = SecVal[11];

                SecVal[11] = SecVal[20];

                SecVal[20] = SecVal[13];

                SecVal[13] = SecVal[18];

                SecVal[18] = SecVal[15];

                SecVal[15] = SecVal[16];

                SecVal[16] = temp;

     

         

                  encrypted = SecVal.join("");

                         

                encryptedArr[encryptedArr.length] =  escape(encrypted);

                

                        

 

 

 

 

outputf =  'SPACE9=' +    '&SPACE10='   +     '&SPACE11='  ;

 

}

 

return encryptedArr.join('&');

 

}

 

window.onload=function() {

document.getElementById('output').innerHTML='<a href="somepage.php?enc="'+makeURL()+'">'+makeURL()+'</a>';

	}

</script>  

 

 

 

</head>

 

<body>

 

 <span id="output"> </span>

 

 

 

 

</body>

 

</html>

Open in new window

0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 37175620
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now