• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 139
  • 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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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