Skip to content

Commit

Permalink
Key Generation program
Browse files Browse the repository at this point in the history
  • Loading branch information
zinechant committed May 15, 2017
0 parents commit e665f88
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build/DataGen: src/DataGen.cpp
g++ src/DataGen.cpp -o build/DataGen

genData:
./build/DataGen

clean:
rm -rf ./build/*
2 changes: 2 additions & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
62 changes: 62 additions & 0 deletions src/DataGen.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <cstdio>
#include <cstdlib>
#include <string>

using namespace std;

void genLinear(const char * FilePath, int len){
FILE * Fo = fopen(FilePath, "w");
for (int i = 0; i < len; i++)
fprintf(Fo, "%8x\n", i+1);
}
void genRandom(const char * FilePath, int len){
printf("RAND_MAX = %d\n", RAND_MAX);
printf("RAND_MAX = %x\n", RAND_MAX);
FILE * Fo = fopen(FilePath, "w");
for (int i = 0; i < len; i++)
fprintf(Fo, "%8x\n", rand());

}
void genGrid(const char * FilePath, int len){
string s = "0x11111111";
FILE * Fo = fopen(FilePath, "w");
for (; len; len--){
fprintf(Fo, "%s\n", s.c_str());
for (int i = s.length() - 1; i >= 0; i--) {
if (s[i] == '9')
s[i] = 'A';
else if (s[i] == 'F')
s[i] = '0';
else s[i]++;

if (s[i] != '0')
break;
}
}
}
void genRevGrid(const char * FilePath, int len){
string s = "0x11111111";
FILE * Fo = fopen(FilePath, "w");
for (; len; len--){
fprintf(Fo, "%s\n", s.c_str());
for (int i = 0; i < s.length(); i--) {
if (s[i] == '9')
s[i] = 'A';
else if (s[i] == 'F')
s[i] = '0';
else s[i]++;

if (s[i] != '0')
break;
}
}
}

int main(){
int N = 1468000;
genLinear("../data/Linear.key", 1468000);
genRandom("../data/Random.key", 1468000);
genGrid("../data/Grid.key", 1468000);
genRevGrid("../data/RevGrid.key", 1468000);
return 0;
}

0 comments on commit e665f88

Please sign in to comment.