Loop to note position of lowest number
Hi guys,
I have a password key which is "password12Qcb6z:!sh:&BYztwYTPM" which i have repeating a number of times in a 1d array.
What i am trying to create an array where numbers are assigned starting with 1, and they are assigned first by alphabetical order, and second, where the same letter appears twice, by position in the word.
for example:
C O N V E N I E N C E
1 10 7 11 3 8 6 4 9 2 5
my key is alot longer than "CONVENIENCE" its roughly 328 characters long ("password12Qcb6z:!sh:&BYztwYTPM" repeated ). so i have a 1d int array array which i want to map out 1-328 following the rule above starting wit the lowest character in its ascii values 32 = SPACE to ~ = 127. so i then have a array mapping out 1-328 ...
I have this code so far
Code :
int v=0, count=0, r=32; // 33 is the first usable ascii character in test file
int[] colprintorder = new int[numberofcols];
while(r<=127) // loop unit last usable ascii char
{
for(int i=0;i<passwordinbyte.length;i++) // go through each cell of the array
{
if (r == passwordinbyte[i]) // if the value of r is the same as what is in passwordinbyte map its position storing in colprintorder
{
colprintorder[count] = i ;
count++; // next cell in the array
}
}
r++; // look for the next characters ascii value 32-127
}
for(int a=0; a<colprintorder.length; a++) // print out colprint order
{
System.out.println( colprintorder[a] + " " );
}
System.out.println("lengthhrr" +passwordinbyte.length);
Here is my output using the code snippet above:
http://i57.photobucket.com/albums/g2...e2k/lolcat.jpg
it appears theres somthing wrong with my code but i dont know what can you guys help me ?
thank you
Re: Loop to note position of lowest number
I have added a better testing print out below
Code :
Coloumn print order:
17 19 10 8 9 12 14 15 11 1 7 16 5 0 6 2 3 18 4 13
Password in bytes:
112 97 115 115 119 111 114 100 49 50 47 70 50 123 52 57 104 33 118 43
Password in characters:
p a s s w o r d 1 2 / F 2 { 4 9 h ! v +
as you can see the lowest ascii number charcter is '+' which has the value of 43 however it has been put at position of 13. (http://www.cs.utk.edu/~pham/ascii_table.jpg)
the coloumn array need to map the password in bytes in order. Does anyone know what im doign wrong
Re: Loop to note position of lowest number
Ok, I'm a little confused (maybe this is above me or something).
So, you are wanting to get the ASCII values of all of the characters, then determine, based on their ASCII values, which come first, second, third, ect.
If so, I am unsure why you have all that code. You can convert a String to a char[] using the String.toCharArray() method, then sort the char[] with the Arrays.sort(char[]) method, then do whatever with the sorted array.
When I input CONVENIENCE in the code below:
Code java:
import java.util.Arrays;
public class ASCIITesting
{
public static void main(String[] args)
{
String input = "CONVENIENCE";
char[] charArr = input.toCharArray();
Arrays.sort(charArr);
for(int i=0;i<charArr.length;i++)
System.out.print(Character.toString(charArr[i]));
}
}
It outputs:
which is the word sorted based on each character's ASCII value.
Similarly, if I input password12Qcb6z:!sh:&BYztwYTPM it outputs:
Quote:
!&126::BMPQTYYabcdhoprssstwwzz
Am I totally off?
Re: Loop to note position of lowest number
yes you are off but after 2 hours if staring at the screen i figured it out .
Than kyou for your help :)