# Thread: Arrays and For Loop

1. ## Arrays and For Loop

Dear all,

If I have int array[256],
how do I generate permutation from length 1 to 256?

for eg: length 1,

array[0] -> from 00 to 255

for length 5,

array[0] 0 1 2.... to 255
array[1] 0 0 0.... to 255
array[2] 0 0 0.... to 255
array[3] 0 0 0.... to 255
array[4] 0 0 0.... to 255

up to 256

array[0]
to
array [255]

I have been trying to generate the numbers for whole day. I can't think of an algorirhtm. Hope the experts here can help me. Thanks in advance

2. What are you trying to do? Generate random numbers?

3. You need to clarify what you are trying to do with these permutations. Your question needs more explanation

4. Originally Posted by MacGyver
What are you trying to do? Generate random numbers?

I want to generate output
of all permutation of 256

[0][0][0] all the way to 255
[0][0][0] all the way to 255
[0][0][0] all the way to 255
[0][0][0] all the way to 255
[0][0][0] all the way to 255
.. all the way to 255
.. all the way to 255
..all the way to 255
..all the way to 255
[0][1][2] all the way to 255

using int arry[256]

5. This is what I think

Code:
```	for(keylen=1; keylen<=256; keylen++)
{
for(x=1; x<=256; x++)
{
for(int j=0x00; j<= 0xFF; j++)
{

K[x-1] =j

}```
However this code can only loop 0x00 to 0xFF for each index only at a time.

6. Originally Posted by kcpilot
You need to clarify what you are trying to do with these permutations. Your question needs more explanation

I have this cryptography assignment.

I am trying to use brute force method to identify the key used in this assignment

http://aycu28.webshots.com/image/299...4210497_rs.jpg

7. There are 256! permutations of 256 numbers - that's an enormous number. 69! already has 100 decimal places. 70! has 70 times as many possibilities, 71! 71 times as many as that, and so on. Your machine doesn't have enough memory to store them all (for that matter, if I were to venture a guess, I'd say all computers on earth together don't have enough memory to store that), and you won't live long enough to see your computer finish computing them all.

But if you want to start, then just make a single array of the numbers 0 through 255 and use the std::next_permutation algorithm on it.

8. But your assignment doesn't refer to a 2048-bit key (you can count the particles in the universe in about 300 bits by the way, just in case you thought a brute-force was feasible).

What I think you should be doing is looking at the information you have to come up with something which might work a lot better than brute-force.

9. Thank guys,

Any crypto experts here?
I have generated an RC4 Stream actually. I am able to decrypt c1 file but the remaining c2 to c6 file I can't decrypt at all. I understand that since all files use the same RC4 Stream, there should not have any problem decrypting the remaining files as well. I am so puzzled and lost.

10. Hi guys,

I need to find the RC4 Stream by XORING all plaintext with all ciphertext.
There are 5 plain text files and 6 ciphertext files.
Plain text file is a part of a document while ciphertext file is the entire document and plain text 1 does not equal to ciphertext 1.

The full question can be found here
http://aycu28.webshots.com/image/299...4210497_rs.jpg

I need to find out the RC4 Stream by XOR, p1 with c1,c2,c3,c4,c5,c6 and p2 with c1...c6,
and for each pair, p1 with c1/2/3/4/5/6 I need to shift c1 1 character at a time.

The generated RC4 Streams with the highest counter will be the actual RC4Stream. Can anybody tell me how to code this operation?

Thanks a lot