[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2009-04-13
9
Medium Priority
?
134 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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!

 

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
 
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 500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

649 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