473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

key++ problem generating keys ..!

hi,

i wish to generate all possible key combinations ranging:

HEX: "0F FF FF FF FF FF FF FF" TO HEX: FF FF FF FF FF FF FF FF

i also test each key after incrementing by 1, for test i want the key to be a an unsigned char[8]

key start rang and end range can be initialize/declare in any format.

Problem is if :

Expand|Select|Wrap|Line Numbers
  1. unsigned char key[] = {0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
then i can not increment this key by +1 , though if i initialize this key in decimal as:

Expand|Select|Wrap|Line Numbers
  1. unsigned long long key = 1152921504606846975;
then i can increment the key in for loop by key++ but then i cant convert it back into unsigned char array :(

i want to achieve something like this soory i am c noob :(

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5.  
  6. unsigned char key[] = {0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
  7.  
  8.  
  9. int main()
  10. {
  11.     int idx;
  12.  
  13.     for(idx=0;;idx++)
  14.     {
  15.  
  16.     //key[]++; here i want to add +1 in key for increamenting
  17.  
  18.  
  19. printf ("Current key: %02X %02X %02X %02X %02X %02X %02X %02X \n",key[0],key[1],key[2],key[3],key[4],key[5],key[6],key[7]); // this way i want to print the final incremented key
  20.     }
  21.  
  22. }
  23.  
  24.  

In my programer i also have function that test each key but key has to be unsigned char so i am kinda stuck :(


Thanks all
Nov 16 '14 #1
3 1375
donbock
2,426 Expert 2GB
Start with the lowest order byte (key[7]), if current value is not 0xFF then increment it, otherwise set the value to 0 and increment the next higher byte using this same algorithm. Make sure you handle the highest order byte (key[0]) properly.
Nov 16 '14 #2
weaknessforcats
9,208 Expert Mod 8TB
Usually, when working with keys you use a tree structure rather than an array. The tree holds the keys actually used rather then reserving a place for all possible keys.

That said, use a small key, like 256 in an int. Get the code working with values 1-255. Reserve 0 as a null key in case you need it.

Later you can expand the code for larger ranges of keys and when you do, you will be starting with code that works.
Nov 17 '14 #3
hi thanks for reply i think i sorted it out by incrementing byte in for loop ... i wanted to make a brute force app but now i calc , PC can generate and test 256keys/seconds :( if i increase number of threads to 16 then its 4096keys/second but still not enough to process all keys 18374686479671623679 :( i guess it will take months ... have to find some efficient way.
Nov 17 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Robert Oschler | last post by:
I am converting a Perl script over to "C" for a potential open source project. I need some open source "C" code that will give me the same functionality of a Perl Style associative array: ...
0
by: Bill1312 | last post by:
Hi I am trying to get an textbox control to work. All of the Key.values are working all except for the Backspace key I have the char value set to 8 Is there a different way of getting the...
6
by: Sahil Malik [MVP] | last post by:
Public Private Key Pairs - How do they work? ----------------------------------------------- I was looking at a presentation recently in which it was suggested that - User 1 Encrypts a message...
2
by: Jim S | last post by:
I am having a problem finding information regarding vb.net allowing you to create shortcut keys for buttons using the CTRL key + function buttons such as F1, F2 etc.. (Ex: Press CTRL+F1 to activate...
6
by: Bruce D | last post by:
I have a datagrid (uggg) that I use and create the columns programmatically...see below. objCol = New DataGridTextBoxColumn objCol.MappingName = "amount" objCol.HeaderText = "Amount"...
5
by: Boni | last post by:
Dear all, How do I get information if Shift is pressed in a mouse wheel handler. Thanks, Boni Sub MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) 'mouse whill...
1
by: josegomez | last post by:
Hi! I want to use shelve to store lists which are indexed by an integer key. The keys are not concurrent or anything, they are just defined as integer values. However, shelve complains that I...
2
by: Vincent | last post by:
Hi, I have a user control that needs to trap the arrow keys to move items around internally. However, using the arrow keys will move the focus to another control on the form hosting the user...
7
by: mutemode | last post by:
Help again please, I need to insert rows into a table from another table. The tables are identical column wise except the table im inserting from does not have a primary key value. On insert I...
2
by: norseman | last post by:
Terry Reedy wrote: ================ First part I understand, second is still giving me a problem. For some reason I still want keys to be dbf column headers. like: name:address:zip so forth...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.