• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 135
  • Last Modified:

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

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
kkoehler
Asked:
kkoehler
  • 4
  • 3
1 Solution
 
Michel PlungjanIT ExpertCommented:
What do you mean?

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

?
0
 
kkoehlerAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
erm... Isn't the idea of an encryption to "jumble up everything together" ??
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
kkoehlerAuthor Commented:
Yes, but I'm adding four separate variables and need to access each one of these variables encryption together.
0
 
Michel PlungjanIT ExpertCommented:
I have no clue as to what you are trying to do
0
 
kkoehlerAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
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
 
CWS (haripriya)Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now