Thread: Arrays and For Loop

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    10

    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. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    What are you trying to do? Generate random numbers?

  3. #3
    Registered User
    Join Date
    Jan 2007
    Location
    Euless, TX
    Posts
    144

    Unhappy

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

  4. #4
    Registered User
    Join Date
    Oct 2007
    Posts
    10
    Quote Originally Posted by MacGyver View Post
    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]
    Last edited by Jack1982; 10-08-2007 at 09:58 AM.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    10
    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. #6
    Registered User
    Join Date
    Oct 2007
    Posts
    10
    Quote Originally Posted by kcpilot View Post
    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
    Last edited by Jack1982; 10-08-2007 at 10:11 AM.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Oct 2007
    Posts
    10
    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. #10
    Registered User
    Join Date
    Oct 2007
    Posts
    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

Popular pages Recent additions subscribe to a feed